Special.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\common\controller\Backend;
  4. /**
  5. * 专题管理
  6. *
  7. * @icon fa fa-newspaper-o
  8. */
  9. class Special extends Backend
  10. {
  11. /**
  12. * Special模型对象
  13. * @var \app\admin\model\cms\Special
  14. */
  15. protected $model = null;
  16. protected $searchFields = 'id,title,seotitle,label';
  17. protected $noNeedRight = ['check_element_available'];
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $config = get_addon_config('cms');
  22. if ($config['specialdatalimit'] != 'all') {
  23. $this->dataLimit = $config['specialdatalimit'];
  24. }
  25. $config = get_addon_config('cms');
  26. $this->assignconfig('spiderRecord', intval($config['spiderrecord']?? 0));
  27. $this->model = new \app\admin\model\cms\Special;
  28. $this->view->assign("flagList", $this->model->getFlagList());
  29. $this->view->assign("statusList", $this->model->getStatusList());
  30. }
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if ($this->request->isAjax()) {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('keyField')) {
  41. return $this->selectpage();
  42. }
  43. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  44. $list = $this->model
  45. ->where($where)
  46. ->order($sort, $order)
  47. ->paginate($limit);
  48. \app\admin\model\cms\SpiderLog::render($list, 'special');
  49. $result = array("total" => $list->total(), "rows" => $list->items());
  50. return json($result);
  51. }
  52. return $this->view->fetch();
  53. }
  54. /**
  55. * 添加
  56. */
  57. public function add()
  58. {
  59. $values = [];
  60. $fields = \addons\cms\library\Service::getCustomFields('special', 0, $values);
  61. $this->view->assign('fields', $fields);
  62. $this->view->assign('values', $values);
  63. return parent::add();
  64. }
  65. /**
  66. * 编辑
  67. */
  68. public function edit($ids = null)
  69. {
  70. $values = \app\admin\model\cms\Special::get($ids);
  71. if (!$values) {
  72. $this->error(__('No Results were found'));
  73. }
  74. $values = $values->toArray();
  75. $fields = \addons\cms\library\Service::getCustomFields('special', 0, $values);
  76. $this->view->assign('fields', $fields);
  77. $this->view->assign('values', $values);
  78. return parent::edit($ids);
  79. }
  80. /**
  81. * 检测元素是否可用
  82. * @internal
  83. */
  84. public function check_element_available()
  85. {
  86. $id = $this->request->request('id');
  87. $name = $this->request->request('name');
  88. $value = $this->request->request('value');
  89. $name = substr($name, 4, -1);
  90. if (!$name) {
  91. $this->error(__('Parameter %s can not be empty', 'name'));
  92. }
  93. if ($id) {
  94. $this->model->where('id', '<>', $id);
  95. }
  96. $exist = $this->model->where($name, $value)->find();
  97. if ($exist) {
  98. $this->error(__('The data already exist'));
  99. } else {
  100. $this->success();
  101. }
  102. }
  103. }