protected function load()
 {
     if (!$this->loaded) {
         $this->loaded = true;
         $eventDispatcher = $this->factory->getEventDispatcher();
         $eventName = $this->factory->getCollectItemsEventName();
         $event = new CollectItemsEvent($this->factory, $this);
         $eventDispatcher->dispatch($eventName, $event);
     }
 }
 protected function compile()
 {
     // create local event dispatcher and provider
     $eventDispatcher = new EventDispatcher();
     $eventDispatcher->addSubscriber(new ArticleProvider());
     $eventDispatcher->addSubscriber(new ContentProvider());
     // create the event driven menu
     $eventDrivenItemFactory = new EventDrivenItemFactory($eventDispatcher, XNavigationEvents::CREATE_ITEM, XNavigationEvents::COLLECT_ITEMS);
     $item = new Item();
     $items = $item->getChildren();
     if ($this->toc_source == 'sections') {
         global $objPage;
         $sections = deserialize($this->toc_sections, true);
         $where = array();
         $where[] = '(' . implode(' OR ', array_fill(0, count($sections), 'inColumn=?')) . ')';
         $where[] = 'pid=?';
         $args = array_merge($sections, array($objPage->id), $sections);
         $order = 'FIELD(tl_article.inColumn,' . implode(',', array_fill(0, count($sections), '?')) . ')';
         $articles = \ArticleModel::findBy($where, $args, array('order' => $order));
         if ($articles) {
             foreach ($articles as $article) {
                 /** @var \ArticleModel $article */
                 $item = $eventDrivenItemFactory->createItem('article', $article->id);
                 if ($this->toc_include_articles) {
                     $items->add($item);
                 } else {
                     $items->addAll($item->getChildren()->toArray());
                 }
             }
         }
     }
     if ($this->toc_source == 'articles') {
         $articleIds = deserialize($this->toc_articles, true);
         foreach ($articleIds as $articleId) {
             $item = $eventDrivenItemFactory->createItem('article', $articleId);
             if ($this->toc_include_articles) {
                 $items->add($item);
             } else {
                 $items->addAll($item->getChildren()->toArray());
             }
         }
     }
     $this->Template->xnav_template = $this->xnavigation_template;
     $this->Template->items = $items;
     $this->Template->item_condition = $this->createItemCondition();
     $this->Template->link_condition = $this->createLinkCondition();
 }
Exemple #3
0
 /**
  * Create the root item and items collection and assign to the template.
  *
  * @param MenuModel $menu
  * @param string    $rootType
  * @param string    $rootName
  */
 protected function createItems(MenuModel $menu, $rootType, $rootName)
 {
     $providerFactory = new ProviderFactory();
     // create local event dispatcher and provider
     $eventDispatcher = $this->createLocalEventDispatcher($menu, $providerFactory);
     // create the event driven menu
     $eventDrivenItemFactory = new EventDrivenItemFactory($eventDispatcher, XNavigationEvents::CREATE_ITEM, XNavigationEvents::COLLECT_ITEMS);
     // create the root item
     $item = $eventDrivenItemFactory->createItem($rootType, $rootName);
     // create the items collection
     if ($menu->include_root) {
         $collection = new ItemCollection();
         $collection->add($item);
     } else {
         $collection = $item->getChildren();
     }
     $this->Template->item = $item;
     $this->Template->items = $collection;
 }