Add a browse / ceate / edit / show / / sleanup etc.. menu item

@param string $label
@param string $privilege
@param string $controller
@param array $other
@return \Gems_Menu_SubMenuItem
764239
public function addAgendaSetupPage($label, $privilege, $controller, array $other = array())
    {
        $page = $this->addPage($label, $privilege, $controller, 'index', $other);
        $page->addAutofilterAction();
        $page->addCreateAction();
        $page->addExportAction();
        $page->addImportAction();
        $show = $page->addShowAction();
        $show->addEditAction();
        $show->addDeleteAction();

        $show->addAction($this->_('Clean up'), $privilege . '.cleanup', 'cleanup')
                ->setModelParameters(1);

        return $page;
    }
560845
public function addGroup($name, $label, $priority = 0): ControlCollection
    {
        $this->groups[$name] = compact('label', 'priority');

        return $this;
    }
1275963
protected function _toNavigationArray(\Gems_Menu_ParameterCollector $source)
    {
        $result = parent::_toNavigationArray($source);

        $store  = self::_getSessionStore($this->get('label'));
        if (isset($store->controller)) {
            foreach ($result['pages'] as $page) {
                if ($page['controller'] === $store->controller) {
                    if (isset($store->action) && $page['action'] === $store->action) {
                        $result['action'] = $store->action;
                        $this->set('action', $store->action);
                    }
                    $result['controller'] = $store->controller;
                    $this->set('controller', $store->controller);
                }
            }
        }

        // Get any missing MVC keys from children, even when invisible
        if ($requiredIndices = $this->notSet('controller', 'action')) {

            if (isset($result['pages'])) {
                $firstChild = null;
                $order = 0;
                foreach ($result['pages'] as $page) {
                    if ($page['allowed']) {
                        if ($page['order'] < $order || $order == 0) {
                            $firstChild = $page;
                            $order = $page['order'];
                        }
                    }
                }

                if (null === $firstChild) {
                    // No children are visible and required mvc properties
                    // are missing: ergo this page is not visible.
                    $result['visible'] = false;

                    // Use first (invisible) child as firstChild
                    $firstChild = reset($result['pages']);
                }
            } else {
                // Use '/' slash as default to ensure any not visible
                // menu items points to another existing item that is
                // active.
                $firstChild = array_fill_keys($requiredIndices, '/');
            }

            foreach ($requiredIndices as $key) {
                $result[$key] = $firstChild[$key];
            }
        }

        return $result;
    }
976983
public function beforeRender(Controller $controller) {
        $badges = array();

        foreach (Configure::read('Admin.menu') as $section => $menu) {
            $badges[$section] = $menu['count'];
        }

        $controller->set('badgeCounts', $badges);

        if (isset($controller->Model)) {
            $controller->set('model', $controller->Model);
        }

        if (isset($controller->request->params['override'])) {
            $controller->layout = 'Admin.admin';
            $controller->request->params['action'] = str_replace('admin_', '', $controller->action);
        }
    }
1262030
public function onKernelController(FilterControllerEvent $event)
    {
        $controllerDefinition = $event->getController();
        $controller = $controllerDefinition[0];

        if (
            !$controller instanceof SecuredControllerInterface &&
            !$controller instanceof SecuredObjectControllerInterface
        ) {
            return;
        }

        $request = $event->getRequest();

        // find appropriate permission type for request
        $permission = '';

        switch ($request->getMethod()) {
            case 'GET':
                $permission = PermissionTypes::VIEW;
                break;
            case 'POST':
                if ('postAction' == $controllerDefinition[1]) { // means that the ClassResourceInterface has to be used
                    $permission = PermissionTypes::ADD;
                } else {
                    $permission = PermissionTypes::EDIT;
                }
                break;
            case 'PUT':
            case 'PATCH':
                $permission = PermissionTypes::EDIT;
                break;
            case 'DELETE':
                $permission = PermissionTypes::DELETE;
                break;
        }

        $securityContext = null;
        $locale = $controller->getLocale($request);
        $objectType = null;
        $objectId = null;

        if ($controller instanceof SecuredObjectControllerInterface) {
            $objectType = $controller->getSecuredClass();
            $objectId = $controller->getSecuredObjectId($request);
        }

        // check permission
        if ($controller instanceof SecuredControllerInterface) {
            $securityContext = $controller->getSecurityContext();
        }

        if (null !== $securityContext) {
            $this->securityChecker->checkPermission(
                new SecurityCondition($securityContext, $locale, $objectType, $objectId),
                $permission
            );
        }
    }
