Example #1
0
 public function __invoke(Page $page)
 {
     if (isset($page->dynamic) && $page->dynamic) {
         $p = $page->route_match->getParams();
         if (isset($p['id'])) {
             $id = $p['id'];
             $route = $page->route;
             $sl = $this->getServiceLocator()->getServiceLocator();
             $em = $this->getEntityManager();
             $objRepository = $em->getRepository($this->getEntityClass($p['controller']));
             $entity = $objRepository->find($id);
             switch ($route) {
                 case 'account/application':
                     $page->params = ['id' => $id];
                     $page->setLabel($entity->getName());
                     break;
                 case 'report/application':
                     $page->params = ['id' => $id];
                     $page->setLabel($entity->getName());
                     break;
                 case 'lead/search':
                     $page->params = ['id' => $id];
                     if ($entity) {
                         $page->setLabel($entity->getName());
                     }
                     break;
             }
         }
     }
 }
Example #2
0
 /**
  * @param Mvc $page
  *
  * @return void;
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Call::class)) {
         /** @var Nda $nda */
         $call = $this->getEntities()->get(Call::class);
         $label = (string) $this->translate(sprintf("txt-view-nda-for-call-%s", $call));
     } else {
         $label = $this->translate('txt-nav-nda');
     }
     $page->set('label', $label);
 }
 /**
  * @param Mvc $page
  *
  * @return void
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Organisation::class)) {
         /** @var Organisation $organisation */
         $organisation = $this->getEntities()->get(Organisation::class);
         $page->setParams(array_merge($page->getParams(), ['id' => $organisation->getId()]));
         $label = (string) $organisation;
     } else {
         $label = $this->translate('txt-nav-view');
     }
     $page->set('label', $label);
 }
Example #4
0
 /**
  * @param Mvc $page
  *
  * @return void
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Selection::class)) {
         /** @var Selection $selection */
         $selection = $this->getEntities()->get(Selection::class);
         $page->setParams(array_merge($page->getParams(), ['id' => $selection->getId()]));
         $label = (string) $selection->getSelection();
     } else {
         $label = $this->translate('txt-nav-selection');
     }
     $page->set('label', $label);
 }
Example #5
0
 /**
  * @param Mvc $page
  *
  * @return void;
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Calendar::class)) {
         /** @var Calendar $calendar */
         $calendar = $this->getEntities()->get(Calendar::class);
         $page->setParams(array_merge($page->getParams(), ['id' => $calendar->getId()]));
         $label = (string) $calendar;
     } else {
         $label = $this->translate('txt-nav-calendar');
     }
     $page->set('label', $label);
 }
Example #6
0
 /**
  * Parse a Funder Contact label
  *
  * @param Mvc $page
  *
  * @return void
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Contact::class)) {
         /** @var Contact $contact */
         $contact = $this->getEntities()->get(Contact::class);
         $page->setParams(array_merge($page->getParams(), ['id' => $contact->getId()]));
         $label = (string) $contact->getDisplayName();
     } else {
         $label = $this->translate('txt-nav-contact');
     }
     $page->set('label', $label);
 }
Example #7
0
 /**
  * Parse a Funder Facebook label
  *
  * @param Mvc $page
  *
  * @return void
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Facebook::class)) {
         /** @var Facebook $facebook */
         $facebook = $this->getEntities()->get(Facebook::class);
         $page->setParams(array_merge($page->getParams(), ['id' => $facebook->getId()]));
         $label = (string) $facebook->getFacebook();
     } else {
         $label = $this->translate('txt-nav-facebook');
     }
     $page->set('label', $label);
 }
 /**
  * @param Mvc $page
  *
  * @return void
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Affiliation::class)) {
         /** @var Affiliation $affiliation */
         $affiliation = $this->getEntities()->get(Affiliation::class);
         $this->getEntities()->set(Project::class, $affiliation->getProject());
         $page->setParams(array_merge($page->getParams(), ['id' => $affiliation->getId()]));
         $label = (string) $affiliation;
     } else {
         $label = $this->translate('txt-nav-view');
     }
     $page->set('label', $label);
 }
