YetiForceCompany/YetiForceCRM

View on GitHub
modules/SSalesProcesses/views/Hierarchy.php

Summary

Maintainability
B
5 hrs
Test Coverage
F
0%
<?php

/**
 * Class to show hierarchy.
 *
 * @copyright YetiForce S.A.
 * @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)
 * @author Tomasz Kur <t.kur@yetiforce.com>
 */
class SSalesProcesses_Hierarchy_View extends \App\Controller\View\Page
{
    use App\Controller\ClearProcess;

    /**
     * Function to check permission.
     *
     * @param \App\Request $request
     *
     * @throws \App\Exceptions\NoPermittedToRecord
     */
    public function checkPermission(App\Request $request)
    {
        $recordId = $request->getInteger('record');
        if (!$recordId) {
            throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
        }
        if (!\App\Privilege::isPermitted($request->getModule(), 'DetailView', $recordId)) {
            throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
        }
    }

    public function process(App\Request $request)
    {
        $viewer = $this->getViewer($request);
        $moduleName = $request->getModule();
        $recordId = $request->getInteger('record');

        $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
        $hierarchy = $recordModel->getHierarchy();

        $viewer->assign('MODULE', $moduleName);
        $viewer->assign('HIERARCHY', $hierarchy);
        $viewer->view('Hierarchy.tpl', $moduleName);
    }
}