Example #1
0
 /**
  * Все опубликованные пункты текущего меню с учетом иерархии
  * Показываются только опубликованные и доступные текущему пользователю
  *
  * @return CArrayList
  */
 public function getMenuPublishedItems()
 {
     if (is_null($this->_itemsPublished)) {
         $this->_itemsPublished = new CArrayList();
         foreach (CActiveRecordProvider::getWithCondition(TABLE_MENU_ITEMS, "menu_id=" . $this->getId() . " and published=1")->getItems() as $i) {
             $item = new CMenuItem($i);
             if ($item->getRoles()->getCount() == 0) {
                 $this->_itemsPublished->add($item->getId(), $item);
             } else {
                 if (is_null(CSession::getCurrentUser())) {
                     if ($item->getRoles()->getCount() == 0) {
                         $this->_itemsPublished->add($item->getId(), $item);
                     }
                 } else {
                     foreach ($item->getRoles()->getItems() as $role) {
                         if (CSession::getCurrentUser()->getRoles()->hasElement($role->getId())) {
                             $this->_itemsPublished->add($item->getId(), $item);
                             break;
                         }
                     }
                 }
             }
             CMenuManager::getCacheItems()->add($item->getId(), $item);
         }
         // инициализируем иерархический вывод
     }
     return $this->_itemsPublished;
 }
 /**
  * Все меню
  *
  * @static
  * @return CArrayList
  */
 public static function getAllMenus()
 {
     if (!self::$_cacheInit) {
         self::$_cacheInit = true;
         foreach (CActiveRecordProvider::getAllFromTable(TABLE_MENUS)->getItems() as $i) {
             $menu = new CMenu($i);
             self::getCacheMenu()->add($menu->getId(), $menu);
             self::getCacheMenu()->add($menu->getAlias(), $menu);
         }
     }
     $arr = new CArrayList();
     foreach (self::getCacheMenu()->getItems() as $menu) {
         $arr->add($menu->getId(), $menu);
     }
     return $arr;
 }
 public function actionRemoveItem()
 {
     if (!CSession::isAuth()) {
         $this->redirectNoAccess();
     }
     $item = CMenuManager::getMenuItem(CRequest::getInt("id"));
     $id = $item->getMenu()->getId();
     $item->remove();
     $this->redirect("?action=view&id=" . $id);
 }
Example #4
0
<?php

$menu_str = '<ul class="nav nav-tabs nav-stacked">';
foreach (CMenuManager::getMenu("main_menu")->getMenuPublishedItemsInHierarchy()->getItems() as $item) {
    if ($item->getChilds()->getCount() > 0) {
        $menu_str .= '<li class="dropdown-submenu">';
        $menu_str .= '<a class="dropdown-toggle" data-toggle="dropdown" href="#">';
        $menu_str .= $item->getName();
        $menu_str .= '</a>';
        $menu_str .= '<ul class="dropdown-menu">';
        foreach ($item->getChilds()->getItems() as $child) {
            $menu_str .= '<li><a tabindex="-1" title="' . htmlspecialchars($child->getName()) . '" href="' . htmlspecialchars($child->getLink()) . '">' . $child->getName() . '</a></li>';
        }
        $menu_str .= '</ul>';
        $menu_str .= '</li>';
    } else {
        $menu_str .= '<li><a tabindex="-1" title="' . htmlspecialchars($item->getName()) . '" href="' . htmlspecialchars($item->getLink()) . '">' . $item->getName() . '</a></li>';
    }
}
$menu_str .= '</ul>';
 /**
  * Меню, к которому данный пункт привязан
  *
  * @return CMenu
  */
 public function getMenu()
 {
     if (is_null($this->_menu)) {
         $this->_menu = CMenuManager::getMenu($this->getRecord()->getItemValue("menu_id"));
     }
     return $this->_menu;
 }