コード例 #1
0
 public function collectItems(CollectItemsEvent $event)
 {
     $item = $event->getParentItem();
     if ($item->getType() == 'page') {
         $table = \PageModel::getTable();
         $columns = array("{$table}.pid=?");
         if (!BE_USER_LOGGED_IN) {
             $time = time();
             $columns[] = "({$table}.start='' OR {$table}.start<{$time}) AND ({$table}.stop='' OR {$table}.stop>{$time}) AND {$table}.published=1";
         }
         $pages = \PageModel::findBy($columns, array($item->getExtra('id')), array('order' => 'sorting'));
         if ($pages) {
             $factory = $event->getFactory();
             foreach ($pages as $page) {
                 $factory->createItem('page', $page->id, $item);
             }
         }
     }
     if ($item->getType() == 'pages') {
         $ids = explode(',', $item->getName());
         $ids = array_filter($ids);
         $table = \PageModel::getTable();
         $columns = array('(' . implode(' OR ', array_fill(0, count($ids), "{$table}.id=?")) . ')');
         $sorting = "FIELD({$table}.id, " . implode(', ', array_fill(0, count($ids), "?")) . ")";
         if (!BE_USER_LOGGED_IN) {
             $time = time();
             $columns[] = "({$table}.start='' OR {$table}.start<{$time}) AND ({$table}.stop='' OR {$table}.stop>{$time}) AND {$table}.published=1";
         }
         $pages = \PageModel::findBy($columns, array_merge($ids, $ids), array('order' => $sorting));
         if ($pages) {
             $factory = $event->getFactory();
             foreach ($pages as $page) {
                 $factory->createItem('page', $page->id, $item);
             }
         }
     }
 }
コード例 #2
0
 public function collectItems(CollectItemsEvent $event)
 {
     $item = $event->getParentItem();
     if ($item->getType() == 'page') {
         if (empty($this->columns)) {
             return;
         }
         $columnWildcards = array_fill(0, count($this->columns), '?');
         $columnWildcards = implode(',', $columnWildcards);
         $t = \ArticleModel::getTable();
         $arrColumns = array("{$t}.pid=?", "{$t}.inColumn IN ({$columnWildcards})");
         if (!BE_USER_LOGGED_IN) {
             $time = time();
             $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.published=1";
         }
         $articles = \ArticleModel::findBy($arrColumns, array_merge(array($item->getName()), $this->columns), array('order' => 'sorting'));
         if ($articles) {
             $factory = $event->getFactory();
             foreach ($articles as $article) {
                 $factory->createItem('article', $article->id, $item);
             }
         }
     }
 }
コード例 #3
0
 /**
  * Collect all metamodels items and create navigation items.
  * @param CollectItemsEvent $event
  */
 public function collectItems(CollectItemsEvent $event)
 {
     $item = $event->getParentItem();
     // match pointing point
     if ($item->getType() != $this->getParentType() || $item->getName() != $this->getParentName()) {
         return;
     }
     $collection = $this->fetchMetaModelsItems();
     $factory = $event->getFactory();
     foreach ($collection as $model) {
         $table = $model->getMetaModel()->getTableName();
         $name = sprintf('%s::%s::%s', $table, $model->get('id'), $this->providerId);
         static::$cache[$name] = $model;
         $factory->createItem('metamodels', $name, $item);
     }
 }
コード例 #4
0
 public function collectItems(CollectItemsEvent $event)
 {
     $item = $event->getParentItem();
     if ($item->getType() == 'article') {
         $t = \ContentModel::getTable();
         $arrColumns = array("{$t}.pid=?", "({$t}.ptable='' OR {$t}.ptable='tl_article')", "{$t}.cssID!=''");
         if (!BE_USER_LOGGED_IN) {
             $time = time();
             $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.invisible=''";
         }
         $contents = \ContentModel::findBy($arrColumns, array($item->getName()), array('order' => 'sorting'));
         if ($contents) {
             $factory = $event->getFactory();
             $reachedLevel = 7;
             foreach ($contents as $content) {
                 $headline = deserialize($content->headline, true);
                 $cssID = deserialize($content->cssID, true);
                 if (!empty($headline['value']) && !empty($headline['unit']) && !empty($cssID[0])) {
                     $elementLevel = (int) substr($headline['unit'], 1);
                     if ($elementLevel <= $reachedLevel) {
                         $factory->createItem('content', $content->id, $item);
                         $reachedLevel = $elementLevel;
                     }
                 }
             }
         }
     } else {
         if ($item->getType() == 'content') {
             $thisHeadline = deserialize($item->getExtra('headline'), true);
             if (!empty($thisHeadline['unit'])) {
                 $expectedLevel = intval(substr($thisHeadline['unit'], 1)) + 1;
                 $t = \ContentModel::getTable();
                 $arrColumns = array("{$t}.pid=?", "({$t}.ptable='' OR {$t}.ptable='tl_article')", "{$t}.cssID!=''", "{$t}.sorting > ?");
                 if (!BE_USER_LOGGED_IN) {
                     $time = time();
                     $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.invisible=''";
                 }
                 $contents = \ContentModel::findBy($arrColumns, array($item->getExtra('pid'), $item->getExtra('sorting')), array('order' => 'sorting'));
                 if ($contents) {
                     $factory = $event->getFactory();
                     $reachedLevel = 7;
                     foreach ($contents as $content) {
                         $headline = deserialize($content->headline, true);
                         $cssID = deserialize($content->cssID, true);
                         if (!empty($headline['value']) && !empty($headline['unit']) && !empty($cssID[0])) {
                             $elementLevel = (int) substr($headline['unit'], 1);
                             // level is one down
                             if ($elementLevel >= $expectedLevel && $elementLevel <= $reachedLevel) {
                                 $factory->createItem('content', $content->id, $item);
                                 $reachedLevel = $elementLevel;
                             } else {
                                 if ($elementLevel < $expectedLevel) {
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }