Commit 771f8d54e7924d794cf1c50d3ab72b0289577bf0
1 parent
19fa91c7
big commti
Showing
22 changed files
with
11 additions
and
1243 deletions
Show diff stats
common/config/main.php
... | ... | @@ -166,199 +166,5 @@ return [ |
166 | 166 | 'artbox-comment' => [ |
167 | 167 | 'class' => 'common\modules\comment\Module', |
168 | 168 | ], |
169 | - 'relation' => [ | |
170 | - 'class' => 'common\modules\relation\Module', | |
171 | - 'relations' => [ | |
172 | - 'product_categories' => [ | |
173 | - 'name' => Yii::t('product', 'Categories'), | |
174 | - 'field' => 'categories', | |
175 | - 'entity1' => [ | |
176 | - 'model' => '\common\modules\product\models\Product', | |
177 | - 'label' => 'Product', | |
178 | - 'listField' => 'name', | |
179 | - 'searchField' => 'name', | |
180 | - 'key' => 'product_id', | |
181 | - 'linked_key' => 'product_id', | |
182 | - ], | |
183 | - 'entity2' => [ | |
184 | - 'model' => '\common\modules\product\models\Category', | |
185 | - 'label' => 'Category', | |
186 | - 'listField' => 'categoryName.value', | |
187 | - 'searchField' => 'category_name.value', | |
188 | - 'searchJoin' => 'categoryName', | |
189 | - 'key' => 'category_id', | |
190 | - 'linked_key' => 'category_id', | |
191 | - 'hierarchy' => [ | |
192 | - 'key' => 'category_id', | |
193 | - 'parentKey' => 'parent_id', | |
194 | - ] | |
195 | - ], | |
196 | - 'via' => [ | |
197 | - 'model' => '\common\modules\product\models\ProductCategory', | |
198 | - ] | |
199 | - ], | |
200 | - 'product_option' => [ | |
201 | - 'name' => Yii::t('product', 'Properties'), | |
202 | - 'field' => 'options', | |
203 | - 'entity1' => [ | |
204 | - 'model' => '\common\modules\product\models\Product', | |
205 | - 'label' => 'Product', | |
206 | - 'listField' => 'fullname', | |
207 | - 'key' => 'product_id', | |
208 | - 'linked_key' => 'product_id', | |
209 | - ], | |
210 | - 'entity2' => [ | |
211 | - 'model' => '\common\modules\rubrication\models\TaxOption', | |
212 | - 'label' => 'Option', | |
213 | - 'listField' => 'ValueRenderFlash', | |
214 | - 'key' => 'tax_option_id', | |
215 | - 'linked_key' => 'option_id', | |
216 | - ], | |
217 | - 'via' => [ | |
218 | - 'model' => 'common\modules\product\models\ProductOption', | |
219 | - ] | |
220 | - ], | |
221 | - 'product_variant_option' => [ | |
222 | - 'name' => Yii::t('product', 'Properties'), | |
223 | - 'field' => 'options', | |
224 | - 'entity1' => [ | |
225 | - 'model' => '\common\modules\product\models\ProductVariant', | |
226 | - 'label' => 'Variant', | |
227 | - 'listField' => 'fullname', | |
228 | - 'key' => 'product_variant_id', | |
229 | - 'linked_key' => 'product_variant_id', | |
230 | - ], | |
231 | - 'entity2' => [ | |
232 | - 'model' => '\common\modules\rubrication\models\TaxOption', | |
233 | - 'label' => 'Option', | |
234 | - 'listField' => 'ValueRenderFlash', | |
235 | - 'key' => 'tax_option_id', | |
236 | - 'linked_key' => 'option_id', | |
237 | - ], | |
238 | - 'via' => [ | |
239 | - 'model' => 'common\modules\product\models\ProductVariantOption', | |
240 | - ] | |
241 | - ], | |
242 | - 'tax_group_to_category' => [ | |
243 | - 'name' => Yii::t('product', 'ะฅะฐัะฐะบัะตัะธััะธะบะธ ะฟะพ ะบะฐัะตะณะพัะธัะผ'), | |
244 | - 'field' => 'group_to_category', | |
245 | - 'entity1' => [ | |
246 | - 'model' => '\common\modules\rubrication\models\TaxGroup', | |
247 | - 'label' => 'Group', | |
248 | - 'listField' => 'name', | |
249 | - 'key' => 'tax_group_id', | |
250 | - 'linked_key' => 'entity1_id', | |
251 | - ], | |
252 | - 'entity2' => [ | |
253 | - 'model' => '\common\modules\product\models\Category', | |
254 | - 'label' => 'Category', | |
255 | - 'listField' => 'name', | |
256 | - 'key' => 'category_id', | |
257 | - 'linked_key' => 'entity2_id', | |
258 | - 'hierarchy' => [ | |
259 | - 'key' => 'category_id', | |
260 | - 'parentKey' => 'parent_id', | |
261 | - ] | |
262 | - ], | |
263 | - 'via' => [ | |
264 | - 'model' => '\common\modules\relation\models\Relation', | |
265 | - 'alias' => 'alias', | |
266 | - ] | |
267 | - ], | |
268 | - /* | |
269 | - 'relation_categories' => [ | |
270 | - 'name' => Yii::t('relation', 'Relation categories'), | |
271 | - 'field' => 'categories', | |
272 | - 'entity1' => [ | |
273 | - 'model' => '\common\modules\product\models\Product', | |
274 | - 'label' => 'Product', | |
275 | - 'listField' => 'fullname', | |
276 | - 'key' => 'product_id', | |
277 | - 'linked_key' => 'product_id', | |
278 | - ], | |
279 | - 'entity2' => [ | |
280 | - 'model' => '\common\modules\rubrication\models\TaxOption', | |
281 | - 'label' => 'Category', | |
282 | - 'listField' => 'ValueRenderFlash', | |
283 | - 'key' => 'tax_option_id', | |
284 | - 'linked_key' => 'category_id', | |
285 | - 'where' => [ | |
286 | - 'tax_group_id' => 1 | |
287 | - ] | |
288 | - ], | |
289 | - 'via' => [ | |
290 | - 'model' => '\common\modules\relation\models\Relation', | |
291 | - 'alias' => 'alias', | |
292 | - ] | |
293 | - ], | |
294 | - 'tax_option_to_group' => [ | |
295 | - 'name' => 'Options-Groups', | |
296 | - 'field' => 'tax_option_to_group', | |
297 | - 'linked_table' => 'tax_option_to_group', | |
298 | - 'entity1' => [ | |
299 | - 'label' => 'Option', | |
300 | - 'listField' => 'ValueRenderFlash', | |
301 | - 'model' => '\common\modules\rubrication\models\TaxOption', | |
302 | - 'key' => 'tax_option_id', | |
303 | - 'linked_key' => 'tax_option_id', | |
304 | - ], | |
305 | - 'entity2' => [ | |
306 | - 'label' => 'Group', | |
307 | - 'listField' => 'name', | |
308 | - 'model' => '\common\modules\rubrication\models\TaxGroup', | |
309 | - 'key' => 'tax_group_id', | |
310 | - 'linked_key' => 'tax_group_id', | |
311 | - ], | |
312 | - 'via' => [ | |
313 | - 'model' => 'common\modules\rubrication\models\TaxOptionToGroup', | |
314 | - 'alias' => 'alias', | |
315 | - ] | |
316 | - ], | |
317 | - 'tax_option_to_option' => [ | |
318 | - 'name' => 'Options-Options', | |
319 | - 'field' => 'tax_option_to_option', | |
320 | - 'entity1' => [ | |
321 | - 'label' => 'Option', | |
322 | - 'listField' => 'ValueRenderFlash', | |
323 | - 'model' => '\common\modules\rubrication\models\TaxOption', | |
324 | - 'key' => 'tax_option_id', | |
325 | - 'linked_key' => 'tax_option1_id', | |
326 | - ], | |
327 | - 'entity2' => [ | |
328 | - 'label' => 'Option', | |
329 | - 'listField' => 'ValueRenderFlash', | |
330 | - 'model' => '\common\modules\rubrication\models\TaxOption', | |
331 | - 'key' => 'tax_option_id', | |
332 | - 'linked_key' => 'tax_option2_id', | |
333 | - ], | |
334 | - 'via' => [ | |
335 | - 'model' => 'common\modules\rubrication\models\TaxOptionRelation', | |
336 | - 'alias' => 'alias', | |
337 | - ] | |
338 | - ], | |
339 | - 'brand_cats' => [ | |
340 | - 'name' => 'ะะฐัะตะณะพัะธะธ ะฟัะพะธะทะฒะพะดะธัะตะปะตะน', | |
341 | - 'field' => 'tax_option_to_option', | |
342 | - 'entity1' => [ | |
343 | - 'label' => 'ะัะตะฝะด', | |
344 | - 'listField' => 'ValueRenderFlash', | |
345 | - 'model' => '\common\modules\rubrication\models\TaxOption', | |
346 | - 'key' => 'tax_option_id', | |
347 | - 'linked_key' => 'tax_option1_id', | |
348 | - ], | |
349 | - 'entity2' => [ | |
350 | - 'label' => 'ะะฐัะตะณะพัะธั', | |
351 | - 'listField' => 'ValueRenderFlash', | |
352 | - 'model' => '\common\modules\rubrication\models\TaxOption', | |
353 | - 'key' => 'tax_option_id', | |
354 | - 'linked_key' => 'tax_option2_id', | |
355 | - ], | |
356 | - 'via' => [ | |
357 | - 'model' => 'common\modules\rubrication\models\TaxOptionRelation', | |
358 | - 'alias' => 'alias', | |
359 | - ] | |
360 | - ]*/ | |
361 | - ] | |
362 | - ], | |
363 | 169 | ], |
364 | 170 | ]; | ... | ... |
common/modules/product/models/Category.php
... | ... | @@ -5,7 +5,6 @@ namespace common\modules\product\models; |
5 | 5 | use common\behaviors\RuSlug; |
6 | 6 | use common\components\artboxtree\ArtboxTreeBehavior; |
7 | 7 | use common\components\artboxtree\ArtboxTreeHelper; |
8 | -use common\modules\relation\relationBehavior; | |
9 | 8 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; |
10 | 9 | use common\modules\rubrication\models\TaxGroup; |
11 | 10 | use Yii; |
... | ... | @@ -62,13 +61,7 @@ class Category extends \yii\db\ActiveRecord |
62 | 61 | 'translit' => true |
63 | 62 | ] |
64 | 63 | ], |
65 | - [ | |
66 | - 'class' => relationBehavior::className(), | |
67 | - 'relations' => [ | |
68 | - 'product_categories' => 'entity2', // Products of category | |
69 | - 'tax_group_to_category' => 'entity2', | |
70 | - ] | |
71 | - ], | |
64 | + | |
72 | 65 | ]; |
73 | 66 | } |
74 | 67 | ... | ... |
common/modules/product/models/Product.php
... | ... | @@ -10,7 +10,6 @@ use common\modules\product\behaviors\FilterBehavior; |
10 | 10 | use common\modules\rubrication\models\TaxGroup; |
11 | 11 | use common\modules\rubrication\models\TaxOption; |
12 | 12 | use Yii; |
13 | -use common\modules\relation\relationBehavior; | |
14 | 13 | use yii\db\ActiveQuery; |
15 | 14 | use yii\db\ActiveRecord; |
16 | 15 | use yii\helpers\ArrayHelper; |
... | ... | @@ -50,13 +49,6 @@ class Product extends \yii\db\ActiveRecord |
50 | 49 | { |
51 | 50 | return [ |
52 | 51 | [ |
53 | - 'class' => relationBehavior::className(), | |
54 | - 'relations' => [ | |
55 | - 'product_categories' => 'entity1', // Product category | |
56 | - 'product_option' => 'entity1' // Product category | |
57 | - ] | |
58 | - ], | |
59 | - [ | |
60 | 52 | 'class' =>FilterBehavior::className(), |
61 | 53 | ], |
62 | 54 | [ | ... | ... |
common/modules/product/models/ProductCategory.php
... | ... | @@ -2,7 +2,6 @@ |
2 | 2 | |
3 | 3 | namespace common\modules\product\models; |
4 | 4 | |
5 | -use common\modules\relation\models\Relation; | |
6 | 5 | use common\modules\rubrication\models\TaxOption; |
7 | 6 | use Yii; |
8 | 7 | |
... | ... | @@ -14,7 +13,7 @@ use Yii; |
14 | 13 | * |
15 | 14 | * @property TaxOption $devCategory |
16 | 15 | */ |
17 | -class ProductCategory extends Relation | |
16 | +class ProductCategory extends \yii\db\ActiveRecord | |
18 | 17 | { |
19 | 18 | public $alias = 'product_categories'; |
20 | 19 | ... | ... |
common/modules/product/models/ProductVariant.php
... | ... | @@ -2,8 +2,7 @@ |
2 | 2 | |
3 | 3 | namespace common\modules\product\models; |
4 | 4 | |
5 | -use common\modules\product\behaviors\FilterBehavior; | |
6 | -use common\modules\relation\relationBehavior; | |
5 | + | |
7 | 6 | use common\modules\rubrication\models\TaxGroup; |
8 | 7 | use common\modules\rubrication\models\TaxOption; |
9 | 8 | use Yii; |
... | ... | @@ -42,22 +41,7 @@ class ProductVariant extends \yii\db\ActiveRecord |
42 | 41 | |
43 | 42 | |
44 | 43 | /** @var array $_images */ |
45 | - public $imagesUpload = []; | |
46 | - | |
47 | - /** | |
48 | - * @inheritdoc | |
49 | - */ | |
50 | - public function behaviors() | |
51 | - { | |
52 | - return [ | |
53 | - [ | |
54 | - 'class' => relationBehavior::className(), | |
55 | - 'relations' => [ | |
56 | - 'product_variant_option' => 'entity1' // Product variant options | |
57 | - ] | |
58 | - ], | |
59 | - ]; | |
60 | - } | |
44 | + public $imagesUpload = ''; | |
61 | 45 | |
62 | 46 | /** |
63 | 47 | * @inheritdoc | ... | ... |
common/modules/relation/Module.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation; | |
4 | - | |
5 | -/** | |
6 | - * relation module definition class | |
7 | - * | |
8 | - * @sections: | |
9 | - * KEY - alias of the section | |
10 | - * - name | |
11 | - * - field | |
12 | - * - via | |
13 | - * - model | |
14 | - * - linked_table | |
15 | - * - alias | |
16 | - * - entity1 | |
17 | - * - entity2: | |
18 | - * - label | |
19 | - * - listField | |
20 | - * - model | |
21 | - * - key | |
22 | - * - linked_key | |
23 | - */ | |
24 | -class Module extends \yii\base\Module | |
25 | -{ | |
26 | - /** | |
27 | - * @inheritdoc | |
28 | - */ | |
29 | - public $controllerNamespace = 'common\modules\relation\controllers'; | |
30 | - | |
31 | - public $relations; | |
32 | - | |
33 | - /** | |
34 | - * @inheritdoc | |
35 | - */ | |
36 | - public function init() | |
37 | - { | |
38 | - parent::init(); | |
39 | - } | |
40 | -} |
common/modules/relation/controllers/DefaultController.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation\controllers; | |
4 | - | |
5 | -use yii\web\Controller; | |
6 | - | |
7 | -/** | |
8 | - * Default controller for the `relation` module | |
9 | - */ | |
10 | -class DefaultController extends Controller | |
11 | -{ | |
12 | - /** | |
13 | - * Renders the index view for the module | |
14 | - * @return string | |
15 | - */ | |
16 | - public function actionIndex() | |
17 | - { | |
18 | - return $this->render('index'); | |
19 | - } | |
20 | -} |
common/modules/relation/controllers/ManageController.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation\controllers; | |
4 | - | |
5 | -use common\modules\rubrication\models\TaxOption; | |
6 | -use yii\base\Exception; | |
7 | -use yii\db\ActiveQuery; | |
8 | -use yii\helpers\ArrayHelper; | |
9 | -use yii\web\Response; | |
10 | -use yii\data\ActiveDataProvider; | |
11 | -use yii\db\ActiveRecord; | |
12 | -use yii\filters\ContentNegotiator; | |
13 | -use yii\web\Controller; | |
14 | -use Yii; | |
15 | -use common\modules\relation\relationHelper; | |
16 | -use common\modules\relation\models\Relation; | |
17 | -use common\modules\relation\models\RelationSearch; | |
18 | -use yii\web\NotFoundHttpException; | |
19 | - | |
20 | -/** | |
21 | - * Default controller for the `relation` module | |
22 | - */ | |
23 | -class ManageController extends Controller | |
24 | -{ | |
25 | - public function behaviors() | |
26 | - { | |
27 | - return [ | |
28 | - /*'bootstrap' => [ | |
29 | - 'class' => ContentNegotiator::className(), | |
30 | - 'only' => ['autocomplete'], | |
31 | - 'formats' => [ 'application/json' => Response::FORMAT_JSON], | |
32 | - 'languages' => [ | |
33 | - 'ru', | |
34 | - ], | |
35 | - ],*/ | |
36 | - ]; | |
37 | - } | |
38 | - | |
39 | - /** | |
40 | - * Renders the relations view | |
41 | - * @return string | |
42 | - */ | |
43 | - public function actionIndex() | |
44 | - { | |
45 | - $relations = relationHelper::getRelations(); | |
46 | - $list = []; | |
47 | - foreach ($relations as $key => $relation) { | |
48 | - $list[] = [ | |
49 | - 'key' => $key, | |
50 | - 'name' => $relation['name'], | |
51 | - 'entity1_label' => $relation['entity1']['label'], | |
52 | - 'entity1_model' => $relation['entity1']['model'], | |
53 | - 'entity2_label' => $relation['entity2']['label'], | |
54 | - 'entity2_model' => $relation['entity2']['model'], | |
55 | - ]; | |
56 | - } | |
57 | - return $this->render('relations', [ | |
58 | - 'relations' => $list | |
59 | - ]); | |
60 | - } | |
61 | - /** | |
62 | - * Renders the pars view for | |
63 | - * @return string | |
64 | - */ | |
65 | - public function actionPars($relation) | |
66 | - { | |
67 | - $relation_key = strtolower($relation); | |
68 | - $relation = relationHelper::getRelation($relation_key); | |
69 | - | |
70 | - $dataProvider = new ActiveDataProvider([ | |
71 | - 'query' => $relation['via']['model']::find(), | |
72 | - ]); | |
73 | - | |
74 | - return $this->render('pars', [ | |
75 | - 'dataProvider' => $dataProvider, | |
76 | - 'relation_key' => $relation_key, | |
77 | - 'relation' => $relation, | |
78 | - ]); | |
79 | - } | |
80 | - | |
81 | - public function actionCreate($relation) { | |
82 | - $relation_key = strtolower($relation); | |
83 | - $relation = relationHelper::getRelation($relation_key); | |
84 | - | |
85 | - $model = new $relation['via']['model']; | |
86 | - | |
87 | - if ($model->load(Yii::$app->request->post())) { | |
88 | - $model->save(); | |
89 | - return $this->redirect(['pars', 'relation' => $relation_key]); | |
90 | -// return $this->redirect(['update', 'id' => $model->{$relation['entity1']['linked_key']}. ':' .$model->{$relation['entity2']['linked_key']}]); | |
91 | - } else { | |
92 | - return $this->render('create', [ | |
93 | - 'model' => $model, | |
94 | -// 'items1' => $query1->limit(100)->all(), | |
95 | -// 'items2' => $query2->asArray()->all(), | |
96 | - 'relation_key' => $relation_key, | |
97 | - 'relation' => $relation, | |
98 | - ]); | |
99 | - } | |
100 | - } | |
101 | - | |
102 | - /** | |
103 | - * Updates an existing TaxGroup model. | |
104 | - * If update is successful, the browser will be redirected to the 'view' page. | |
105 | - * @param integer $id | |
106 | - * @return mixed | |
107 | - */ | |
108 | - public function actionUpdate($relation, $id) { | |
109 | - $relation_key = strtolower($relation); | |
110 | - $relation = relationHelper::getRelation($relation_key); | |
111 | - | |
112 | - list($id1, $id2) = explode(':', $id); | |
113 | - | |
114 | - $model = $this->findModel($relation_key, $id1, $id2); | |
115 | - | |
116 | - if ($model->load(Yii::$app->request->post())) { | |
117 | - $connection = Yii::$app->getDb(); | |
118 | - $transaction = $connection->beginTransaction(); | |
119 | - try { | |
120 | - // Delete links from viaTable | |
121 | - $connection->createCommand() | |
122 | - ->update | |
123 | - ( | |
124 | - $relation['linked_table'], | |
125 | - [ | |
126 | - $relation['entity1']['linked_key'] => $model->getAttribute($relation['entity1']['linked_key']), | |
127 | - $relation['entity2']['linked_key'] => $model->getAttribute($relation['entity2']['linked_key']) | |
128 | - ], | |
129 | - $this->getWhere($relation_key, $id1, $id2) | |
130 | - ) | |
131 | - ->execute(); | |
132 | - $transaction->commit(); | |
133 | - } catch (Exception $ex) { | |
134 | - $transaction->rollback(); | |
135 | - throw $ex; | |
136 | - } | |
137 | - | |
138 | - return $this->redirect(['pars', 'relation' => $relation_key]); | |
139 | - } else { | |
140 | - return $this->render('update', [ | |
141 | - 'model' => $model, | |
142 | - 'value1' => $model->entity1->getAttribute($relation['entity1']['listField']), | |
143 | - 'value2' => $model->entity2->getAttribute($relation['entity2']['listField']), | |
144 | - 'relation_key' => $relation_key, | |
145 | - 'relation' => $relation, | |
146 | - ]); | |
147 | - } | |
148 | - } | |
149 | - | |
150 | - /** | |
151 | - * Deletes an existing TaxGroup model. | |
152 | - * If deletion is successful, the browser will be redirected to the 'index' page. | |
153 | - * @param integer $id | |
154 | - * @return mixed | |
155 | - */ | |
156 | - public function actionDelete($relation, $id) | |
157 | - { | |
158 | - $relation_key = strtolower($relation); | |
159 | - $relation = relationHelper::getRelation($relation_key); | |
160 | - | |
161 | - list($id1, $id2) = explode(':', $id); | |
162 | - | |
163 | - $connection = Yii::$app->getDb(); | |
164 | - $transaction = $connection->beginTransaction(); | |
165 | - try { | |
166 | - // Delete links from viaTable | |
167 | - $connection->createCommand() | |
168 | - ->delete | |
169 | - ( | |
170 | - $relation['linked_table'], | |
171 | - $this->getWhere($relation_key, $id1, $id2) | |
172 | - ) | |
173 | - ->execute(); | |
174 | - $transaction->commit(); | |
175 | - } catch (Exception $ex) { | |
176 | - $transaction->rollback(); | |
177 | - throw $ex; | |
178 | - } | |
179 | - | |
180 | - return $this->redirect(['pars', 'relation' => $relation_key]); | |
181 | - } | |
182 | - | |
183 | - public function actionAutocomplete() { | |
184 | - $relation_key = Yii::$app->request->get('relation_key'); | |
185 | - $entity = Yii::$app->request->get('entity'); | |
186 | - $term = Yii::$app->request->get('term'); | |
187 | - $relation_key = strtolower($relation_key); | |
188 | - $relation = relationHelper::getRelation($relation_key); | |
189 | - | |
190 | - /** @var ActiveQuery $query */ | |
191 | - $query = $relation[$entity]['model']::find(); | |
192 | - | |
193 | - if (!empty($relation[$entity]['searchJoin'])) { | |
194 | - $query->innerJoinWith($relation[$entity]['searchJoin']); | |
195 | - } | |
196 | - if (!empty($relation[$entity]['where'])) { | |
197 | - $query->where($relation[$entity]['where']); | |
198 | - } | |
199 | - $query->where(['ilike', $relation[$entity]['searchField'], $term]); | |
200 | - | |
201 | - print json_encode(ArrayHelper::map($query->limit(50)->all(), $relation[$entity]['key'], $relation[$entity]['listField'])); | |
202 | - exit; | |
203 | - } | |
204 | - | |
205 | - /** | |
206 | - * Finds the based model for relation on its primaries keys value. | |
207 | - * If the model is not found, a 404 HTTP exception will be thrown. | |
208 | - * @param string $relation | |
209 | - * @param integer $id1 | |
210 | - * @param integer $id2 | |
211 | - * @return ActiveRecord the loaded model | |
212 | - * @throws NotFoundHttpException if the model cannot be found | |
213 | - */ | |
214 | - protected function findModel($relation, $id1, $id2) | |
215 | - { | |
216 | - $relation_key = strtolower($relation); | |
217 | - $relation = relationHelper::getRelation($relation_key); | |
218 | - if (($model = $relation['via']['model']::findOne($this->getWhere($relation_key, $id1, $id2))) !== null) { | |
219 | - return $model; | |
220 | - } else { | |
221 | - throw new NotFoundHttpException('The requested page does not exist.'); | |
222 | - } | |
223 | - } | |
224 | - | |
225 | - protected function getWhere($relation_key, $id1, $id2) { | |
226 | - $relation = relationHelper::getRelation($relation_key); | |
227 | - // @todo Just think - if you need to search keys in the reverse order | |
228 | - $where = [ | |
229 | - $relation['entity1']['linked_key'] => $id1, | |
230 | - $relation['entity2']['linked_key'] => $id2, | |
231 | - ]; | |
232 | - if (!empty($relation['alias'])) { | |
233 | - $where[$relation['alias']] = $relation_key; | |
234 | - } | |
235 | - return $where; | |
236 | - } | |
237 | - | |
238 | -} |
common/modules/relation/models/Relation.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation\models; | |
4 | - | |
5 | -use common\modules\relation\relationHelper; | |
6 | -use Yii; | |
7 | - | |
8 | -/** | |
9 | - * This is the model class for table "relation". | |
10 | - * | |
11 | - * @property string $alias | |
12 | - * @property integer $entity1_id | |
13 | - * @property integer $entity2_id | |
14 | - */ | |
15 | -class Relation extends \yii\db\ActiveRecord | |
16 | -{ | |
17 | - /** | |
18 | - * @inheritdoc | |
19 | - */ | |
20 | - public static function tableName() | |
21 | - { | |
22 | - return 'relation'; | |
23 | - } | |
24 | - | |
25 | - /** | |
26 | - * @inheritdoc | |
27 | - */ | |
28 | - public function rules() | |
29 | - { | |
30 | - return [ | |
31 | - [['alias', 'entity1_id', 'entity2_id'], 'required'], | |
32 | - [['entity1_id', 'entity2_id'], 'integer'], | |
33 | - [['alias'], 'string', 'max' => 50] | |
34 | - ]; | |
35 | - } | |
36 | - | |
37 | - /** | |
38 | - * @inheritdoc | |
39 | - */ | |
40 | - public function attributeLabels() | |
41 | - { | |
42 | - return [ | |
43 | - 'alias' => Yii::t('relation', 'Alias'), | |
44 | - 'entity1_id' => Yii::t('relation', 'Entity1 ID'), | |
45 | - 'entity2_id' => Yii::t('relation', 'Entity2 ID'), | |
46 | - 'entity1' => Yii::t('relation', 'Entity1 ID'), | |
47 | - 'entity2' => Yii::t('relation', 'Entity2 ID'), | |
48 | - ]; | |
49 | - } | |
50 | - | |
51 | - /** | |
52 | - * @inheritdoc | |
53 | - * @return RelationQuery the active query used by this AR class. | |
54 | - */ | |
55 | - public static function find() | |
56 | - { | |
57 | - return new RelationQuery(get_called_class()); | |
58 | - } | |
59 | - | |
60 | - public function getRelationSection() { | |
61 | - return relationHelper::getRelation($this->alias); | |
62 | - } | |
63 | - | |
64 | - public function getEntity1() { | |
65 | - return $this->getEntity('entity1'); | |
66 | - } | |
67 | - | |
68 | - public function getEntity2() { | |
69 | - return $this->getEntity('entity2'); | |
70 | - } | |
71 | - | |
72 | - protected function getEntity($entity) { | |
73 | - $relation = $this->getRelationSection(); | |
74 | - if (!$relation) | |
75 | - return; | |
76 | - return $this->hasOne($relation[$entity]['model']::className(), [$relation[$entity]['key'] => $relation[$entity]['linked_key']]); | |
77 | - } | |
78 | -} |
common/modules/relation/models/RelationQuery.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation\models; | |
4 | - | |
5 | -/** | |
6 | - * This is the ActiveQuery class for [[Relation]]. | |
7 | - * | |
8 | - * @see Relation | |
9 | - */ | |
10 | -class RelationQuery extends \yii\db\ActiveQuery | |
11 | -{ | |
12 | - /*public function active() | |
13 | - { | |
14 | - $this->andWhere('[[status]]=1'); | |
15 | - return $this; | |
16 | - }*/ | |
17 | - | |
18 | - /** | |
19 | - * @inheritdoc | |
20 | - * @return Relation[]|array | |
21 | - */ | |
22 | - public function all($db = null) | |
23 | - { | |
24 | - return parent::all($db); | |
25 | - } | |
26 | - | |
27 | - /** | |
28 | - * @inheritdoc | |
29 | - * @return Relation|array|null | |
30 | - */ | |
31 | - public function one($db = null) | |
32 | - { | |
33 | - return parent::one($db); | |
34 | - } | |
35 | -} | |
36 | 0 | \ No newline at end of file |
common/modules/relation/relationBehavior.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation; | |
4 | - | |
5 | -use yii\base\Behavior; | |
6 | -use yii\base\Exception; | |
7 | -use yii\db\ActiveRecord; | |
8 | -use Yii; | |
9 | -use yii\helpers\ArrayHelper; | |
10 | - | |
11 | -class relationBehavior extends Behavior { | |
12 | - | |
13 | - /** @var array $fields Form-fields for current relations */ | |
14 | - public $fields = []; | |
15 | - | |
16 | - /** @var array $values Values for current relations */ | |
17 | - public $values = []; | |
18 | - | |
19 | - /** @var array $relations List of relations of current model */ | |
20 | - public $relations = []; | |
21 | - | |
22 | - /** | |
23 | - * @param ActiveRecord $owner | |
24 | - * @throws Exception | |
25 | - */ | |
26 | - public function attach($owner) | |
27 | - { | |
28 | - parent::attach($owner); | |
29 | - } | |
30 | - | |
31 | - /* | |
32 | - * Inicialize behavior (read and prepare params) | |
33 | - */ | |
34 | - public function init() { | |
35 | - | |
36 | - foreach ($this->relations as $relation_key => &$relation) { | |
37 | - if (is_string($relation)) { | |
38 | - // Get data from module's data | |
39 | - $relation_entity = $relation; | |
40 | - $relation = $this->_getRelationParams($relation_key); | |
41 | - $relation['inner'] = $relation[$relation_entity]; | |
42 | - $relation['outer'] = $relation[$relation_entity == 'entity1' ? 'entity2' : 'entity1']; | |
43 | - $relation['linked_table'] = $relation['via']['model']::tableName(); | |
44 | - if (!empty($relation['via']['alias'])) { | |
45 | - $relation['linked_alias'] = $relation['via']['alias']; | |
46 | - } | |
47 | - } | |
48 | - $this->fields[$relation['field']] = $relation_key; | |
49 | - | |
50 | - } | |
51 | - } | |
52 | - | |
53 | - /* | |
54 | - * Events for auto-drive relations data | |
55 | - */ | |
56 | - public function events() | |
57 | - { | |
58 | - return [ | |
59 | - ActiveRecord::EVENT_AFTER_INSERT => 'relationsAfterSave', | |
60 | - ActiveRecord::EVENT_AFTER_UPDATE => 'relationsAfterSave', | |
61 | - ActiveRecord::EVENT_BEFORE_DELETE => 'relationBeforeDelete', | |
62 | - ]; | |
63 | - } | |
64 | - | |
65 | - public function relationsAfterSave($insert) { | |
66 | - | |
67 | - if (is_array($modelPrimaryKey = $this->owner->getPrimaryKey())) { | |
68 | - throw new ErrorException('This behavior does not support composite primary keys'); | |
69 | - } | |
70 | - | |
71 | - foreach ($this->relations as $relation_key => $relation) { | |
72 | - if (empty($relation['field']) || !is_array($this->{$relation['field']})) | |
73 | - continue; | |
74 | - | |
75 | - $values = $this->{$relation['field']}; | |
76 | - | |
77 | - /** @var ActiveRecord $model */ | |
78 | - $model = new $relation['inner']['model']; | |
79 | - | |
80 | - $connection = $model::getDb(); | |
81 | - $transaction = $connection->beginTransaction(); | |
82 | - | |
83 | - $delete_where = [$relation['inner']['linked_key'] => $this->owner->{$relation['inner']['key']}]; | |
84 | - if (!empty($relation['linked_alias'])) { | |
85 | - $delete_where[$relation['linked_alias']] = $relation_key; | |
86 | - } | |
87 | - | |
88 | - try { | |
89 | - // Delete all links from viaTable | |
90 | - $connection->createCommand() | |
91 | - ->delete | |
92 | - ( | |
93 | - $relation['linked_table'], | |
94 | - $delete_where | |
95 | - ) | |
96 | - ->execute(); | |
97 | - | |
98 | - if (!empty($values)) { | |
99 | - | |
100 | - foreach($values as $value) { | |
101 | - $insertData = [ | |
102 | - $relation['inner']['linked_key'] => $this->owner->{$relation['inner']['key']}, | |
103 | - $relation['outer']['linked_key'] => $value | |
104 | - ]; | |
105 | - if (!empty($relation['linked_alias'])) { | |
106 | - $insertData[$relation['linked_alias']] = $relation_key; | |
107 | - } | |
108 | - | |
109 | - | |
110 | - $connection->createCommand() | |
111 | - ->insert | |
112 | - ( | |
113 | - $relation['linked_table'], | |
114 | - $insertData | |
115 | - ) | |
116 | - ->execute(); | |
117 | - } | |
118 | - } | |
119 | - $transaction->commit(); | |
120 | - | |
121 | -// $model->link($relation_key, ) | |
122 | - } catch (Exception $ex) { | |
123 | -// var_dump($relation_key, $relation);exit; | |
124 | - $transaction->rollback(); | |
125 | - throw $ex; | |
126 | - } | |
127 | - } | |
128 | - } | |
129 | - | |
130 | - public function relationBeforeDelete() { | |
131 | - if (is_array($modelPrimaryKey = $this->owner->getPrimaryKey())) { | |
132 | - throw new ErrorException('This behavior does not support composite primary keys'); | |
133 | - } | |
134 | - foreach ($this->relations as $relation_key => $relation) { | |
135 | - if (empty($relation['field'])) | |
136 | - continue; | |
137 | - $values = $this->{$relation['field']}; | |
138 | - | |
139 | - /** @var ActiveRecord $model */ | |
140 | - $model = new $relation['inner']['model']; | |
141 | - | |
142 | - $connection = $model::getDb(); | |
143 | - $transaction = $connection->beginTransaction(); | |
144 | - | |
145 | - // @todo Refix to ActiveRecord format | |
146 | - try { | |
147 | - // Delete all links from viaTable | |
148 | - $connection->createCommand() | |
149 | - ->delete | |
150 | - ( | |
151 | - $relation['linked_table'], | |
152 | - [$relation['inner']['linked_key'] => $this->owner->{$relation['inner']['key']}] | |
153 | - ) | |
154 | - ->execute(); | |
155 | - $transaction->commit(); | |
156 | - } catch (Exception $ex) { | |
157 | - $transaction->rollback(); | |
158 | - throw $ex; | |
159 | - } | |
160 | - } | |
161 | - } | |
162 | - | |
163 | - /** | |
164 | - * Get related data for $relation | |
165 | - * @params string $relation Relation key | |
166 | - */ | |
167 | - public function getRelations($relation) { | |
168 | - $relation = $this->_getRelation($relation); | |
169 | - return | |
170 | - $this->owner | |
171 | - ->hasMany($relation['outer']['model'], [$relation['outer']['key'] => $relation['outer']['linked_key']]) | |
172 | - ->viaTable($relation['linked_table'], [$relation['inner']['linked_key'] => $relation['inner']['key']]); | |
173 | - } | |
174 | - | |
175 | - /* | |
176 | - * Get relation params for $relation | |
177 | - * @param string $relation Relation key | |
178 | - */ | |
179 | - protected function _getRelation($relation) { | |
180 | - $relation = strtolower($relation); | |
181 | - return isset($this->relations[$relation]) ? $this->relations[$relation] : null; | |
182 | - } | |
183 | - | |
184 | - /** | |
185 | - * Return relation data from main app config | |
186 | - * @params string $section Relations key | |
187 | - */ | |
188 | - protected function _getRelationParams($section) { | |
189 | - $relation = relationHelper::getRelation($section); | |
190 | - if (!$relation) | |
191 | - throw new Exception('Relation "' . $section . '" not set on this application.'); | |
192 | - return $relation; | |
193 | - } | |
194 | - | |
195 | - protected function _getRelationNameByField($field) { | |
196 | - return isset($this->fields[$field]) ? $this->fields[$field] : null; | |
197 | - } | |
198 | - | |
199 | - protected function _getRelationByField($field) { | |
200 | - return ( isset($this->fields[$field]) && isset($this->relations[$this->fields[$field]]) ) ? $this->relations[$this->fields[$field]] : null; | |
201 | - } | |
202 | - | |
203 | - /** | |
204 | - * @inheritdoc | |
205 | - */ | |
206 | - public function canGetProperty($name, $checkVars = true) | |
207 | - { | |
208 | - return true; | |
209 | - } | |
210 | - | |
211 | - /** | |
212 | - * @inheritdoc | |
213 | - */ | |
214 | - public function canSetProperty($name, $checkVars = true) | |
215 | - { | |
216 | - return array_key_exists($name, $this->fields) ? | |
217 | - true : parent::canSetProperty($name, $checkVars = true); | |
218 | - } | |
219 | - | |
220 | - /** | |
221 | - * @inheritdoc | |
222 | - */ | |
223 | - public function __set($name, $value) { | |
224 | - if (isset($this->fields[$name])) { | |
225 | - $this->values[$name] = $value; | |
226 | - } | |
227 | - } | |
228 | - | |
229 | - /** | |
230 | - * @inheritdoc | |
231 | - */ | |
232 | - public function __get($name) { | |
233 | - if (isset($this->values[$name])) { | |
234 | - return $this->values[$name]; | |
235 | - } else { | |
236 | - $relation_key = $this->_getRelationNameByField($name); | |
237 | - if (!$relation_key) | |
238 | - return; | |
239 | - | |
240 | - return $this->getRelations($relation_key); | |
241 | - } | |
242 | - } | |
243 | -} | |
244 | 0 | \ No newline at end of file |
common/modules/relation/relationHelper.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation; | |
4 | - | |
5 | -use Yii; | |
6 | -use yii\base\Object; | |
7 | - | |
8 | -class relationHelper extends Object { | |
9 | - /** @var array $relations Cached relations list */ | |
10 | - private static $relations; | |
11 | - | |
12 | - /** | |
13 | - * Return all relations for current @app | |
14 | - * @return array | |
15 | - */ | |
16 | - public static function getRelations() { | |
17 | - $module = \Yii::$app->getModule('relation'); | |
18 | - | |
19 | - if (!is_array($module->relations)) | |
20 | - return []; | |
21 | - | |
22 | - return $module->relations; | |
23 | - } | |
24 | - | |
25 | - /** | |
26 | - * Return one relation for key $name | |
27 | - * @param string $name | |
28 | - * @return string (@todo refix to relationOject) | |
29 | - */ | |
30 | - public static function getRelation($name) { | |
31 | - $name = strtolower($name); | |
32 | - if (isset(self::$relations[$name])) { | |
33 | - return self::$relations[$name]; | |
34 | - } | |
35 | - $relations = self::getRelations(); | |
36 | - if (isset($relations[$name])) { | |
37 | - self::$relations[$name] = self::prepareRelation($relations[$name]); | |
38 | - } else { | |
39 | - self::$relations[$name] = null; | |
40 | - } | |
41 | - return self::$relations[$name]; | |
42 | - } | |
43 | - | |
44 | - | |
45 | - private static function prepareRelation($relation) { | |
46 | - if (!isset($relation['linked_table']) && isset($relation['via']['model'])) { | |
47 | - $relation['linked_table'] = $relation['via']['model']::tableName(); | |
48 | - } | |
49 | - return $relation; | |
50 | - } | |
51 | - | |
52 | - /** | |
53 | - * @param string $name | |
54 | - * @return bool | |
55 | - */ | |
56 | - public static function issetRelation($name) { | |
57 | - $relations = self::getRelations(); | |
58 | - return isset($relations[$name]); | |
59 | - } | |
60 | -} | |
61 | 0 | \ No newline at end of file |
common/modules/relation/relationObject.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation; | |
4 | - | |
5 | -use yii\base\Object; | |
6 | - | |
7 | -class relationObject extends Object { | |
8 | - protected $key; | |
9 | - protected $entity1; | |
10 | - protected $entity2; | |
11 | - | |
12 | - protected $moduleRelations = []; | |
13 | - | |
14 | - public function __construct($relation_key, $params) { | |
15 | - $relation_key = strtolower($relation_key); | |
16 | - if (is_string($params)) { | |
17 | - // Get data from module's data | |
18 | - $relation_entity = $params; | |
19 | - $relation = $this->_getRelationParams($relation_key); | |
20 | - $relation['inner'] = $relation[$relation_entity]; | |
21 | - $relation['outer'] = $relation[$relation_entity == 'entity1' ? 'entity2' : 'entity1']; | |
22 | - $relation['linked_table'] = $relation['via']['model']::tableName(); | |
23 | - } | |
24 | - | |
25 | - $this->moduleRelations = relationHelper::getRelations(); | |
26 | - | |
27 | - | |
28 | - } | |
29 | -} | |
30 | 0 | \ No newline at end of file |
common/modules/relation/relationQueryTrait.php deleted
1 | -<?php | |
2 | - | |
3 | -namespace common\modules\relation; | |
4 | - | |
5 | -trait relationQueryTrait { | |
6 | - | |
7 | - static public $cache_tree = []; | |
8 | - | |
9 | - /** @var \yii\db\ActiveQuery $this */ | |
10 | - static $model; | |
11 | - | |
12 | - /* | |
13 | - * @return \yii\db\ActiveQuery | |
14 | - */ | |
15 | - private function getModel() | |
16 | - { | |
17 | - if (empty(self::$model)) { | |
18 | - $class = $this->modelClass; | |
19 | - self::$model = new $class; | |
20 | - } | |
21 | - return self::$model; | |
22 | - } | |
23 | - | |
24 | - /*public function getRelations($relation) { | |
25 | - $model = $this->getModel(); | |
26 | - | |
27 | - $relation = $model->_getRelation($relation); | |
28 | - return | |
29 | - $model->owner | |
30 | - ->hasMany($relation['outer']['model'], [$relation['outer']['key'] => $relation['outer']['linked_key']]) | |
31 | - ->viaTable($relation['linked_table'], [$relation['inner']['linked_key'] => $relation['inner']['key']]); | |
32 | - }*/ | |
33 | -} | |
34 | 0 | \ No newline at end of file |
common/modules/relation/views/default/index.php deleted
1 | -<div class="relation-default-index"> | |
2 | - <h1><?= $this->context->action->uniqueId ?></h1> | |
3 | - <p> | |
4 | - This is the view content for action "<?= $this->context->action->id ?>". | |
5 | - The action belongs to the controller "<?= get_class($this->context) ?>" | |
6 | - in the "<?= $this->context->module->id ?>" module. | |
7 | - </p> | |
8 | - <p> | |
9 | - You may customize this page by editing the following file:<br> | |
10 | - <code><?= __FILE__ ?></code> | |
11 | - </p> | |
12 | -</div> |
common/modules/relation/views/manage/_form.php deleted
1 | -<?php | |
2 | - | |
3 | -use yii\helpers\Html; | |
4 | -use yii\widgets\ActiveForm; | |
5 | -use yii\helpers\ArrayHelper; | |
6 | -use yii\jui\AutoComplete; | |
7 | - | |
8 | -/* @var $this yii\web\View */ | |
9 | -/* @var $model common\modules\rubrication\models\TaxGroup */ | |
10 | -/* @var $form yii\widgets\ActiveForm */ | |
11 | -?> | |
12 | - | |
13 | -<div class="relation-form"> | |
14 | - | |
15 | - <?php $form = ActiveForm::begin(); ?> | |
16 | - | |
17 | - <?= $form->field($model, $relation['entity1']['linked_key'])->widget( | |
18 | - AutoComplete::className(), [ | |
19 | -// 'model' => \common\modules\relation\models\Relation::className(), | |
20 | - 'clientOptions' => [ | |
21 | - 'source' => \yii\helpers\Url::to(['manage/autocomplete/', 'relation_key' => $relation_key, 'entity' => 'entity1']), | |
22 | - 'dataType' => 'json', | |
23 | - 'autoFill' => true, | |
24 | - 'minLength' => '2', | |
25 | - ], | |
26 | - 'options' => [ | |
27 | - 'value' => empty($value1) ? '' : $value1, | |
28 | - 'class'=>'form-control', | |
29 | - 'placeholder' => $relation['entity1']['label'] | |
30 | - ] | |
31 | - ]); | |
32 | - ?> | |
33 | - | |
34 | - <?= $form->field($model, $relation['entity2']['linked_key'])->widget( | |
35 | - AutoComplete::className(), [ | |
36 | -// 'model' => \common\modules\relation\models\Relation::className(), | |
37 | - 'clientOptions' => [ | |
38 | - 'source' => \yii\helpers\Url::to(['manage/autocomplete/', 'relation_key' => $relation_key, 'entity' => 'entity2']), | |
39 | - 'dataType' => 'json', | |
40 | - 'autoFill' => true, | |
41 | - 'minLength' => '2', | |
42 | - 'allowClear' => true, | |
43 | - ], | |
44 | - 'options' => [ | |
45 | - 'value' => empty($value2) ? '' : $value2, | |
46 | - 'class'=>'form-control', | |
47 | - 'placeholder' => $relation['entity2']['label'] | |
48 | - ] | |
49 | - ]); | |
50 | - ?> | |
51 | - | |
52 | - <div class="form-group"> | |
53 | - <?= Html::submitButton($model->isNewRecord ? Yii::t('relation', 'Create') : Yii::t('relation', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
54 | - </div> | |
55 | - | |
56 | - <?php ActiveForm::end(); ?> | |
57 | - | |
58 | -</div> |
common/modules/relation/views/manage/create.php deleted
1 | -<?php | |
2 | - | |
3 | -use yii\helpers\Html; | |
4 | - | |
5 | -/* @var $this yii\web\View */ | |
6 | - | |
7 | -$this->title = Yii::t('relation', $relation['name']); | |
8 | -$this->params['breadcrumbs'][] = ['label' => Yii::t('relation', 'Relations'), 'url' => ['index']]; | |
9 | -$this->params['breadcrumbs'][] = ['label' => Yii::t('relation', $relation['name']), 'url' => ['/relation/manage/pars', 'relation' => $relation_key]]; | |
10 | -$this->params['breadcrumbs'][] = $this->title; | |
11 | -?> | |
12 | -<div class="tax-group-create"> | |
13 | - | |
14 | - <h1><?= Html::encode($this->title) ?></h1> | |
15 | - | |
16 | - <?= $this->render('_form', [ | |
17 | - 'model' => $model, | |
18 | - 'relation_key' => $relation_key, | |
19 | - 'relation' => $relation, | |
20 | - ]) ?> | |
21 | - | |
22 | -</div> |
common/modules/relation/views/manage/pars.php deleted
1 | -<?php | |
2 | - | |
3 | -use yii\helpers\Html; | |
4 | -use yii\grid\GridView; | |
5 | -/* @var $this yii\web\View */ | |
6 | - | |
7 | -$this->title = Yii::t('relation', 'Relation items for {relation}', ['relation' => $relation['name']]); | |
8 | -$this->params['breadcrumbs'][] = ['label' => Yii::t('relation', 'Relations'), 'url' => ['/relation/manage']]; | |
9 | -$this->params['breadcrumbs'][] = $this->title; | |
10 | -?> | |
11 | -<div class="relation-pars"> | |
12 | - | |
13 | - <h1><?= Html::encode($this->title) ?></h1> | |
14 | - | |
15 | - <p> | |
16 | - <?= Html::a(Yii::t('relation', 'Create relation'), ['create?relation='. $relation_key], ['class' => 'btn btn-success']) ?> | |
17 | - </p> | |
18 | - | |
19 | - <?= GridView::widget([ | |
20 | - 'dataProvider' => $dataProvider, | |
21 | - 'columns' => [ | |
22 | - ['class' => 'yii\grid\SerialColumn'], | |
23 | - 'alias', | |
24 | - 'entity1.'. $relation['entity1']['listField'], | |
25 | - 'entity2.'. $relation['entity2']['listField'], | |
26 | - [ | |
27 | - 'class' => 'yii\grid\ActionColumn', | |
28 | - 'template' => '{update} {delete}', | |
29 | - 'buttons' => [ | |
30 | - 'update' => function ($url, $model) { | |
31 | - return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ | |
32 | - 'title' => Yii::t('relation', 'Edit par'), | |
33 | - ]); | |
34 | - }, | |
35 | - 'delete' => function ($url, $model) { | |
36 | - return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [ | |
37 | - 'title' => Yii::t('relation', 'Delete par'), | |
38 | - ]); | |
39 | - }, | |
40 | - ], | |
41 | - 'urlCreator' => function ($action, $model, $key, $index) use ($relation, $relation_key) { | |
42 | - if ($action === 'update') { | |
43 | - $url ='/admin/relation/manage/update?relation='. $relation_key .'&id='. $model->{$relation['entity1']['linked_key']} .':'. $model->{$relation['entity2']['linked_key']}; | |
44 | - return $url; | |
45 | - } | |
46 | - if ($action === 'delete') { | |
47 | - $url ='/admin/relation/manage/delete?relation='. $relation_key .'&id='. $model->{$relation['entity1']['linked_key']} .':'. $model->{$relation['entity2']['linked_key']}; | |
48 | - return $url; | |
49 | - } | |
50 | - } | |
51 | - ], | |
52 | - ], | |
53 | - ]); ?> | |
54 | -</div> |
common/modules/relation/views/manage/relations.php deleted
1 | -<?php | |
2 | - | |
3 | -use yii\helpers\Html; | |
4 | -use yii\grid\GridView; | |
5 | -/* @var $this yii\web\View */ | |
6 | - | |
7 | -$this->title = Yii::t('relation', 'Relations'); | |
8 | -$this->params['breadcrumbs'][] = $this->title; | |
9 | -?> | |
10 | -<div class="relation-sections"> | |
11 | - | |
12 | - <h1><?= Html::encode($this->title) ?></h1> | |
13 | - | |
14 | - <?php | |
15 | - $dataProvider = new \yii\data\ArrayDataProvider([ | |
16 | - 'allModels' => $relations, | |
17 | - 'sort' => [ | |
18 | - 'attributes' => ['name', 'key', 'entity1_label', 'entity2_label'], | |
19 | - ], | |
20 | - 'pagination' => [ | |
21 | - 'pageSize' => 10, | |
22 | - ], | |
23 | - ]); | |
24 | - ?> | |
25 | - | |
26 | - <?= GridView::widget([ | |
27 | - 'dataProvider' => $dataProvider, | |
28 | - 'columns' => [ | |
29 | - ['class' => 'yii\grid\SerialColumn'], | |
30 | - 'name', | |
31 | - 'key', | |
32 | - 'entity1_label', | |
33 | - 'entity2_label', | |
34 | - [ | |
35 | - 'class' => 'yii\grid\ActionColumn', | |
36 | - 'template' => '{view}', | |
37 | - 'buttons' => [ | |
38 | - 'view' => function ($url, $model) { | |
39 | - return Html::a('<span class="glyphicon glyphicon-th-list"></span>', $url, [ | |
40 | - 'title' => Yii::t('relation', 'View pars'), | |
41 | - ]); | |
42 | - }, | |
43 | - ], | |
44 | - 'urlCreator' => function ($action, $model) { | |
45 | - if ($action === 'view') { | |
46 | - $url ='/admin/relation/manage/pars?relation='. $model['key']; | |
47 | - return $url; | |
48 | - } | |
49 | - } | |
50 | - ], | |
51 | - ], | |
52 | - ]); ?> | |
53 | -</div> |
common/modules/relation/views/manage/update.php deleted
1 | -<?php | |
2 | - | |
3 | -use yii\helpers\Html; | |
4 | - | |
5 | - | |
6 | -/* @var $this yii\web\View */ | |
7 | - | |
8 | -$this->title = Yii::t('relation', $relation['name']); | |
9 | -$this->params['breadcrumbs'][] = ['label' => Yii::t('relation', 'Relations'), 'url' => ['index']]; | |
10 | -$this->params['breadcrumbs'][] = ['label' => Yii::t('relation', $relation['name']), 'url' => ['/relation/manage/pars', 'relation' => $relation_key]]; | |
11 | -$this->params['breadcrumbs'][] = $this->title; | |
12 | -?> | |
13 | -<div class="tax-group-create"> | |
14 | - | |
15 | - <h1><?= Html::encode($this->title) ?></h1> | |
16 | - | |
17 | - <?= $this->render('_form', [ | |
18 | - 'model' => $model, | |
19 | - 'value1' => $value1, | |
20 | - 'value2' => $value2, | |
21 | - 'relation_key' => $relation_key, | |
22 | - 'relation' => $relation, | |
23 | - ]) ?> | |
24 | - | |
25 | -</div> |
common/modules/rubrication/models/TaxGroup.php
... | ... | @@ -3,7 +3,6 @@ |
3 | 3 | namespace common\modules\rubrication\models; |
4 | 4 | |
5 | 5 | use common\modules\product\models\Category; |
6 | -use common\modules\relation\relationBehavior; | |
7 | 6 | use Yii; |
8 | 7 | |
9 | 8 | /** |
... | ... | @@ -34,12 +33,6 @@ class TaxGroup extends \yii\db\ActiveRecord |
34 | 33 | public function behaviors() |
35 | 34 | { |
36 | 35 | return [ |
37 | - [ | |
38 | - 'class' => relationBehavior::className(), | |
39 | - 'relations' => [ | |
40 | - 'tax_group_to_category' => 'entity1', | |
41 | - ] | |
42 | - ], | |
43 | 36 | 'slug' => [ |
44 | 37 | 'class' => 'common\behaviors\Slug', |
45 | 38 | 'in_attribute' => 'name', | ... | ... |
frontend/models/ProductFrontendSearch.php
... | ... | @@ -3,24 +3,25 @@ |
3 | 3 | namespace frontend\models; |
4 | 4 | |
5 | 5 | use common\modules\product\helpers\ProductHelper; |
6 | -use common\modules\product\models\Brand; | |
7 | -use common\modules\product\models\BrandName; | |
8 | -use common\modules\product\models\CategoryName; | |
9 | 6 | use common\modules\product\models\ProductCategory; |
10 | 7 | use common\modules\product\models\ProductOption; |
11 | -use common\modules\product\models\ProductSearch; | |
12 | 8 | use common\modules\rubrication\models\TaxGroup; |
13 | 9 | use common\modules\rubrication\models\TaxOption; |
14 | 10 | use Yii; |
15 | 11 | use yii\base\Model; |
16 | 12 | use yii\data\ActiveDataProvider; |
17 | 13 | use yii\db\ActiveQuery; |
18 | -use yii\db\ActiveRecord; | |
19 | -use yii\web\NotFoundHttpException; | |
14 | + | |
20 | 15 | use common\modules\product\models\Product; |
21 | 16 | use common\modules\product\models\ProductVariant; |
22 | 17 | |
23 | 18 | class ProductFrontendSearch extends Product { |
19 | + | |
20 | + | |
21 | + public $price_interval; | |
22 | + public $brands; | |
23 | + | |
24 | + | |
24 | 25 | /** |
25 | 26 | * @inheritdoc |
26 | 27 | */ | ... | ... |