Example #9
0
 /**
  * @param Mvc $page
  *
  * @return void;
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Document::class)) {
         /** @var Document $document */
         $document = $this->getEntities()->get(Document::class);
         $this->getEntities()->set(Calendar::class, $document->getCalendar());
         $page->setParams(array_merge($page->getParams(), ['id' => $document->getId()]));
         $label = (string) $document;
     } else {
         $label = $this->translate('txt-nav-document');
     }
     $page->set('label', $label);
 }
Example #10
0
 /**
  * @param Mvc $page
  *
  * @return void
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Doa::class)) {
         /** @var Doa $doa */
         $doa = $this->getEntities()->get(Doa::class);
         $this->getEntities()->set(Affiliation::class, $doa->getAffiliation());
         $this->getEntities()->set(Project::class, $doa->getAffiliation()->getProject());
         $page->setParams(array_merge($page->getParams(), ['id' => $doa->getId()]));
         $label = $this->translate('txt-doa');
     } else {
         $label = $this->translate('txt-nav-view');
     }
     $page->set('label', $label);
 }
Example #11
0
 /**
  * Returns href for this page
  *
  * This method uses {@link RouteStackInterface} to assemble
  * the href based on the page's properties.
  *
  * @see RouteStackInterface
  * @return string  page href
  * @throws Exception\DomainException if no router is set
  */
 public function getHref()
 {
     $url = parent::getHref();
     if (!empty($this->get('locale'))) {
         $url = '/' . $this->get('locale') . $url;
     }
     return $url;
 }
Example #12
0
 public function __invoke(Event $e)
 {
     $router = $e->getRouter();
     Page::setDefaultRouter($router);
     if (null === $this->cache || null === ($navigation = $this->cache->getItem(self::CACHE_KEY))) {
         $collection = $e->getTarget()->getPageCollection();
         $navigation = $this->parser->parse($collection);
         if (null !== $this->cache) {
             $this->cache->setItem(self::CACHE_KEY, $navigation);
         }
     }
     $this->helper->setContainer($navigation);
 }
Example #13
0
 public function onBootstrap(MvcEvent $e)
 {
     $sm = $e->getApplication()->getServiceManager();
     /* @var $eventManager \Zend\EventManager\EventManager */
     $eventManager = $e->getApplication()->getEventManager();
     $eventManager->attach($sm->get('Authorize\\Guard\\Controller'));
     $eventManager->attach($sm->get('Authorize\\View\\UnauthorizedStrategy'));
     /* @var $acl \Authorize\Permission\Acl */
     $acl = $sm->get('Authorize\\Permission\\Acl');
     /* @var $serviceUser \User\Service\User */
     $serviceUser = $sm->get('User\\Service\\User');
     \Zend\View\Helper\Navigation::setDefaultAcl($acl);
     \Zend\Navigation\Page\Mvc::setDefaultRouter($sm->get('router'));
 }
Example #14
0
 /**
  * OnBootstrap listener
  * @param $e
  */
 public function onBootstrap(\Zend\Mvc\MvcEvent $e)
 {
     $application = $e->getApplication();
     $sm = $application->getServiceManager();
     $viewHelperPluginManager = $sm->get('view_helper_manager');
     /* @var $viewHelperPluginManager \Zend\View\HelperPluginManager */
     //Register DluTwBootstrap view helpers
     $viewHelperConfigurator = $sm->get('dlu_twb_view_helper_configurator');
     /* @var $viewHelperConfigurator \DluTwBootstrap\Form\View\HelperConfig */
     $viewHelperConfigurator->configureServiceManager($viewHelperPluginManager);
     //Register DluTwBootstrap view navigation helpers
     $navViewHelperConfigurator = $sm->get('dlu_twb_nav_view_helper_configurator');
     /* @var $navViewHelperConfigurator \DluTwBootstrap\View\Helper\Navigation\PluginConfigurator */
     $navHelperPluginManager = $viewHelperPluginManager->get('navigation')->getPluginManager();
     $navViewHelperConfigurator->configureServiceManager($navHelperPluginManager);
     //Prepare the \Zend\Navigation\Page\Mvc for use
     //The pages in navigation container created with a factory have the router injected,
     //but any other explicitly created page needs the router too, so it makes sense to set the default router
     $router = $sm->get('router');
     \Zend\Navigation\Page\Mvc::setDefaultRouter($router);
 }
