Exemplo n.º 1
0
 protected function setUp()
 {
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Resolução de Scripts
     $resolver = new TemplateMapResolver(['error/404' => './module/Balance/view/error/404.phtml', 'error/500' => './module/Balance/view/error/500.phtml', 'layout/page-header' => './module/Balance/view/layout/page-header.phtml', 'layout/navigation' => './module/Balance/view/layout/navigation.phtml']);
     // Rederizador
     $renderer = (new PhpRenderer())->setResolver($resolver);
     // Camada de Visualização
     $view = new ViewModel();
     // Navegação
     $navigation = new Navigation();
     // Página Principal
     $page = new Page(['label' => 'Balance']);
     // Adicionar Página
     $navigation->addPage($page);
     // Configurar Serviço
     $serviceLocator->setService('navigation', $navigation);
     // Auxiliar de Navegação
     $helper = (new Helper())->setContainer($navigation)->setView($renderer);
     // Configurar Auxiliar como Plugin
     $renderer->getHelperPluginManager()->setService('navigation', $helper)->setServiceLocator($serviceLocator);
     // Configurações
     $this->renderer = $renderer;
     $this->view = $view;
     $this->page = $page;
 }
 /**
  * Get the feed list and the posts of the feed we are looking at now
  *
  * @return void
  */
 public function indexAction()
 {
     $viewData = array();
     $flashMessenger = $this->flashMessenger();
     $username = $this->params()->fromRoute('username');
     $currentFeedId = $this->params()->fromRoute('feed_id');
     $userData = ApiClient::getUser($username);
     if ($userData !== FALSE) {
         $hydrator = new ClassMethods();
         $user = $hydrator->hydrate($userData, new User());
     } else {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $subscribeForm = new SubscribeForm();
     $unsubscribeForm = new UnsubscribeForm();
     $subscribeForm->setAttribute('action', $this->url()->fromRoute('feeds-subscribe', array('username' => $username)));
     $unsubscribeForm->setAttribute('action', $this->url()->fromRoute('feeds-unsubscribe', array('username' => $username)));
     $hydrator = new ClassMethods();
     $response = ApiClient::getFeeds($username);
     $feeds = array();
     foreach ($response as $r) {
         $feeds[$r['id']] = $hydrator->hydrate($r, new Feed());
     }
     if ($currentFeedId === null && !empty($feeds)) {
         $currentFeedId = reset($feeds)->getId();
     }
     $feedsMenu = new Navigation();
     $router = $this->getEvent()->getRouter();
     $routeMatch = $this->getEvent()->getRouteMatch()->setParam('feed_id', $currentFeedId);
     foreach ($feeds as $f) {
         $feedsMenu->addPage(AbstractPage::factory(array('title' => $f->getTitle(), 'icon' => $f->getIcon(), 'route' => 'feeds', 'routeMatch' => $routeMatch, 'router' => $router, 'params' => array('username' => $username, 'feed_id' => $f->getId()))));
     }
     $currentFeed = $currentFeedId != null ? $feeds[$currentFeedId] : null;
     if ($currentFeed != null) {
         $paginator = new Paginator(new ArrayAdapter($currentFeed->getArticles()));
         $paginator->setItemCountPerPage(5);
         $paginator->setCurrentPageNumber($this->params()->fromRoute('page'));
         $viewData['paginator'] = $paginator;
         $viewData['feedId'] = $currentFeedId;
     }
     $unsubscribeForm->get('feed_id')->setValue($currentFeedId);
     $viewData['subscribeForm'] = $subscribeForm;
     $viewData['unsubscribeForm'] = $unsubscribeForm;
     $viewData['username'] = $username;
     $viewData['feedsMenu'] = $feedsMenu;
     $viewData['user'] = $user;
     $viewData['paginator'] = $paginator;
     $viewData['feedId'] = $currentFeedId;
     $viewData['feed'] = $currentFeed;
     $this->layout()->username = $username;
     if ($flashMessenger->hasMessages()) {
         $viewData['flashMessages'] = $flashMessenger->getMessages();
     }
     return $viewData;
 }
Exemplo n.º 3
0
 public function addPage($page)
 {
     return parent::addPage($page);
     // TODO: Change the autogenerated stub
 }
Exemplo n.º 4
0
 public function testGetChildrenShouldReturnTheCurrentPage()
 {
     $container = new Navigation\Navigation();
     $page = Page\AbstractPage::factory(array('type' => 'uri'));
     $container->addPage($page);
     $this->assertEquals($page, $container->getChildren());
 }