/**
  * 编辑部门
  * @author jry <*****@*****.**>
  */
 public function edit($id)
 {
     if (IS_POST) {
         $group_object = D('Group');
         $_POST['menu_auth'] = json_encode(I('post.menu_auth'));
         $data = $group_object->create();
         if ($data) {
             if ($group_object->save($data) !== false) {
                 $this->success('更新成功', U('index'));
             } else {
                 $this->error('更新失败');
             }
         } else {
             $this->error($group_object->getError());
         }
     } else {
         // 获取部门信息
         $info = D('Group')->find($id);
         $info['menu_auth'] = json_decode($info['menu_auth'], true);
         // 获取现有部门
         $map['status'] = array('egt', 0);
         $all_group = select_list_as_tree('Group', $map, '顶级部门');
         // 获取所有安装并启用的功能模块
         $moule_list = D('Module')->where(array('status' => 1))->select();
         // 获取功能模块的后台菜单列表
         $tree = new Tree();
         $all_module_menu_list = array();
         foreach ($moule_list as $key => $val) {
             $temp = json_decode($val['admin_menu'], true);
             $menu_list_item = $tree->list_to_tree($temp);
             $all_module_menu_list[$val['name']] = $menu_list_item[0];
         }
         $this->assign('info', $info);
         $this->assign('all_module_menu_list', $all_module_menu_list);
         $this->assign('all_group', $all_group);
         $this->assign('meta_title', '编辑部门');
         $this->display('add_edit');
     }
 }
Beispiel #2
0
 /**
  * 获取导航树,指定导航则返回指定导航的子导航树,不指定则返回所有导航树,指定导航若无子导航则返回同级导航
  * @param  integer $id    导航ID
  * @param  boolean $field 查询字段
  * @return array          导航树
  * @author jry <*****@*****.**>
  */
 public function getNavTree($id = 0, $field = true)
 {
     // 获取当前导航信息
     if ((int) $id > 0) {
         $info = $this->find($id);
         $id = $info['id'];
     }
     // 获取所有导航
     $map['status'] = array('eq', 1);
     $tree = new Tree();
     $list = $this->field($field)->where($map)->order('sort asc')->select();
     // 返回当前导航的子导航树
     $list = $tree->list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = (int) $id);
     if (!$list) {
         return $this->getSameLevelNavTree($id);
     }
     return $list;
 }
Beispiel #3
0
 /**
  * 获取导航树,指定导航则返回指定导航的子导航树,不指定则返回所有导航树,指定导航若无子导航则返回同级导航
  * @param  integer $id    导航ID
  * @param  boolean $field 查询字段
  * @return array          导航树
  * @author jry <*****@*****.**>
  */
 public function getNavTree($id = 0, $group = 'main', $field = true)
 {
     if (!in_array(MODULE_NAME, array('Home', 'Admin', 'Common', 'Install')) && is_file(APP_PATH . MODULE_NAME . '/Model/NavModel.class.php')) {
         $module_nav_tree = D(MODULE_NAME . '/Nav')->getNavTree($id, $group, $field);
         if ($module_nav_tree) {
             return $module_nav_tree;
         }
     }
     // 获取当前导航信息
     if ((int) $id > 0) {
         $info = $this->find($id);
         $id = $info['id'];
     }
     // 获取所有导航
     $map['status'] = array('eq', 1);
     $map['group'] = array('eq', $group);
     $tree = new Tree();
     $list = $this->field($field)->where($map)->order('sort asc,id asc')->select();
     // 返回当前导航的子导航树
     $list = $tree->list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = (int) $id);
     if (!$list) {
         return $this->getSameLevelNavTree($id);
     }
     return $list;
 }