Example #15
0
 /**
  * @param Mvc $page
  *
  * @return void;
  */
 public function __invoke(Mvc $page)
 {
     if ($this->getEntities()->containsKey(Nda::class)) {
         /** @var Nda $nda */
         $nda = $this->getEntities()->get(Nda::class);
         if (!is_null($nda->getCall())) {
             $page->setParams(array_merge($page->getParams(), ['id' => $nda->getId(), 'callId' => $nda->getCall()->getId()]));
             $label = (string) $nda;
         } else {
             $page->setParams(array_merge($page->getParams(), ['id' => $nda->getId()]));
             $label = (string) $nda;
         }
     } else {
         $label = $this->translate('txt-nav-nda');
     }
     $page->set('label', $label);
 }
Example #16
0
 /**
  * Returns whether page should be considered active or not
  *
  * This method will compare the page's route name and mvc params with the
  * matched route's name and params
  *
  * @param  bool $recursive  [optional] whether page should be considered
  *                          active if any child pages are active. Default is
  *                          false.
  * @return bool             whether page should be considered active or not
  */
 public function isActive($recursive = false)
 {
     if (!$this->active) {
         //do we have a matched route?
         if ($this->routeMatch instanceof \Zend\Mvc\Router\RouteMatch) {
             if (null !== $this->getRoute() && $this->routeMatch->getMatchedRouteName() === $this->getRoute()) {
                 //get default params and set defaults
                 $myParams = $this->params;
                 if (!isset($myParams['controller'])) {
                     $myParams['controller'] = 'index';
                 }
                 if (!isset($myParams['action'])) {
                     $myParams['action'] = 'index';
                 }
                 //check the controller and action params
                 if (strtolower($this->routeMatch->getParam('__CONTROLLER__')) == strtolower($myParams['controller']) && strtolower($this->routeMatch->getParam('action')) == strtolower($myParams['action'])) {
                     $this->active = true;
                     return true;
                 }
             }
             //if recursive check the sub pages
             if ($recursive) {
                 /** @var $page Mvc */
                 foreach ($this->pages as $page) {
                     $page->setRouteMatch($this->routeMatch);
                     if ($page->isActive(true)) {
                         return true;
                     }
                 }
             }
             return false;
         }
         //no matched route so try parent logic
         return parent::isActive($recursive);
     }
     return true;
 }
Example #17
0
    public function testNoExceptionForGetHrefIfDefaultRouterIsSet()
    {
        $page = new Page\Mvc(array(
            'label'            => 'foo',
            'action'           => 'index',
            'controller'       => 'index',
            'route'            => 'default',
            'defaultRouter'    => $this->router
        ));

        // If the default router is not used an exception will be thrown.
        // This method intentionally has no assertion.
        $page->getHref();
        $page->setDefaultRouter(null);
    }
