Special.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 $noNeedRight = ['check_element_available'];
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $cms = get_addon_config('cms');
  21. if ($cms['specialdatalimit'] != 'all') {
  22. $this->dataLimit = $cms['specialdatalimit'];
  23. }
  24. $this->model = new \app\admin\model\cms\Special;
  25. $this->view->assign("flagList", $this->model->getFlagList());
  26. $this->view->assign("statusList", $this->model->getStatusList());
  27. }
  28. public function add()
  29. {
  30. $values = [];
  31. $fields = \addons\cms\library\Service::getCustomFields('special', 0, $values);
  32. $this->view->assign('fields', $fields);
  33. $this->view->assign('values', $values);
  34. return parent::add();
  35. }
  36. public function edit($ids = null)
  37. {
  38. $values = \app\admin\model\cms\Special::get($ids);
  39. if (!$values) {
  40. $this->error(__('No Results were found'));
  41. }
  42. $values = $values->toArray();
  43. $fields = \addons\cms\library\Service::getCustomFields('special', 0, $values);
  44. $this->view->assign('fields', $fields);
  45. $this->view->assign('values', $values);
  46. return parent::edit($ids);
  47. }
  48. /**
  49. * 检测元素是否可用
  50. * @internal
  51. */
  52. public function check_element_available()
  53. {
  54. $id = $this->request->request('id');
  55. $name = $this->request->request('name');
  56. $value = $this->request->request('value');
  57. $name = substr($name, 4, -1);
  58. if (!$name) {
  59. $this->error(__('Parameter %s can not be empty', 'name'));
  60. }
  61. if ($id) {
  62. $this->model->where('id', '<>', $id);
  63. }
  64. $exist = $this->model->where($name, $value)->find();
  65. if ($exist) {
  66. $this->error(__('The data already exist'));
  67. } else {
  68. $this->success();
  69. }
  70. }
  71. }