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