예제 #1
0
 /**
  * Рекурсивное построение дерева.
  *
  * @param ItemInterface $menu
  * @param Item|null     $parent_item
  */
 protected function addChild(ItemInterface $menu, Item $parent_item = null)
 {
     $items = null == $parent_item ? $this->em->getRepository('MenuModule:Item')->findByParent($this->menu, null) : $parent_item->getChildren();
     /** @var Item $item */
     foreach ($items as $item) {
         if ($this->is_admin) {
             $uri = $this->container->get('router')->generate('smart_module.menu.admin_item', ['item_id' => $item->getId()]);
         } else {
             $itemUrl = $item->getUrl();
             if ((null === $item->getFolder() or !$item->getFolder()->isActive()) and empty($itemUrl)) {
                 continue;
             }
             $uri = $item->getFolder() ? $this->container->get('cms.folder')->getUri($item->getFolder()) : $itemUrl;
         }
         $item_title = $this->is_admin ? (string) $item . ' (position: ' . $item->getPosition() . ')' : (string) $item;
         $item_title = isset($menu[$item_title]) ? $item_title . ' (' . $item->getId() . ')' : $item_title;
         if ($this->is_admin or $item->getIsActive()) {
             $new_item = $menu->addChild($item_title, ['uri' => $uri]);
             $new_item->setAttributes(['title' => $item->getDescription()])->setExtras($item->getProperties());
             if (!$this->is_admin and $item->getOpenInNewWindow()) {
                 $new_item->setLinkAttribute('target', '_blank');
             }
             if ($this->is_admin and (!$item->getIsActive() or null != $item->getFolder() and !$item->getFolder()->isActive())) {
                 $new_item->setAttribute('style', 'text-decoration: line-through;');
             }
         } else {
             continue;
         }
         $this->addChild($menu[$item_title], $item);
     }
 }
예제 #2
0
 /**
  * @param Item|null $parent_item
  *
  * @return $this
  */
 public function setParentItem($parent_item)
 {
     if (empty($parent_item) or $parent_item->getId() == $this->getId()) {
         $this->parent_item = null;
     } else {
         $this->parent_item = $parent_item;
     }
     return $this;
 }