1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\controllers\admin; |
4
|
|
|
|
5
|
|
|
use app\models\{Page, PageSearch}; |
6
|
|
|
use app\traits\{AdminBeforeActionTrait, AccessTrait, AdditionFieldsTrait}; |
7
|
|
|
use Itstructure\MFUploader\interfaces\UploadModelInterface; |
8
|
|
|
use Itstructure\AdminModule\controllers\CommonAdminController; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class PageController |
12
|
|
|
* PageController implements the CRUD actions for Page model. |
13
|
|
|
* |
14
|
|
|
* @package app\controllers\admin |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
class PageController extends CommonAdminController |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
use AdminBeforeActionTrait, AccessTrait, AdditionFieldsTrait; |
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(Page::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(Page::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 Page model name. |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
protected function getModelName():string |
106
|
|
|
{ |
107
|
|
|
return Page::class; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns PageSearch model name. |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
protected function getSearchModelName():string |
116
|
|
|
{ |
117
|
|
|
return PageSearch::class; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.