Block.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\common\controller\Backend;
  4. /**
  5. * 区块表
  6. *
  7. * @icon fa fa-th-large
  8. */
  9. class Block extends Backend
  10. {
  11. /**
  12. * Block模型对象
  13. */
  14. protected $model = null;
  15. protected $searchFields = 'id,name,type,title,url';
  16. protected $noNeedRight = ['selectpage_type'];
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\cms\Block;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. $this->view->assign("nameList", $this->model->getNameList());
  23. }
  24. public function index()
  25. {
  26. $typeArr = \app\admin\model\cms\Block::distinct('type')->column('type');
  27. $this->view->assign('typeList', $typeArr);
  28. $this->assignconfig('typeList', $typeArr);
  29. return parent::index();
  30. }
  31. public function selectpage_type()
  32. {
  33. $list = [];
  34. $word = (array)$this->request->request("q_word/a");
  35. $field = $this->request->request('showField');
  36. $keyValue = $this->request->request('keyValue');
  37. if (!$keyValue) {
  38. if (array_filter($word)) {
  39. foreach ($word as $k => $v) {
  40. $list[] = ['id' => $v, $field => $v];
  41. }
  42. }
  43. $typeArr = \app\admin\model\cms\Block::column('type');
  44. $typeArr = array_unique($typeArr);
  45. foreach ($typeArr as $index => $item) {
  46. $list[] = ['id' => $item, $field => $item];
  47. }
  48. } else {
  49. $list[] = ['id' => $keyValue, $field => $keyValue];
  50. }
  51. return json(['total' => count($list), 'list' => $list]);
  52. }
  53. /**
  54. * 添加
  55. */
  56. public function add()
  57. {
  58. if ($this->request->isPost()) {
  59. $row = $this->request->post("row/a", []);
  60. if (isset($row['parsetpl']) && $row['parsetpl']) {
  61. $this->token();
  62. }
  63. }
  64. $values = [];
  65. $fields = \addons\cms\library\Service::getCustomFields('block', 0, $values);
  66. $this->view->assign('fields', $fields);
  67. $this->view->assign('values', $values);
  68. return parent::add();
  69. }
  70. public function edit($ids = null)
  71. {
  72. if ($this->request->isPost()) {
  73. $row = $this->request->post("row/a", []);
  74. if (isset($row['parsetpl']) && $row['parsetpl']) {
  75. $this->token();
  76. }
  77. }
  78. $values = \app\admin\model\cms\Block::get($ids);
  79. if (!$values) {
  80. $this->error(__('No Results were found'));
  81. }
  82. $values = $values->toArray();
  83. $fields = \addons\cms\library\Service::getCustomFields('block', 0, $values);
  84. $this->view->assign('fields', $fields);
  85. $this->view->assign('values', $values);
  86. return parent::edit($ids);
  87. }
  88. public function import()
  89. {
  90. return parent::import();
  91. }
  92. }