1080663
public function addItem(string $id, string $label, string $uri = null, string $icon = null, array $attributes = []): Menu
    {
        $attributes = Arr::except($attributes, ['label', 'uri']);

        $this->dispatcher->dispatch(new ItemAdding($id, $this->generateMenuItem($this->menuItem)));

        if ($icon && Str::startsWith($icon, 'zmdi-')) {
            $icon = 'zmdi ' . $icon;
        }
        if ($icon && !app('antares.request')->shouldMakeApiResponse()) {
            $label = sprintf('<i class="%s"></i> %s', $icon, $label);
        }

        $item = $this->menuItem->addChild($id, array_merge($attributes, [
            'label' => $label,
            'uri'   => $uri,
            'icon'  => $icon,
        ]));
        $item->setAttributes(array_merge($attributes, ['icon' => $icon]));

        $item->setExtra('safe_label', true);

        $this->dispatcher->dispatch(new ItemAdded($id, $this->generateMenuItem($this->menuItem)));

        return $this;
    }
1275015
public function addTrackBuilderMenu($label, array $other = array())
    {
        $setup = $this->addContainer($label);

        // SURVEY SOURCES CONTROLLER
        $page = $setup->addPage($this->_('Survey Sources'), 'pr.source', 'source');
        $page->addAutofilterAction();
        $page->addCreateAction();
        $page->addExportAction();
        $page->addImportAction();
        $show = $page->addShowAction();
        $show->addEditAction();
        $show->addDeleteAction();

        $show->addAction($this->_('Check status'), null, 'ping')
                ->addParameters(\MUtil_Model::REQUEST_ID);
        $show->addAction($this->_('Synchronize surveys'), 'pr.source.synchronize', 'synchronize')
                ->addParameters(\MUtil_Model::REQUEST_ID);
        $show->addAction($this->_('Check is answered'), 'pr.source.check-answers', 'check')
                ->addParameters(\MUtil_Model::REQUEST_ID);
        $show->addAction($this->_('Check attributes'), 'pr.source.check-attributes', 'attributes')
                ->addParameters(\MUtil_Model::REQUEST_ID);

        $page->addAction($this->_('Synchronize all surveys'), 'pr.source.synchronize-all', 'synchronize-all');
        $page->addAction($this->_('Check all is answered'), 'pr.source.check-answers-all', 'check-all');
        $page->addAction($this->_('Check all attributes'), 'pr.source.check-attributes-all', 'attributes-all');

        // ADD CHART SETUP CONTROLLER
        $setup->addBrowsePage($this->_('Charts setup'), 'pr.chartsetup', 'chartconfig');

        // ADD CONDITIONS CONTROLLER - do not include import/export as this is handled by track import/export
        $conditions = $setup->addPage($this->_('Conditions'), 'pr.conditions', 'condition');
        $conditions->addAutofilterAction();
        $conditions->addCreateAction();
        $show = $conditions->addShowAction();
        $show->addEditAction();
        $show->addDeleteAction();

        // SURVEY MAINTENANCE CONTROLLER
        $page = $setup->addPage($this->_('Surveys'), 'pr.survey-maintenance', 'survey-maintenance');
        $page->addAutofilterAction();
        $page->addExportAction();
        $showPage = $page->addShowAction();
        $showPage->addEditAction();
        $showPage->addAction($this->_('Check is answered'), 'pr.survey-maintenance.check', 'check')
                ->addParameters(\MUtil_Model::REQUEST_ID)
                ->setParameterFilter('gsu_active', 1);
        $showPage->addAction($this->_('Import answers'), 'pr.survey-maintenance.answer-import', 'answer-import')
                ->addParameters(\MUtil_Model::REQUEST_ID)
                ->setParameterFilter('gsu_active', 1);
        $showPage->addPdfButton($this->_('PDF'), 'pr.survey-maintenance')
                ->addParameters(\MUtil_Model::REQUEST_ID)
                ->setParameterFilter('gsu_has_pdf', 1);
        // Multi survey
        $page->addAction($this->_('Check all is answered'), 'pr.survey-maintenance.check-all', 'check-all');
        $page->addAction($this->_('Import answers'), 'pr.survey-maintenance.answer-import', 'answer-imports');

        $page->addPage($this->_('Update to new survey'), 'pr.track-maintenance.edit', 'update-survey', 'run');

        // TRACK MAINTENANCE CONTROLLER
        $page = $setup->addPage($this->_('Tracks'), 'pr.track-maintenance', 'track-maintenance', 'index');
        $page->addAutofilterAction();
        $page->addCreateAction();
        //$page->addExportAction();
        $page->addImportAction();
        $showPage = $page->addShowAction();
        $showPage->addEditAction();
        $showPage->addDeleteAction();
        /*$showPage->addButtonOnly($this->_('Copy'),  'pr.track-maintenance.copy', 'track-maintenance', 'copy')
                ->setModelParameters(1);*/

        $showPage->addAction($this->_('Export'), 'pr.track-maintenance.export', 'export')
                 ->addParameters(\MUtil_Model::REQUEST_ID);
        $showPage->addAction($this->_('Check rounds'), 'pr.track-maintenance.check', 'check-track')
                ->addParameters(\MUtil_Model::REQUEST_ID)
                ->setParameterFilter('gtr_active', 1);
        $showPage->addAction($this->_('Recalculate fields'), 'pr.track-maintenance.check', 'recalc-fields')
                ->addParameters(\MUtil_Model::REQUEST_ID)
                ->setParameterFilter('gtr_active', 1);

        // Fields
        $fpage = $showPage->addPage($this->_('Fields'), 'pr.track-maintenance', 'track-fields')
                ->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gtf_id_track');
        $fpage->addAutofilterAction();
        $fpage->addCreateAction('pr.track-maintenance.create')
                ->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gtf_id_track');
        $fpage = $fpage->addShowAction()
                ->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gtf_id_track', \Gems_Model::FIELD_ID, 'gtf_id_field', 'sub', 'sub');
        $fpage->addEditAction('pr.track-maintenance.edit')
                ->addNamedParameters(\Gems_Model::FIELD_ID, 'gtf_id_field', \MUtil_Model::REQUEST_ID, 'gtf_id_track', 'sub', 'sub');
        $fpage->addDeleteAction('pr.track-maintenance.delete')
                ->addNamedParameters(\Gems_Model::FIELD_ID, 'gtf_id_field', \MUtil_Model::REQUEST_ID, 'gtf_id_track', 'sub', 'sub');

        // Rounds
        $rpage = $showPage->addPage($this->_('Rounds'), 'pr.track-maintenance', 'track-rounds')
                ->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gro_id_track');
        $rpage->addAutofilterAction();
        $rpage->addCreateAction('pr.track-maintenance.create')
                ->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gro_id_track');
        $spage = $rpage->addShowAction()
                ->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gro_id_track', \Gems_Model::ROUND_ID, 'gro_id_round');
        $spage->addEditAction('pr.track-maintenance.edit')
                ->addNamedParameters(\Gems_Model::ROUND_ID, 'gro_id_round', \MUtil_Model::REQUEST_ID, 'gro_id_track');
        $spage->addDeleteAction('pr.track-maintenance.delete')
                ->addNamedParameters(\Gems_Model::ROUND_ID, 'gro_id_round', \MUtil_Model::REQUEST_ID, 'gro_id_track');

        $ajaxPage = $this->addPage($this->_('Sort rounds'), 'pr.track-maintenance.edit', 'track-rounds', 'sort', array('visible' => false));

        $overviewPage = $page->addPage($this->_('Tracks per org'), 'pr.track-maintenance.trackperorg', 'track-overview', 'index');
        $overviewPage->addExportAction();
        $overviewPage->addAutofilterAction();

        $page->addAction($this->_('Check all rounds'), 'pr.track-maintenance.check-all', 'check-all');
        $page->addAction($this->_('Recalculate all fields'), 'pr.track-maintenance.check-all', 'recalc-all-fields');

        return $setup;
    }
