initializeTranslator(); Benchmark::measure('Director base Controller init()'); $this->checkForRestApiRequest(); $this->checkDirectorPermissions(); $this->checkSpecialDirectorPermissions(); } protected function initializeTranslator() { TranslationHelper::setTranslator(new Translator('director')); } public function getAuth() { return $this->Auth(); } protected function checkDirectorPermissions() { $this->assertPermission('director/admin'); } protected function checkSpecialDirectorPermissions() { if ($this->params->get('format') === 'sql') { $this->assertPermission('director/showsql'); } } /** * Assert that the current user has one of the given permission * * @param array $permissions Permission name list * * @return $this * @throws SecurityException If the current user lacks the given permission */ protected function assertOneOfPermissions($permissions) { $auth = $this->Auth(); foreach ($permissions as $permission) { if ($auth->hasPermission($permission)) { return $this; } } throw new SecurityException( 'Got none of the following permissions: %s', implode(', ', $permissions) ); } /** * @param int $interval * @return $this */ public function setAutorefreshInterval($interval) { if (! $this->getRequest()->isApiRequest()) { parent::setAutorefreshInterval($interval); } return $this; } protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) { $limit = $this->params->get('limit', $limit); $page = $this->params->get('page', $offset); $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); return $paginatable; } protected function addAddLink($title, $url, $urlParams = null, $target = '_next') { $this->actions()->add(Link::create( $this->translate('Add'), $url, $urlParams, [ 'class' => 'icon-plus', 'title' => $title, 'data-base-target' => $target ] )); return $this; } protected function addBackLink($url, $urlParams = null) { $this->actions()->add(new Link( $this->translate('back'), $url, $urlParams, ['class' => 'icon-left-big'] )); return $this; } /** * @param string $name * * @return QuickForm */ public function loadForm($name) { $form = FormLoader::load($name, $this->Module()); if ($this->getRequest()->isApiRequest()) { // TODO: Ask form for API support? $form->setApiRequest(); } return $form; } /** * @param string $name * * @return QuickTable */ public function loadTable($name) { return TableLoader::load($name, $this->Module()); } /** * @param string $permission * @return $this */ public function assertPermission($permission) { parent::assertPermission($permission); return $this; } public function postDispatch() { Benchmark::measure('Director postDispatch'); if ($this->view->content || $this->view->controls) { $viewRenderer = new SimpleViewRenderer(); $viewRenderer->replaceZendViewRenderer(); $this->view = $viewRenderer->view; if ($this->getOriginalUrl()->getParam('view') === 'compact') { if ($this->view->controls) { $this->controls()->attributes()->add('style', 'display: none;'); } } } else { $viewRenderer = null; } if ($this->getRequest()->isApiRequest()) { $this->_helper->layout()->disableLayout(); if ($viewRenderer) { $viewRenderer->disable(); } else { $this->_helper->viewRenderer->setNoRender(true); } } parent::postDispatch(); // TODO: Change the autogenerated stub } /** * @return Monitoring */ protected function monitoring() { if ($this->monitoring === null) { $this->monitoring = new Monitoring; } return $this->monitoring; } }