Example #18
0
 public function testRecursiveDetectIsActiveWhenRouteNameIsKnown()
 {
     $parentPage = new Page\Mvc(array('label' => 'some Label', 'route' => 'parentPageRoute'));
     $childPage = new Page\Mvc(array('label' => 'child', 'route' => 'childPageRoute'));
     $parentPage->addPage($childPage);
     $router = new TreeRouteStack();
     $router->addRoutes(array('parentPageRoute' => array('type' => 'literal', 'options' => array('route' => '/foo', 'defaults' => array('controller' => 'fooController', 'action' => 'fooAction'))), 'childPageRoute' => array('type' => 'literal', 'options' => array('route' => '/bar', 'defaults' => array('controller' => 'barController', 'action' => 'barAction')))));
     $routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'Application\\Controller', 'controller' => 'barController', 'action' => 'barAction'));
     $routeMatch->setMatchedRouteName('childPageRoute');
     $event = new MvcEvent();
     $event->setRouter($router)->setRouteMatch($routeMatch);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->onRoute($event);
     $parentPage->setRouter($event->getRouter());
     $parentPage->setRouteMatch($event->getRouteMatch());
     $childPage->setRouter($event->getRouter());
     $childPage->setRouteMatch($event->getRouteMatch());
     $this->assertTrue($childPage->isActive(true));
     $this->assertTrue($parentPage->isActive(true));
 }
 /**
  * Factory a site map page
  *
  * @return Mvc
  */
 public function factoryMVCPage()
 {
     $application = $this->getServiceLocator()->get('Application');
     $routeMatch = $application->getMvcEvent()->getRouteMatch();
     $router = $this->getServiceLocator()->get('HttpRouter');
     $page = new Mvc();
     $page->setRouteMatch($routeMatch);
     $page->setRouter($router);
     return $page;
 }
Example #20
0
 public function testSpecifyingAnotherUrlHelperToGenerateHrefs()
 {
     $newHelper = new \ZendTest\Navigation\TestAsset\UrlHelper();
     Page\Mvc::setUrlHelper($newHelper);
     $page = new Page\Mvc();
     $expected = \ZendTest\Navigation\TestAsset\UrlHelper::RETURN_URL;
     $actual = $page->getHref();
     $front = FrontController::getInstance();
     $old = $front->getHelperBroker()->load('URL');
     Page\Mvc::setUrlHelper($old);
     $this->assertEquals($expected, $actual);
 }
Example #21
0
 public function testSpecifyingAnotherUrlHelperToGenerateHrefs()
 {
     $newHelper = new TestAsset\UrlHelper();
     $page = new Page\Mvc();
     $page->setUrlHelper($newHelper);
     $expected = TestAsset\UrlHelper::RETURN_URL;
     $actual = $page->getHref();
     $this->assertEquals($expected, $actual);
 }
Example #22
0
 /**
  * Parse a single page into a navigation configuration
  *
  * @param  Page $page
  * @return array
  * @throws Exception\RuntimeException
  */
 public function parsePage(PageInterface $page)
 {
     $meta = $page->getMetaData();
     $navPage = Page::factory(array('type' => 'mvc', 'route' => (string) $page->getId(), 'label' => $meta->getNavigationTitle(), 'visible' => $page->isVisible()));
     $event = new Event();
     $event->setName(__FUNCTION__ . '.' . $page->getModule());
     $event->setTarget($this);
     $event->setParams(array('page' => $page, 'navigation' => $navPage));
     $this->events->trigger($event);
     return $navPage;
 }
Example #23
0
 /**
  * {@inheritDoc}
  */
 public function toArray()
 {
     return array_merge(parent::toArray(), array('section' => $this->getSection(), 'module' => $this->getModule()));
 }
Example #24
0
 public function testInheritedRouteMatchParamsWorkWithModuleRouteListener()
 {
     $page = new Page\Mvc(array('label' => 'mpinkstonwashere', 'route' => 'lmaoplane'));
     $route = new SegmentRoute('/lmaoplane[/:controller]');
     $router = new TreeRouteStack();
     $router->addRoute('lmaoplane', $route);
     $routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'Application\\Controller', 'controller' => 'index'));
     $routeMatch->setMatchedRouteName('lmaoplane');
     $event = new MvcEvent();
     $event->setRouter($router)->setRouteMatch($routeMatch);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->onRoute($event);
     $page->setRouter($event->getRouter());
     $page->setRouteMatch($event->getRouteMatch());
     $this->assertEquals('/lmaoplane', $page->getHref());
     $page->setUseRouteMatch(true);
     $this->assertEquals('/lmaoplane/index', $page->getHref());
 }