1 | <?php |
||
2 | |||
3 | namespace app\controllers\admin; |
||
4 | |||
5 | use yii\web\NotFoundHttpException; |
||
6 | use app\models\{Contact, ContactSearch}; |
||
7 | use app\traits\{AdminBeforeActionTrait, AccessTrait}; |
||
8 | use Itstructure\AdminModule\controllers\CommonAdminController; |
||
9 | |||
10 | /** |
||
11 | * Class ContactController |
||
12 | * ContactController implements the CRUD actions for Contact model. |
||
13 | * |
||
14 | * @package app\controllers\admin |
||
15 | */ |
||
16 | class ContactController extends CommonAdminController |
||
17 | { |
||
18 | use AdminBeforeActionTrait, AccessTrait; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
19 | |||
20 | /** |
||
21 | * @var bool |
||
22 | */ |
||
23 | protected $setEditingScenarios = true; |
||
24 | |||
25 | /** |
||
26 | * Set contacts record as default. |
||
27 | * |
||
28 | * @param $contactId |
||
29 | * |
||
30 | * @return \yii\web\Response |
||
31 | * |
||
32 | * @throws NotFoundHttpException |
||
33 | */ |
||
34 | public function actionSetDefault($contactId) |
||
35 | { |
||
36 | if (!$this->checkAccessToUpdate()) { |
||
37 | return $this->accessError(); |
||
0 ignored issues
–
show
|
|||
38 | } |
||
39 | |||
40 | $contact = Contact::findOne($contactId); |
||
41 | |||
42 | if (null === $contact) { |
||
43 | throw new NotFoundHttpException('Record with id ' . $contactId . ' does not exist'); |
||
44 | } |
||
45 | |||
46 | $contact->default = 1; |
||
47 | $contact->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 Contact model name. |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | protected function getModelName():string |
||
124 | { |
||
125 | return Contact::class; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Returns ContactSearch model name. |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | protected function getSearchModelName():string |
||
134 | { |
||
135 | return ContactSearch::class; |
||
136 | } |
||
137 | } |
||
138 |