1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\controllers\admin; |
4
|
|
|
|
5
|
|
|
use yii\web\NotFoundHttpException; |
6
|
|
|
use app\models\{Home, HomeSearch}; |
7
|
|
|
use app\traits\{AdminBeforeActionTrait, AccessTrait}; |
8
|
|
|
use Itstructure\AdminModule\controllers\CommonAdminController; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class HomeController |
12
|
|
|
* HomeController implements the CRUD actions for Home model. |
13
|
|
|
* |
14
|
|
|
* @package app\controllers\admin |
15
|
|
|
*/ |
16
|
|
|
class HomeController extends CommonAdminController |
17
|
|
|
{ |
18
|
|
|
use AdminBeforeActionTrait, AccessTrait; |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
protected $setEditingScenarios = true; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Set home record as default. |
27
|
|
|
* |
28
|
|
|
* @param $homeId |
29
|
|
|
* |
30
|
|
|
* @return \yii\web\Response |
31
|
|
|
* |
32
|
|
|
* @throws NotFoundHttpException |
33
|
|
|
*/ |
34
|
|
|
public function actionSetDefault($homeId) |
35
|
|
|
{ |
36
|
|
|
if (!$this->checkAccessToUpdate()) { |
37
|
|
|
return $this->accessError(); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$home = Home::findOne($homeId); |
41
|
|
|
|
42
|
|
|
if (null === $home) { |
43
|
|
|
throw new NotFoundHttpException('Record with id ' . $homeId . ' does not exist'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$home->default = 1; |
47
|
|
|
$home->save(); |
48
|
|
|
|
49
|
|
|
return $this->redirect('index'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return mixed|string |
54
|
|
|
*/ |
55
|
|
|
public function actionIndex() |
56
|
|
|
{ |
57
|
|
|
if (!$this->checkAccessToIndex()) { |
58
|
|
|
return $this->accessError(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return parent::actionIndex(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param int|string $id |
66
|
|
|
* |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
|
|
public function actionView($id) |
70
|
|
|
{ |
71
|
|
|
if (!$this->checkAccessToView()) { |
72
|
|
|
return $this->accessError(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return parent::actionView($id); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return mixed|string|\yii\web\Response |
80
|
|
|
*/ |
81
|
|
|
public function actionCreate() |
82
|
|
|
{ |
83
|
|
|
if (!$this->checkAccessToCreate()) { |
84
|
|
|
return $this->accessError(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return parent::actionCreate(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param int|string $id |
92
|
|
|
* |
93
|
|
|
* @return string|\yii\web\Response |
94
|
|
|
*/ |
95
|
|
|
public function actionUpdate($id) |
96
|
|
|
{ |
97
|
|
|
if (!$this->checkAccessToUpdate()) { |
98
|
|
|
return $this->accessError(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return parent::actionUpdate($id); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param int|string $id |
106
|
|
|
* |
107
|
|
|
* @return mixed|\yii\web\Response |
108
|
|
|
*/ |
109
|
|
|
public function actionDelete($id) |
110
|
|
|
{ |
111
|
|
|
if (!$this->checkAccessToDelete()) { |
112
|
|
|
return $this->accessError(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return parent::actionDelete($id); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns Home model name. |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
protected function getModelName():string |
124
|
|
|
{ |
125
|
|
|
return Home::class; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Returns HomeSearch model name. |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
protected function getSearchModelName():string |
134
|
|
|
{ |
135
|
|
|
return HomeSearch::class; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|