예제 #1
0
 /**
  * Save one menu item.
  *
  * @param MenuItem $menuItem
  * @return integer
  */
 public function saveItem(MenuItem $menuItem)
 {
     $fields = array('href' => $menuItem->getHref(), 'title' => $menuItem->getTitle(), 'menu_id' => $menuItem->getMenuId(), 'sort' => $menuItem->getSort(), 'parent_id' => $menuItem->getParentId(), 'page_id' => $menuItem->getSiteId(), 'box_id' => $menuItem->getBoxId(), 'box_key' => $menuItem->getBoxKey(), 'type' => $menuItem->getType(), 'module_key' => $menuItem->getModuleKey());
     foreach ($fields as $key => $value) {
         if ($value === null) {
             unset($fields[$key]);
         }
     }
     $itemId = (int) $this->db()->select('id', 'menu_items', array('id' => $menuItem->getId()))->execute()->fetchCell();
     if ($itemId) {
         $this->db()->update('menu_items')->values($fields)->where(array('id' => $itemId))->execute();
     } else {
         $itemId = $this->db()->insert('menu_items')->values($fields)->execute();
     }
     return $itemId;
 }
예제 #2
0
 /**
  * Gets the menu items as html-string.
  *
  * @param \Modules\Admin\Models\MenuItem $item
  * @param array $options
  * @return string
  */
 protected function recGetItems($item, $locale, $options = array())
 {
     $menuMapper = new \Modules\Admin\Mappers\Menu();
     $pageMapper = new \Modules\Page\Mappers\Page();
     $subItems = $menuMapper->getMenuItemsByParent($item->getMenuId(), $item->getId());
     $html = '';
     if (in_array($item->getType(), array(1, 2, 3))) {
         $html = '<li>';
     }
     if ($item->getType() == 1) {
         $html .= '<a href="' . $item->getHref() . '">' . $item->getTitle() . '</a>';
     } elseif ($item->getType() == 2) {
         $page = $pageMapper->getPageByIdLocale($item->getSiteId(), $locale);
         $html .= '<a href="' . $this->layout->getUrl($page->getPerma()) . '">' . $item->getTitle() . '</a>';
     } elseif ($item->getType() == 3) {
         $html .= '<a href="' . $this->layout->getUrl(array('module' => $item->getModuleKey(), 'action' => 'index', 'controller' => 'index')) . '">' . $item->getTitle() . '</a>';
     }
     if (!empty($subItems)) {
         if (isset($options['class_ul'])) {
             $html .= '<ul class="' . $options['class_ul'] . '">';
         } else {
             $html .= '<ul class="list-unstyled ilch_menu_ul">';
         }
         foreach ($subItems as $subItem) {
             $html .= $this->recGetItems($subItem, $locale, $options);
         }
         $html .= '</ul>';
     }
     if (in_array($item->getType(), array(1, 2, 3))) {
         $html .= '</li>';
     }
     return $html;
 }