示例#1
0
 /**
  * Делаем выборку из дерева роутов
  *
  * Дальнейшие операции для производительности идут через масив $this->_routesTree или через getter "$this->getRoutesTree"
  *
  * @param int $parent_id
  * @param string $parent_url
  * @return array
  */
 protected function _buildRoutesTree($childs = false, $parent_url = '')
 {
     if ($childs == false) {
         $select = $this->select()->order('sort ASC');
         $items = $this->fetchAll($select)->toArray();
         $childs = System_Functions::toForest($items, 'route_id', 'parent_route_id');
     }
     $cleanRoutes = array();
     $i = 0;
     foreach ($childs as $row) {
         $cleanRoutes[$i] = $row;
         $cleanRoutes[$i]['url'] = $parent_url . $row['uri'] . '/';
         if (sizeof($row['childs'])) {
             $cleanRoutes[$i]['childs'] = $this->_buildRoutesTree($row['childs'], $cleanRoutes[$i]['url']);
         }
         $cleanRoutes[$i]['module'] = strtolower($cleanRoutes[$i]['module']);
         $cleanRoutes[$i]['controller'] = strtolower($cleanRoutes[$i]['controller']);
         $cleanRoutes[$i]['action'] = strtolower($cleanRoutes[$i]['action']);
         $this->_routesData[$row['route_id']] = $cleanRoutes[$i];
         $i++;
     }
     if ($parent_url == '') {
         return $this->_routesTree = $cleanRoutes;
     } else {
         return $cleanRoutes;
     }
 }
示例#2
0
 /**
  * Получаем дерево разделов определённого меню
  *
  * @param int $menuId
  * @return array
  */
 public function getMenuTree($menuId)
 {
     $menu = $this->getMenu($menuId);
     if (!sizeof($menu)) {
         return array();
     }
     $sections = $this->_modelItems->fetchAll($this->_modelItems->select()->where('menu_id = ?', $menu->menu_id)->order('sort', 'item_id'));
     if ($menu->type == 'router') {
         $routerTree = Modules_Router_Model_Router::getInstance()->getItem($menu->parent_route_id);
         $_makeTreeFromRouter = function ($routerTree, $sections, $parentDisable) use(&$_makeTreeFromRouter) {
             $return = array();
             foreach ($routerTree as $i => $row) {
                 if (1 == $row['disable']) {
                     continue;
                 }
                 $return[$i] = $row;
                 $return[$i]['type'] = 'from_router';
                 $return[$i]['item_id'] = $row['route_id'];
                 $return[$i]['parent_id'] = $row['parent_route_id'];
                 $return[$i]['disable'] = $parentDisable;
                 unset($return[$i]['route_id'], $return[$i]['parent_route_id'], $return[$i]['childs']);
                 if (sizeof($sections)) {
                     foreach ($sections as $item) {
                         if ($item->route_id == $row['route_id']) {
                             $return[$i]['disable'] = $item->disable || $parentDisable;
                             $return[$i]['name'] = $item->name ? $item->name : $row['name'];
                         }
                     }
                 }
                 $return[$i]['childs'] = $_makeTreeFromRouter($row['childs'], $sections, $return[$i]['disable']);
             }
             return $return;
         };
         $sections = $_makeTreeFromRouter($routerTree['childs'], $sections, false);
     } else {
         $_makeUrl = function ($sections) use(&$_makeUrl) {
             $return = array();
             foreach ($sections as $i => $item) {
                 $return[$i] = $item;
                 if ($item['external_link']) {
                     $return[$i]['url'] = $item['external_link'];
                 } else {
                     $return[$i] += Modules_Router_Model_Router::getInstance()->getItem($item['route_id']);
                 }
                 $return[$i]['childs'] = $_makeUrl($item['childs']);
             }
             return $return;
         };
         $sections = System_Functions::toForest($sections->toArray(), 'item_id', 'parent_id');
         $sections = $_makeUrl($sections);
     }
     $this->_setCurrents($sections);
     return $sections;
 }
示例#3
0
 /**
  * Выборка доступных ролей у пользователя в виде дерева
  *
  * @return array()
  */
 public function getAccepdedRolesTree($roles = false)
 {
     $currentRoles = $this->getMyGroup();
     if (!$roles) {
         $roles = $this->_modelRoles->fetchAll()->toArray();
         $roles = System_Functions::toForest($roles, 'name', 'role_parent');
     }
     foreach ($roles as $key => $tree) {
         if ($key == $currentRoles) {
             $return = $tree['childs'];
         } else {
             if (sizeof($tree['childs'])) {
                 $return = $this->getAccepdedRolesTree($tree['childs']);
             }
         }
     }
     return $return;
 }