/** * 回收站列表 * @author huajie <*****@*****.**> */ public function recycle() { //获取左边菜单 $this->getMenu(); $map['status'] = -1; if (!IS_ROOT) { $cate_auth = AuthGroupModel::getAuthCategories(UID); if ($cate_auth) { $map['category_id'] = array('IN', $cate_auth); } else { $map['category_id'] = -1; } } $list = $this->lists(D('Document'), $map, 'update_time desc'); //处理列表数据 if (is_array($list)) { foreach ($list as $k => &$v) { $v['username'] = get_nickname($v['uid']); } } $this->assign('list', $list); $this->meta_title = '回收站'; $this->display(); }
/** * 显示左边菜单,进行权限控制 * @author huajie <*****@*****.**> */ protected function getMenu() { //获取动态分类 $cate_auth = AuthGroupModel::getAuthCategories(UID); //获取当前用户所有的内容权限节点 $cate_auth = $cate_auth == null ? array() : $cate_auth; $cate = M('Category')->where(array('status' => 1))->field('id,title,pid,allow_publish')->order('pid,sort')->select(); //没有权限的分类则不显示 if (!IS_ROOT) { foreach ($cate as $key => $value) { if (!in_array($value['id'], $cate_auth)) { unset($cate[$key]); } } } $cate = list_to_tree($cate); //生成分类树 //获取分类id $cate_id = I('param.cate_id'); $this->cate_id = $cate_id; //是否展开分类 $hide_cate = false; if (ACTION_NAME != 'recycle' && ACTION_NAME != 'draftbox' && ACTION_NAME != 'mydocument') { $hide_cate = true; } //生成每个分类的url foreach ($cate as $key => &$value) { $value['url'] = 'Article/index?cate_id=' . $value['id']; if ($cate_id == $value['id'] && $hide_cate) { $value['current'] = true; } else { $value['current'] = false; } if (!empty($value['_child'])) { $is_child = false; foreach ($value['_child'] as $ka => &$va) { $va['url'] = 'Article/index?cate_id=' . $va['id']; if (!empty($va['_child'])) { foreach ($va['_child'] as $k => &$v) { $v['url'] = 'Article/index?cate_id=' . $v['id']; $v['pid'] = $va['id']; $is_child = $v['id'] == $cate_id ? true : false; } } //展开子分类的父分类 if ($va['id'] == $cate_id || $is_child) { $is_child = false; if ($hide_cate) { $value['current'] = true; $va['current'] = true; } else { $value['current'] = false; $va['current'] = false; } } else { $va['current'] = false; } } } } $this->assign('nodes', $cate); $this->assign('cate_id', $this->cate_id); //获取面包屑信息 $nav = get_parent_category($cate_id); $this->assign('rightNav', $nav); //获取回收站权限 $show_recycle = $this->checkRule('Admin/article/recycle'); $this->assign('show_recycle', IS_ROOT || $show_recycle); //获取草稿箱权限 $show_draftbox = C('OPEN_DRAFTBOX'); $this->assign('show_draftbox', IS_ROOT || $show_draftbox); }
/** * 回收站列表 * @author huajie <*****@*****.**> */ public function recycle() { //获取左边菜单 $this->getMenu(); if (IS_ROOT) { $map = array('status' => -1); } else { $cate_auth = AuthGroupModel::getAuthCategories(UID); if ($cate_auth) { $map = array('status' => -1, 'category_id' => array('IN', implode(',', $cate_auth))); } else { $map = array('status' => -1, 'category_id' => -1); } } $list = M('Document')->where($map)->field('id,title,uid,category_id,type,update_time')->order('update_time desc')->select(); //处理列表数据 foreach ($list as $k => &$v) { $v['username'] = get_nickname($v['uid']); //$v['create_time'] = time_format($v['create_time']); } $this->assign('list', $list); $this->meta_title = '回收站'; $this->display(); }
/** * 删除状态为-1的数据(包含扩展模型) * @return true 删除成功, false 删除失败 * @author huajie <*****@*****.**> */ public function remove() { //查询假删除的基础数据 if (is_administrator()) { $map = array('status' => -1); } else { $cate_ids = AuthGroupModel::getAuthCategories(UID); $map = array('status' => -1, 'category_id' => array('IN', trim(implode(',', $cate_ids), ','))); } $base_list = $this->where($map)->field('id,model_id')->select(); //删除扩展模型数据 $base_ids = array_column($base_list, 'id'); //孤儿数据 $orphan = get_stemma($base_ids, $this, 'id,model_id'); $all_list = array_merge($base_list, $orphan); foreach ($all_list as $key => $value) { $logic = $this->logic($value['model_id']); $logic->delete($value['id']); } //删除基础数据 $ids = array_merge($base_ids, (array) array_column($orphan, 'id')); if (!empty($ids)) { $res = $this->where(array('id' => array('IN', trim(implode(',', $ids), ','))))->delete(); } return $res; }
protected function checkDynamic() { $cates = AuthGroupModel::getAuthCategories(UID); switch (strtolower(ACTION_NAME)) { case 'index': //文档列表 //文档列表 case 'add': // 新增 $cate_id = I('cate_id'); break; case 'edit': //编辑 //编辑 case 'update': //更新 $doc_id = I('id'); $cate_id = M('Document')->where(array('id' => $doc_id))->getField('category_id'); break; case 'setstatus': //更改状态 //更改状态 case 'permit': //回收站 $doc_id = (array) I('ids'); $cate_id = M('Document')->where(array('id' => array('in', $doc_id)))->getField('category_id', true); $cate_id = array_unique($cate_id); break; } if (!$cate_id) { return null; //不明 } elseif (!is_array($cate_id) && in_array($cate_id, $cates)) { return true; //有权限 } elseif (is_array($cate_id) && $cate_id == array_intersect($cate_id, $cates)) { return true; //有权限 } else { return false; //无权限 } }