123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\admin\controller\content\article;
- use app\common\controller\Backend;
- use app\common\Enum\StatusEnum;
- use fast\Tree;
- use app\admin\model\content\article\Category;
- use think\Db;
- /**
- * 文章管理管理
- *
- * @icon fa fa-circle-o
- */
- class Index extends Backend
- {
- protected $CategoryList = [];
- /**
- * @var Tree
- */
- protected $tree = null;
-
- /**
- * 允许的文章分类IDs
- */
- protected $channelIds = [];
- /**
- * Index模型对象
- * @var \app\admin\model\content\article\Index
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\content\article\Index;
- // 移除权限检查
- // $this->isSuperAdmin = $this->auth->isSuperAdmin();
- $channelList = [];
- $all = collection(Category::order("sort desc,id desc")->select())->toArray();
-
- //允许的栏目 - 不区分权限,所有用户都可以选择所有栏目
- $this->channelIds = Category::column('id');
- $parentChannelIds = Category::column('parent_id');
- $parentChannelIds = array_unique($parentChannelIds);
- $tree = Tree::instance()->init($all, 'parent_id');
- foreach ($all as $k => &$v) {
- $state = ['opened' => true];
- // 移除外部链接类型检查,因为表结构中没有type字段
- // 不再检查权限,所有用户都可以看到所有分类
- $channelList[] = [
- 'id' => $v['id'],
- 'parent' => $v['parent_id'] ?: '0',
- 'text' => htmlentities(__($v['title'])),
- 'expand' => true,
- 'state' => $state
- ];
- $v['title'] = htmlentities($v['title']);
- }
- unset($v);
- $tree = Tree::instance()->init($all, 'parent_id');
- $categoryOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected>@spacer@title</option>", '');
- $this->view->assign('categoryOptions', $categoryOptions);
- $this->view->assign("statusList",StatusEnum::getMap());
- $this->assignconfig('statusSearchList',json_encode(StatusEnum::getMap()));
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 编辑
- *
- * @param mixed $ids
- */
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
-
- // 获取当前文章分类ID(确保字段名称正确)
- $categoryId = isset($row['category_id']) ? $row['category_id'] : 0;
-
- // 获取所有分类,不限制权限
- $all = collection(Category::order("sort DESC,id DESC")->select())->toArray();
- foreach ($all as $k => &$v) {
- $v['title'] = htmlentities($v['title']);
- }
-
- // 初始化树结构并生成分类选项
- $tree = Tree::instance()->init($all, 'parent_id');
- $categoryOptions = $tree->getTree(0, "<option value=@id @selected>@spacer@title</option>", $categoryId);
-
- $this->view->assign('categoryOptions', $categoryOptions);
- $this->view->assign("row", $row);
-
- return parent::edit($ids);
- }
- }
|