1 | <?php |
||
2 | |||
3 | namespace app\controllers\admin; |
||
4 | |||
5 | use app\models\{Page, Article, ArticleSearch}; |
||
6 | use app\traits\{AdminBeforeActionTrait, AccessTrait, AdditionFieldsTrait}; |
||
7 | use Itstructure\MFUploader\interfaces\UploadModelInterface; |
||
8 | use Itstructure\AdminModule\controllers\CommonAdminController; |
||
9 | |||
10 | /** |
||
11 | * Class ArticleController |
||
12 | * ArticleController implements the CRUD actions for Article model. |
||
13 | * |
||
14 | * @package app\controllers\admin |
||
15 | */ |
||
16 | class ArticleController extends CommonAdminController |
||
17 | { |
||
18 | use AdminBeforeActionTrait, AccessTrait, AdditionFieldsTrait; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
19 | |||
20 | /** |
||
21 | * @var bool |
||
22 | */ |
||
23 | protected $setEditingScenarios = true; |
||
24 | |||
25 | /** |
||
26 | * @return mixed|string |
||
27 | */ |
||
28 | public function actionIndex() |
||
29 | { |
||
30 | if (!$this->checkAccessToIndex()) { |
||
31 | return $this->accessError(); |
||
32 | } |
||
33 | |||
34 | return parent::actionIndex(); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param int|string $id |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | public function actionView($id) |
||
43 | { |
||
44 | if (!$this->checkAccessToView()) { |
||
45 | return $this->accessError(); |
||
46 | } |
||
47 | |||
48 | $this->additionFields['images'] = $this->getMediaFiles(Article::tableName(), (int)$id, UploadModelInterface::FILE_TYPE_IMAGE); |
||
49 | |||
50 | return parent::actionView($id); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @return mixed|string|\yii\web\Response |
||
55 | */ |
||
56 | public function actionCreate() |
||
57 | { |
||
58 | if (!$this->checkAccessToCreate()) { |
||
59 | return $this->accessError(); |
||
60 | } |
||
61 | |||
62 | $this->additionFields['pages'] = Page::getMenu(); |
||
63 | $this->additionFields['albums'] = $this->getAlbums(); |
||
64 | |||
65 | return parent::actionCreate(); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param int|string $id |
||
70 | * |
||
71 | * @return string|\yii\web\Response |
||
72 | */ |
||
73 | public function actionUpdate($id) |
||
74 | { |
||
75 | if (!$this->checkAccessToUpdate()) { |
||
76 | return $this->accessError(); |
||
77 | } |
||
78 | |||
79 | $this->additionFields['pages'] = Page::getMenu(); |
||
80 | $this->additionFields['albums'] = $this->getAlbums(); |
||
81 | $this->additionFields['images'] = $this->getMediaFiles(Article::tableName(), (int)$id, UploadModelInterface::FILE_TYPE_IMAGE); |
||
82 | |||
83 | return parent::actionUpdate($id); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param int|string $id |
||
88 | * |
||
89 | * @return mixed|\yii\web\Response |
||
90 | */ |
||
91 | public function actionDelete($id) |
||
92 | { |
||
93 | if (!$this->checkAccessToDelete()) { |
||
94 | return $this->accessError(); |
||
95 | } |
||
96 | |||
97 | return parent::actionDelete($id); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Returns Product model name. |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | protected function getModelName():string |
||
106 | { |
||
107 | return Article::class; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Returns ProductSearch model name. |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | protected function getSearchModelName():string |
||
116 | { |
||
117 | return ArticleSearch::class; |
||
118 | } |
||
119 | } |
||
120 |