コード例 #1
0
 /**
  * 过滤权限
  */
 public function filterUser($list)
 {
     $userData = CSession::get('user');
     $groupId = $userData['groupData']['gid'];
     if (1 == $groupId) {
         return $list;
     }
     $category = CDatabase::getInstance()->from('admin_group')->select()->execute()->asArray();
     foreach ($category as $key => $val) {
         $category[$key]['name'] = $val['gname'];
         $category[$key]['id'] = $val['gid'];
     }
     $category = TreeClass::getTree($category);
     // 获取该组ID阔以查看的所有子组ID
     $childData = $childDataVal = array();
     TreeClass::getCatTree($groupId, $category, $childData, $childDataVal);
     // 可以查询的子组ID序列
     $groupList = array();
     foreach ($childDataVal as $key => $val) {
         $groupList[] = $val['gid'];
     }
     foreach ($list as $key => $val) {
         if (!in_array($val['groupId'], $groupList)) {
             unset($list[$key]);
         }
     }
     return $list;
 }
コード例 #2
0
 /**
  * 可添加的角色组
  */
 public function filterCanAddRole($list)
 {
     $userData = CSession::get('user');
     $groupId = $userData['groupData']['gid'];
     // 超级管理员给全部资源
     if (1 == $groupId) {
         return $list;
     }
     $category = CDatabase::getInstance()->from('admin_group')->select()->execute()->asArray();
     foreach ($category as $key => $val) {
         $category[$key]['name'] = $val['gname'];
         $category[$key]['id'] = $val['gid'];
     }
     $category = TreeClass::getTree($category);
     // 获取其子类
     $childData = $childDataVal = array();
     TreeClass::getCatTree($groupId, $category, $childData, $childDataVal);
     foreach ($list as $key => $val) {
         if (!in_array($val['gid'], $childData)) {
             unset($list[$key]);
         }
     }
     return $list;
 }