783114
public function addChild($class, $id, $label, $permission, $options =[])
    {
        if (is_string($id)) {
            $id = explode('/', $id);
        }

        if (count($id) == 1) {
            if (isset($this->childItems[$id[0]])) {
                return $this->childItems[$id[0]];
            }

            $item = $this->itemBuilder->create(
                $class,
                $id[0],
                $this->getPath() . '/' . $id[0],
                $label,
                $permission,
                $options
            );
            $this->childItems[$id[0]] = $item;
            return $item;
        }

        $parent = array_splice($id, 0, count($id) - 1);
        return $this->getChild($parent)->addChild($class, $id, $label, $permission, $options);
    }
137260
public function addBadge($label, $colorOrStatus = null, $toolTipLabel = null, $url = null)
    {
        if ($label === null) {
            $this->badges = [];
        } else {
            $this->badges[] = $this->getBadgeElementArray($label, $colorOrStatus, $toolTipLabel, $url);
        }
        return $this;
    }
1355887
public function addOption($value, string $label): Menu
    {
        $this->addMenuItem(
            new MenuOption(
                $value,
                $label,
                function (CliMenu $menu) {
                    $this->result = $menu->getSelectedItem()->getValue();
                    $menu->close();
                }
            )
        );

        return $this;
    }
701992
public function gotoStartPage(\Gems_Menu $menu, \Zend_Controller_Request_Abstract $request)
    {
        if (false && $this->isPasswordResetRequired()) {
            // Set menu OFF
            // This code may be obsolete from 1.8.4
            $menu->setVisible(false);

            $menuItem = $menu->findController('option', 'change-password');
            // This may not yet be true, but is needed for the redirect.
            $menuItem->set('allowed', true);
            $menuItem->set('visible', true);
        } else {
            $menuItem = $menu->findFirst(array('allowed' => true, 'visible' => true));
        }

        if ($menuItem) {
            // Prevent redirecting to the current page.
            if (! ($menuItem->is('controller', $request->getControllerName()) && $menuItem->is('action', $request->getActionName()))) {
                if (!$menuItem->has('controller')) {
                    //This is a container, try to find first active child
                    $item = $menuItem;
                    foreach ($item->sortByOrder()->getChildren() as $menuItem) {
                        if ($menuItem->isAllowed() && $menuItem->has('controller')) {
                            break;
                        }
                        $menuItem = null;
                    }
                }

                if ($menuItem) {
                    $redirector = \Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
                    $redirector->gotoRoute($menuItem->toRouteUrl($request), null, true);
                }
            }
        }

        return $menuItem;
    }
