1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\controllers\admin; |
4
|
|
|
|
5
|
|
|
use yii\data\Pagination; |
6
|
|
|
use app\models\{Page, Product, ProductSearch}; |
7
|
|
|
use app\traits\{LanguageTrait, AdminBeforeActionTrait, AccessTrait}; |
8
|
|
|
use Itstructure\MFUploader\models\OwnerMediafile; |
9
|
|
|
use Itstructure\MFUploader\models\album\Album; |
10
|
|
|
use Itstructure\MFUploader\interfaces\UploadModelInterface; |
11
|
|
|
use Itstructure\AdminModule\controllers\CommonAdminController; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ProductController |
15
|
|
|
* ProductController implements the CRUD actions for Page model. |
16
|
|
|
* |
17
|
|
|
* @package app\controllers\admin |
18
|
|
|
*/ |
19
|
|
|
class ProductController extends CommonAdminController |
20
|
|
|
{ |
21
|
|
|
use LanguageTrait, AdminBeforeActionTrait, AccessTrait; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var bool |
25
|
|
|
*/ |
26
|
|
|
protected $isMultilanguage = true; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return mixed|string |
30
|
|
|
*/ |
31
|
|
|
public function actionIndex() |
32
|
|
|
{ |
33
|
|
|
if (!$this->checkAccessToIndex()) { |
34
|
|
|
return $this->accessError(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return parent::actionIndex(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param int|string $id |
42
|
|
|
* |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function actionView($id) |
46
|
|
|
{ |
47
|
|
|
if (!$this->checkAccessToView()) { |
48
|
|
|
return $this->accessError(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return parent::actionView($id); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return mixed|string|\yii\web\Response |
56
|
|
|
*/ |
57
|
|
|
public function actionCreate() |
58
|
|
|
{ |
59
|
|
|
if (!$this->checkAccessToCreate()) { |
60
|
|
|
return $this->accessError(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return parent::actionCreate(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param int|string $id |
68
|
|
|
* |
69
|
|
|
* @return string|\yii\web\Response |
70
|
|
|
*/ |
71
|
|
|
public function actionUpdate($id) |
72
|
|
|
{ |
73
|
|
|
if (!$this->checkAccessToUpdate()) { |
74
|
|
|
return $this->accessError(); |
75
|
|
|
} |
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
|
|
|
* Get addition fields for the view template. |
96
|
|
|
* |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
protected function getAdditionFields(): array |
100
|
|
|
{ |
101
|
|
|
if ($this->action->id == 'create' || $this->action->id == 'update') { |
102
|
|
|
$fields = []; |
103
|
|
|
|
104
|
|
|
$fields['pages'] = Page::getMenu(); |
105
|
|
|
$fields['albums'] = Album::find()->select([ |
106
|
|
|
'id', 'title' |
107
|
|
|
])->all(); |
108
|
|
|
|
109
|
|
|
if ($this->action->id == 'update') { |
110
|
|
|
$mediafilesQuery = OwnerMediafile::getMediaFilesQuery([ |
111
|
|
|
'owner' => Product::tableName(), |
112
|
|
|
'ownerId' => $this->model->getId(), |
113
|
|
|
'ownerAttribute' => UploadModelInterface::FILE_TYPE_IMAGE, |
114
|
|
|
]); |
115
|
|
|
$media_pages = new Pagination([ |
116
|
|
|
'defaultPageSize' => 6, |
117
|
|
|
'totalCount' => $mediafilesQuery->count() |
118
|
|
|
]); |
119
|
|
|
$fields['images'] = $mediafilesQuery->offset($media_pages->offset) |
120
|
|
|
->limit($media_pages->limit) |
121
|
|
|
->all(); |
122
|
|
|
$fields['media_pages'] = $media_pages; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $fields; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $this->additionFields; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns Product model name. |
133
|
|
|
* |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
protected function getModelName():string |
137
|
|
|
{ |
138
|
|
|
return Product::class; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Returns ProductSearch model name. |
143
|
|
|
* |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
protected function getSearchModelName():string |
147
|
|
|
{ |
148
|
|
|
return ProductSearch::class; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|