300477
public static function appendLabel($uri, $label)
    {
        $host = new Host(self::filterUri($uri)->getHost());
        if ($host->isDomain()) {
            return $uri->withHost((string) (new Domain($host))->append($label));
        }

        if ($host->isIpv4()) {
            $label = ltrim((string) new Host($label), '.');

            return $uri->withHost((string) $host->withContent($host->getContent().'.'.$label));
        }

        throw new SyntaxError(sprintf('The URI host %s can not be appended', (string) $host));
    }
834771
final protected function addMenuEntry($label, $path, $icon = null, $permission = null)
    {
        Deprecated::method(null, 'registerMenuEntries');

        $this->menuEntries[] = (new MenuEntry($label, $path))
            ->setLabel($label)
            ->setIcon($icon)
            ->setPermission($permission)
        ;
    }
25302
public function getCurrentMenuList(\Zend_Controller_Request_Abstract $request, $parentLabel = null)
    {
        $controller = $request->getControllerName();
        $action     = $request->getActionName();

        $menuList = $this->getMenuList();

        if ($controller !== 'index') {
            $menuList->addByController($controller, 'index', $parentLabel);
        }

        foreach ($this->getCurrent()->getChildren() as $child) {
            if ($child instanceof \Gems_Menu_SubMenuItem) {
                $chAction = $child->get('action');
                $chContr  = $child->get('controller');
                if (! ($controller == $chContr && $action == $chAction)) {
                    $menuList->addByController($chContr, $chAction);
                }
            }
        }
        return $menuList;
    }
182786
public function notEq($other, array $options = []): Image
    {
        return $this->callEnum($other, 'relational', OperationRelational::NOTEQ, $options);
    }
1317105
public function addMenu(string $label, Addon\DropDownMenu $menu, bool $active = false, bool $disabled = false)
    {
        $this->items[] = [
            'label'    => $label, 
            'menu'     => $menu, 
            'active'   => $active, 
            'disabled' => $disabled
        ];
        return $this;
    }
841266
public function resource(string $name, string $controller) : ResourceController
    {
        return $this->resourceController->resourceController($this, $name, $controller);
    }