Commit e0205ce9d82186bdc5915873aa1e4a2245124a7f
1 parent
4a7f93fb
-Delivery model prettyfied
Showing
15 changed files
with
689 additions
and
90 deletions
Show diff stats
1 | +<?php | ||
2 | + | ||
3 | + namespace backend\controllers; | ||
4 | + | ||
5 | + use common\models\DeliverySearch; | ||
6 | + use Yii; | ||
7 | + use common\models\Delivery; | ||
8 | + use yii\web\Controller; | ||
9 | + use yii\web\NotFoundHttpException; | ||
10 | + use yii\filters\VerbFilter; | ||
11 | + use yii\helpers\ArrayHelper; | ||
12 | + | ||
13 | + /** | ||
14 | + * DeliveryController implements the CRUD actions for Delivery model. | ||
15 | + */ | ||
16 | + class DeliveryController extends Controller | ||
17 | + { | ||
18 | + | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public function behaviors() | ||
23 | + { | ||
24 | + return [ | ||
25 | + 'verbs' => [ | ||
26 | + 'class' => VerbFilter::className(), | ||
27 | + 'actions' => [ | ||
28 | + 'delete' => [ 'POST' ], | ||
29 | + ], | ||
30 | + ], | ||
31 | + ]; | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * Lists all Delivery models. | ||
36 | + * @return mixed | ||
37 | + */ | ||
38 | + public function actionIndex() | ||
39 | + { | ||
40 | + $searchModel = new DeliverySearch(); | ||
41 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
42 | + | ||
43 | + return $this->render('index', [ | ||
44 | + 'dataProvider' => $dataProvider, | ||
45 | + 'searchModel' => $searchModel, | ||
46 | + ]); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Displays a single Delivery model. | ||
51 | + * | ||
52 | + * @param integer $id | ||
53 | + * | ||
54 | + * @return mixed | ||
55 | + */ | ||
56 | + public function actionView($id) | ||
57 | + { | ||
58 | + return $this->render('view', [ | ||
59 | + 'model' => $this->findModel($id), | ||
60 | + ]); | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Creates a new Delivery model. | ||
65 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
66 | + * @return mixed | ||
67 | + */ | ||
68 | + public function actionCreate() | ||
69 | + { | ||
70 | + $model = new Delivery(); | ||
71 | + $model->generateLangs(); | ||
72 | + $parent_items = Delivery::find() | ||
73 | + ->with('lang') | ||
74 | + ->all(); | ||
75 | + $parent_items = ArrayHelper::map($parent_items, 'id', 'lang.title'); | ||
76 | + if($model->load(Yii::$app->request->post()) && $model->save()) { | ||
77 | + return $this->redirect([ | ||
78 | + 'view', | ||
79 | + 'id' => $model->id, | ||
80 | + ]); | ||
81 | + } else { | ||
82 | + return $this->render('create', [ | ||
83 | + 'model' => $model, | ||
84 | + 'model_langs' => $model->model_langs, | ||
85 | + 'parent_items' => $parent_items, | ||
86 | + ]); | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * Updates an existing Delivery model. | ||
92 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
93 | + * | ||
94 | + * @param integer $id | ||
95 | + * | ||
96 | + * @return mixed | ||
97 | + */ | ||
98 | + public function actionUpdate($id) | ||
99 | + { | ||
100 | + $model = $this->findModel($id); | ||
101 | + $model->generateLangs(); | ||
102 | + $parent_items = Delivery::find() | ||
103 | + ->with('lang') | ||
104 | + ->all(); | ||
105 | + $parent_items = ArrayHelper::map($parent_items, 'id', 'lang.title'); | ||
106 | + | ||
107 | + if($model->load(Yii::$app->request->post())) { | ||
108 | + $model->loadLangs(\Yii::$app->request); | ||
109 | + if($model->save() && $model->transactionStatus) { | ||
110 | + return $this->redirect([ | ||
111 | + 'view', | ||
112 | + 'id' => $model->id, | ||
113 | + ]); | ||
114 | + } | ||
115 | + } | ||
116 | + return $this->render('update', [ | ||
117 | + 'model' => $model, | ||
118 | + 'model_langs' => $model->model_langs, | ||
119 | + 'parent_items' => $parent_items, | ||
120 | + ]); | ||
121 | + } | ||
122 | + | ||
123 | + /** | ||
124 | + * Deletes an existing Delivery model. | ||
125 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
126 | + * | ||
127 | + * @param integer $id | ||
128 | + * | ||
129 | + * @return mixed | ||
130 | + */ | ||
131 | + public function actionDelete($id) | ||
132 | + { | ||
133 | + $this->findModel($id) | ||
134 | + ->delete(); | ||
135 | + | ||
136 | + return $this->redirect([ 'index' ]); | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Finds the Delivery model based on its primary key value. | ||
141 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
142 | + * | ||
143 | + * @param integer $id | ||
144 | + * | ||
145 | + * @return Delivery the loaded model | ||
146 | + * @throws NotFoundHttpException if the model cannot be found | ||
147 | + */ | ||
148 | + protected function findModel($id) | ||
149 | + { | ||
150 | + if(( $model = Delivery::find() | ||
151 | + ->with('parent') | ||
152 | + ->where([ | ||
153 | + 'id' => $id, | ||
154 | + ]) | ||
155 | + ->one() ) !== NULL | ||
156 | + ) { | ||
157 | + return $model; | ||
158 | + } else { | ||
159 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
160 | + } | ||
161 | + } | ||
162 | + } |
1 | +<?php | ||
2 | + | ||
3 | + use common\models\OrdersDeliveryLang; | ||
4 | + use yii\helpers\Html; | ||
5 | + use yii\widgets\ActiveForm; | ||
6 | + use common\modules\language\widgets\LanguageForm; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var yii\web\View $this | ||
10 | + * @var common\models\Delivery $model | ||
11 | + * @var yii\widgets\ActiveForm $form | ||
12 | + * @var OrdersDeliveryLang[] $model_langs | ||
13 | + */ | ||
14 | +?> | ||
15 | + | ||
16 | +<div class="delivery-form"> | ||
17 | + | ||
18 | + <?php $form = ActiveForm::begin(); ?> | ||
19 | + | ||
20 | + <?= $form->field($model, 'parent_id') | ||
21 | + ->dropDownList($parent_items, [ | ||
22 | + 'prompt' => "Выберите вид доставки..." | ||
23 | + ]) ?> | ||
24 | + | ||
25 | + <?= $form->field($model, 'value') | ||
26 | + ->textInput() ?> | ||
27 | + | ||
28 | + <?= $form->field($model, 'sort') | ||
29 | + ->textInput() ?> | ||
30 | + | ||
31 | + <?= LanguageForm::widget([ | ||
32 | + 'model_langs' => $model_langs, | ||
33 | + 'formView' => '@backend/views/delivery/_form_language', | ||
34 | + 'form' => $form, | ||
35 | + ]) ?> | ||
36 | + | ||
37 | + <div class="form-group"> | ||
38 | + <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> | ||
39 | + </div> | ||
40 | + | ||
41 | + <?php ActiveForm::end(); ?> | ||
42 | + | ||
43 | +</div> |
1 | +<?php | ||
2 | + use common\models\OrdersDeliveryLang; | ||
3 | + use common\modules\language\models\Language; | ||
4 | + use yii\web\View; | ||
5 | + use yii\widgets\ActiveForm; | ||
6 | + | ||
7 | + /** | ||
8 | + * @var OrdersDeliveryLang $model_lang | ||
9 | + * @var Language $language | ||
10 | + * @var ActiveForm $form | ||
11 | + * @var View $this | ||
12 | + */ | ||
13 | +?> | ||
14 | +<?= $form->field($model_lang, '[' . $language->language_id . ']title') | ||
15 | + ->textInput([ 'maxlength' => true ]); ?> | ||
16 | + | ||
17 | +<?= $form->field($model_lang, '[' . $language->language_id . ']text') | ||
18 | + ->textarea(); ?> |
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | +use yii\widgets\ActiveForm; | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $model common\models\DeliverySearch */ | ||
8 | +/* @var $form yii\widgets\ActiveForm */ | ||
9 | +?> | ||
10 | + | ||
11 | +<div class="delivery-search"> | ||
12 | + | ||
13 | + <?php $form = ActiveForm::begin([ | ||
14 | + 'action' => ['index'], | ||
15 | + 'method' => 'get', | ||
16 | + ]); ?> | ||
17 | + | ||
18 | + <?= $form->field($model, 'id') ?> | ||
19 | + | ||
20 | + <?= $form->field($model, 'parent_id') ?> | ||
21 | + | ||
22 | + <?= $form->field($model, 'value') ?> | ||
23 | + | ||
24 | + <?= $form->field($model, 'sort') ?> | ||
25 | + | ||
26 | + <div class="form-group"> | ||
27 | + <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> | ||
28 | + <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> | ||
29 | + </div> | ||
30 | + | ||
31 | + <?php ActiveForm::end(); ?> | ||
32 | + | ||
33 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | + | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $model common\models\Delivery */ | ||
8 | + | ||
9 | +$this->title = 'Create Delivery'; | ||
10 | +$this->params['breadcrumbs'][] = ['label' => 'Deliveries', 'url' => ['index']]; | ||
11 | +$this->params['breadcrumbs'][] = $this->title; | ||
12 | +?> | ||
13 | +<div class="delivery-create"> | ||
14 | + | ||
15 | + <h1><?= Html::encode($this->title) ?></h1> | ||
16 | + | ||
17 | + <?= $this->render('_form', [ | ||
18 | + 'model' => $model, | ||
19 | + 'model_langs' => $model_langs, | ||
20 | + 'parent_items' => $parent_items, | ||
21 | + ]) ?> | ||
22 | + | ||
23 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use yii\helpers\Html; | ||
4 | + use yii\grid\GridView; | ||
5 | + use yii\web\View; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + use common\models\DeliverySearch; | ||
8 | + | ||
9 | + /** | ||
10 | + * @var View $this | ||
11 | + * @var ActiveDataProvider $dataProvider | ||
12 | + * @var DeliverySearch $searchModel | ||
13 | + */ | ||
14 | + | ||
15 | + $this->title = 'Deliveries'; | ||
16 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
17 | +?> | ||
18 | +<div class="delivery-index"> | ||
19 | + | ||
20 | + <h1><?= Html::encode($this->title) ?></h1> | ||
21 | + | ||
22 | + <p> | ||
23 | + <?= Html::a('Create Delivery', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> | ||
24 | + </p> | ||
25 | + <?= GridView::widget([ | ||
26 | + 'dataProvider' => $dataProvider, | ||
27 | + 'filterModel' => $searchModel, | ||
28 | + 'columns' => [ | ||
29 | + | ||
30 | + 'id', | ||
31 | + [ | ||
32 | + 'attribute' => 'title', | ||
33 | + 'value' => 'lang.title', | ||
34 | + ], | ||
35 | + [ | ||
36 | + 'attribute' => 'parent_title', | ||
37 | + 'value' => 'parent.lang.title', | ||
38 | + ], | ||
39 | + 'value', | ||
40 | + [ 'class' => 'yii\grid\ActionColumn' ], | ||
41 | + ], | ||
42 | + ]); ?> | ||
43 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\models\OrdersDeliveryLang; | ||
4 | + use yii\helpers\Html; | ||
5 | + use common\models\Delivery; | ||
6 | + use yii\web\View; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var Delivery $model | ||
11 | + * @var array $parent_items | ||
12 | + * @var OrdersDeliveryLang[] $model_langs | ||
13 | + */ | ||
14 | + | ||
15 | + $this->title = 'Update Delivery: ' . $model->lang->title; | ||
16 | + $this->params[ 'breadcrumbs' ][] = [ | ||
17 | + 'label' => 'Deliveries', | ||
18 | + 'url' => [ 'index' ], | ||
19 | + ]; | ||
20 | + $this->params[ 'breadcrumbs' ][] = [ | ||
21 | + 'label' => $model->lang->title, | ||
22 | + 'url' => [ | ||
23 | + 'view', | ||
24 | + 'id' => $model->id, | ||
25 | + ], | ||
26 | + ]; | ||
27 | + $this->params[ 'breadcrumbs' ][] = 'Update'; | ||
28 | +?> | ||
29 | +<div class="delivery-update"> | ||
30 | + | ||
31 | + <h1><?= Html::encode($this->title) ?></h1> | ||
32 | + | ||
33 | + <?= $this->render('_form', [ | ||
34 | + 'model' => $model, | ||
35 | + 'model_langs' => $model_langs, | ||
36 | + 'parent_items' => $parent_items, | ||
37 | + ]) ?> | ||
38 | + | ||
39 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\models\Delivery; | ||
4 | + use yii\helpers\Html; | ||
5 | + use yii\widgets\DetailView; | ||
6 | + use yii\web\View; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var Delivery $model | ||
11 | + */ | ||
12 | + | ||
13 | + $this->title = $model->lang->title; | ||
14 | + $this->params[ 'breadcrumbs' ][] = [ | ||
15 | + 'label' => 'Deliveries', | ||
16 | + 'url' => [ 'index' ], | ||
17 | + ]; | ||
18 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
19 | + | ||
20 | + $parent_link = ''; | ||
21 | + if(!empty( $model->parent )) { | ||
22 | + $parent_link = Html::a($model->parent->lang->title, [ | ||
23 | + 'view', | ||
24 | + 'id' => $model->parent->id, | ||
25 | + ]); | ||
26 | + } | ||
27 | +?> | ||
28 | +<div class="delivery-view"> | ||
29 | + | ||
30 | + <h1><?= Html::encode($this->title) ?></h1> | ||
31 | + | ||
32 | + <p> | ||
33 | + <?= Html::a('Update', [ | ||
34 | + 'update', | ||
35 | + 'id' => $model->id, | ||
36 | + ], [ 'class' => 'btn btn-primary' ]) ?> | ||
37 | + <?= Html::a('Delete', [ | ||
38 | + 'delete', | ||
39 | + 'id' => $model->id, | ||
40 | + ], [ | ||
41 | + 'class' => 'btn btn-danger', | ||
42 | + 'data' => [ | ||
43 | + 'confirm' => 'Are you sure you want to delete this item?', | ||
44 | + 'method' => 'post', | ||
45 | + ], | ||
46 | + ]) ?> | ||
47 | + </p> | ||
48 | + | ||
49 | + <?= DetailView::widget([ | ||
50 | + 'model' => $model, | ||
51 | + 'attributes' => [ | ||
52 | + 'id', | ||
53 | + [ | ||
54 | + 'label' => 'Вид доставки', | ||
55 | + 'value' => $parent_link, | ||
56 | + 'format' => 'html', | ||
57 | + ], | ||
58 | + 'lang.title', | ||
59 | + 'lang.text', | ||
60 | + 'value', | ||
61 | + 'sort', | ||
62 | + ], | ||
63 | + ]) ?> | ||
64 | + | ||
65 | +</div> |
backend/views/layouts/main-sidebar.php
@@ -22,6 +22,7 @@ use yii\widgets\Menu; | @@ -22,6 +22,7 @@ use yii\widgets\Menu; | ||
22 | 'url' => ['/product/manage'], | 22 | 'url' => ['/product/manage'], |
23 | 'active' => preg_match('/^manage.*$/', $this->context->id) || | 23 | 'active' => preg_match('/^manage.*$/', $this->context->id) || |
24 | preg_match('/^category.*$/', $this->context->id) || | 24 | preg_match('/^category.*$/', $this->context->id) || |
25 | + preg_match('/^delivery.*$/', $this->context->id) || | ||
25 | preg_match('/^brand.*$/', $this->context->id) || | 26 | preg_match('/^brand.*$/', $this->context->id) || |
26 | preg_match('/^product-unit.*$/', $this->context->id) || | 27 | preg_match('/^product-unit.*$/', $this->context->id) || |
27 | preg_match('/^import.*$/', $this->context->id) || | 28 | preg_match('/^import.*$/', $this->context->id) || |
@@ -34,11 +35,11 @@ use yii\widgets\Menu; | @@ -34,11 +35,11 @@ use yii\widgets\Menu; | ||
34 | 'url' => ['/product/manage'], | 35 | 'url' => ['/product/manage'], |
35 | 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide'] | 36 | 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide'] |
36 | ], | 37 | ], |
37 | -// [ | ||
38 | -// 'label' => 'Модификации', | ||
39 | -// 'url' => ['/product/variant'], | ||
40 | -// 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide'] | ||
41 | -// ], | 38 | + [ |
39 | + 'label' => 'Доставка', | ||
40 | + 'url' => ['/delivery'], | ||
41 | + 'options' => ['class'=>\Yii::$app->user->can('delivery') ? '' :'hide'] | ||
42 | + ], | ||
42 | [ | 43 | [ |
43 | 'label' => 'Категории', | 44 | 'label' => 'Категории', |
44 | 'url' => ['/category'], | 45 | 'url' => ['/category'], |
common/models/Delivery.php
@@ -10,21 +10,26 @@ | @@ -10,21 +10,26 @@ | ||
10 | /** | 10 | /** |
11 | * Class Delivery | 11 | * Class Delivery |
12 | * * From language behavior * | 12 | * * From language behavior * |
13 | - * @property OrdersDeliveryLang $lang | ||
14 | - * @property OrdersDeliveryLang[] $langs | ||
15 | - * @property OrdersDeliveryLang $object_lang | ||
16 | - * @property string $ownerKey | ||
17 | - * @property string $langKey | ||
18 | - * @property OrdersDeliveryLang[] $model_langs | ||
19 | - * @property bool $transactionStatus | 13 | + * @property OrdersDeliveryLang $lang |
14 | + * @property OrdersDeliveryLang[] $langs | ||
15 | + * @property OrdersDeliveryLang $object_lang | ||
16 | + * @property string $ownerKey | ||
17 | + * @property string $langKey | ||
18 | + * @property OrdersDeliveryLang[] $model_langs | ||
19 | + * @property integer $id | ||
20 | + * @property integer $parent_id | ||
21 | + * @property integer $sort | ||
22 | + * @property integer $value | ||
23 | + * @property bool $transactionStatus | ||
24 | + * @property Delivery $parent | ||
20 | * @method string getOwnerKey() | 25 | * @method string getOwnerKey() |
21 | - * @method void setOwnerKey(string $value) | 26 | + * @method void setOwnerKey( string $value ) |
22 | * @method string getLangKey() | 27 | * @method string getLangKey() |
23 | - * @method void setLangKey(string $value) | 28 | + * @method void setLangKey( string $value ) |
24 | * @method ActiveQuery getLangs() | 29 | * @method ActiveQuery getLangs() |
25 | * @method ActiveQuery getLang( integer $language_id ) | 30 | * @method ActiveQuery getLang( integer $language_id ) |
26 | * @method OrdersDeliveryLang[] generateLangs() | 31 | * @method OrdersDeliveryLang[] generateLangs() |
27 | - * @method void loadLangs(Request $request) | 32 | + * @method void loadLangs( Request $request ) |
28 | * @method bool linkLangs() | 33 | * @method bool linkLangs() |
29 | * @method bool saveLangs() | 34 | * @method bool saveLangs() |
30 | * @method bool getTransactionStatus() | 35 | * @method bool getTransactionStatus() |
@@ -37,7 +42,12 @@ | @@ -37,7 +42,12 @@ | ||
37 | { | 42 | { |
38 | return [ | 43 | return [ |
39 | 'language' => [ | 44 | 'language' => [ |
40 | - 'class' => LanguageBehavior::className(), | 45 | + 'class' => LanguageBehavior::className(), |
46 | + 'object_lang' => OrdersDeliveryLang::className(), | ||
47 | + // optional, default to {TableLang}::className() | ||
48 | + 'ownerKey' => 'id', | ||
49 | + //optional, default to {Table}->primaryKey()[0] | ||
50 | + 'langKey' => 'orders_delivery_id', | ||
41 | ], | 51 | ], |
42 | ]; | 52 | ]; |
43 | } | 53 | } |
@@ -47,4 +57,22 @@ | @@ -47,4 +57,22 @@ | ||
47 | return 'orders_delivery'; | 57 | return 'orders_delivery'; |
48 | } | 58 | } |
49 | 59 | ||
60 | + public function rules() | ||
61 | + { | ||
62 | + return [ | ||
63 | + [ | ||
64 | + [ | ||
65 | + 'value', | ||
66 | + 'parent_id', | ||
67 | + 'sort', | ||
68 | + ], | ||
69 | + 'integer', | ||
70 | + ], | ||
71 | + ]; | ||
72 | + } | ||
73 | + | ||
74 | + public function getParent() | ||
75 | + { | ||
76 | + return $this->hasOne(self::className(), [ 'id' => 'parent_id' ]); | ||
77 | + } | ||
50 | } | 78 | } |
51 | \ No newline at end of file | 79 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * DeliverySearch represents the model behind the search form about `common\models\Delivery`. | ||
10 | + */ | ||
11 | + class DeliverySearch extends Delivery | ||
12 | + { | ||
13 | + | ||
14 | + /** | ||
15 | + * @var string | ||
16 | + */ | ||
17 | + public $title; | ||
18 | + | ||
19 | + /** | ||
20 | + * @var string | ||
21 | + */ | ||
22 | + public $parent_title; | ||
23 | + | ||
24 | + /** | ||
25 | + * @inheritdoc | ||
26 | + */ | ||
27 | + public function rules() | ||
28 | + { | ||
29 | + return [ | ||
30 | + [ | ||
31 | + [ | ||
32 | + 'id', | ||
33 | + 'parent_id', | ||
34 | + 'value', | ||
35 | + 'sort', | ||
36 | + ], | ||
37 | + 'integer', | ||
38 | + ], | ||
39 | + [ | ||
40 | + [ 'title' ], | ||
41 | + 'safe', | ||
42 | + ], | ||
43 | + ]; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * @inheritdoc | ||
48 | + */ | ||
49 | + public function scenarios() | ||
50 | + { | ||
51 | + // bypass scenarios() implementation in the parent class | ||
52 | + return Model::scenarios(); | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Creates data provider instance with search query applied | ||
57 | + * | ||
58 | + * @param array $params | ||
59 | + * | ||
60 | + * @return ActiveDataProvider | ||
61 | + */ | ||
62 | + public function search($params) | ||
63 | + { | ||
64 | + $query = Delivery::find() | ||
65 | + ->joinWith('lang') | ||
66 | + ->joinWith([ 'parent as parent' ]); | ||
67 | + | ||
68 | + // add conditions that should always apply here | ||
69 | + | ||
70 | + $dataProvider = new ActiveDataProvider([ | ||
71 | + 'query' => $query, | ||
72 | + 'sort' => [ | ||
73 | + 'attributes' => [ | ||
74 | + 'id', | ||
75 | + 'value', | ||
76 | + 'title' => [ | ||
77 | + 'asc' => [ 'orders_delivery_lang.title' => SORT_ASC ], | ||
78 | + 'desc' => [ 'orders_delivery_lang.title' => SORT_DESC ], | ||
79 | + ], | ||
80 | + ], | ||
81 | + ], | ||
82 | + ]); | ||
83 | + | ||
84 | + $this->load($params); | ||
85 | + | ||
86 | + if(!$this->validate()) { | ||
87 | + // uncomment the following line if you do not want to return any records when validation fails | ||
88 | + // $query->where('0=1'); | ||
89 | + return $dataProvider; | ||
90 | + } | ||
91 | + | ||
92 | + // grid filtering conditions | ||
93 | + $query->andFilterWhere([ | ||
94 | + 'id' => $this->id, | ||
95 | + 'value' => $this->value, | ||
96 | + 'sort' => $this->sort, | ||
97 | + ]) | ||
98 | + ->andFilterWhere([ | ||
99 | + 'like', | ||
100 | + 'orders_delivery_lang.title', | ||
101 | + $this->title, | ||
102 | + ]); | ||
103 | + | ||
104 | + return $dataProvider; | ||
105 | + } | ||
106 | + } |
common/models/OrdersDeliveryLang.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | -namespace common\models; | ||
4 | - | ||
5 | -use common\modules\language\models\Language; | ||
6 | -use Yii; | ||
7 | - | ||
8 | -/** | ||
9 | - * This is the model class for table "orders_delivery_lang". | ||
10 | - * | ||
11 | - * @property integer $orders_delivery_id | ||
12 | - * @property integer $language_id | ||
13 | - * @property string $title | ||
14 | - * @property string $text | ||
15 | - * | ||
16 | - * @property Language $language | ||
17 | - * @property Delivery $delivery | ||
18 | - */ | ||
19 | -class OrdersDeliveryLang extends \yii\db\ActiveRecord | ||
20 | -{ | ||
21 | 2 | ||
22 | - public static function primaryKey() | ||
23 | - { | ||
24 | - return [ | ||
25 | - 'orders_delivery_id', | ||
26 | - 'language_id', | ||
27 | - ]; | ||
28 | - } | 3 | + namespace common\models; |
4 | + | ||
5 | + use common\modules\language\models\Language; | ||
6 | + use Yii; | ||
7 | + use yii\db\ActiveRecord; | ||
29 | 8 | ||
30 | /** | 9 | /** |
31 | - * @inheritdoc | ||
32 | - */ | ||
33 | - public static function tableName() | ||
34 | - { | ||
35 | - return 'orders_delivery_lang'; | ||
36 | - } | ||
37 | - | ||
38 | - /** | ||
39 | - * @inheritdoc | ||
40 | - */ | ||
41 | - public function rules() | ||
42 | - { | ||
43 | - return [ | ||
44 | - [['title', 'text'], 'required'], | ||
45 | - [['text'], 'string'], | ||
46 | - [['title'], 'string', 'max' => 255], | ||
47 | - [['orders_delivery_id', 'language_id'], 'unique', 'targetAttribute' => ['orders_delivery_id', 'language_id'], 'message' => 'The combination of Orders Delivery ID and Language ID has already been taken.'], | ||
48 | - [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], | ||
49 | - [['orders_delivery_id'], 'exist', 'skipOnError' => true, 'targetClass' => Delivery::className(), 'targetAttribute' => ['orders_delivery_id' => 'id']], | ||
50 | - ]; | ||
51 | - } | ||
52 | - | ||
53 | - /** | ||
54 | - * @inheritdoc | ||
55 | - */ | ||
56 | - public function attributeLabels() | ||
57 | - { | ||
58 | - return [ | ||
59 | - 'orders_delivery_id' => Yii::t('app', 'orders_delivery_id'), | ||
60 | - 'language_id' => Yii::t('app', 'language_id'), | ||
61 | - 'title' => Yii::t('app', 'title'), | ||
62 | - 'text' => Yii::t('app', 'text'), | ||
63 | - ]; | ||
64 | - } | ||
65 | - | ||
66 | - /** | ||
67 | - * @return \yii\db\ActiveQuery | ||
68 | - */ | ||
69 | - public function getLanguage() | ||
70 | - { | ||
71 | - return $this->hasOne(Language::className(), ['language_id' => 'language_id']); | ||
72 | - } | ||
73 | - | ||
74 | - /** | ||
75 | - * @return \yii\db\ActiveQuery | 10 | + * This is the model class for table "orders_delivery_lang". |
11 | + * @property integer $orders_delivery_id | ||
12 | + * @property integer $language_id | ||
13 | + * @property string $title | ||
14 | + * @property string $text | ||
15 | + * @property Language $language | ||
16 | + * @property Delivery $delivery | ||
76 | */ | 17 | */ |
77 | - public function getDelivery() | 18 | + class OrdersDeliveryLang extends ActiveRecord |
78 | { | 19 | { |
79 | - return $this->hasOne(Delivery::className(), ['id' => 'orders_delivery_id']); | 20 | + |
21 | + /** | ||
22 | + * @inheritdoc | ||
23 | + */ | ||
24 | + public static function primaryKey() | ||
25 | + { | ||
26 | + return [ | ||
27 | + 'orders_delivery_id', | ||
28 | + 'language_id', | ||
29 | + ]; | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * @inheritdoc | ||
34 | + */ | ||
35 | + public static function tableName() | ||
36 | + { | ||
37 | + return 'orders_delivery_lang'; | ||
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * @inheritdoc | ||
42 | + */ | ||
43 | + public function rules() | ||
44 | + { | ||
45 | + return [ | ||
46 | + [ | ||
47 | + [ | ||
48 | + 'title', | ||
49 | + 'text', | ||
50 | + ], | ||
51 | + 'required', | ||
52 | + ], | ||
53 | + [ | ||
54 | + [ 'text' ], | ||
55 | + 'string', | ||
56 | + ], | ||
57 | + [ | ||
58 | + [ 'title' ], | ||
59 | + 'string', | ||
60 | + 'max' => 255, | ||
61 | + ], | ||
62 | + [ | ||
63 | + [ | ||
64 | + 'orders_delivery_id', | ||
65 | + 'language_id', | ||
66 | + ], | ||
67 | + 'unique', | ||
68 | + 'targetAttribute' => [ | ||
69 | + 'orders_delivery_id', | ||
70 | + 'language_id', | ||
71 | + ], | ||
72 | + 'message' => 'The combination of Orders Delivery ID and Language ID has already been taken.', | ||
73 | + ], | ||
74 | + [ | ||
75 | + [ 'language_id' ], | ||
76 | + 'exist', | ||
77 | + 'skipOnError' => true, | ||
78 | + 'targetClass' => Language::className(), | ||
79 | + 'targetAttribute' => [ 'language_id' => 'language_id' ], | ||
80 | + ], | ||
81 | + [ | ||
82 | + [ 'orders_delivery_id' ], | ||
83 | + 'exist', | ||
84 | + 'skipOnError' => true, | ||
85 | + 'targetClass' => Delivery::className(), | ||
86 | + 'targetAttribute' => [ 'orders_delivery_id' => 'id' ], | ||
87 | + ], | ||
88 | + ]; | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * @inheritdoc | ||
93 | + */ | ||
94 | + public function attributeLabels() | ||
95 | + { | ||
96 | + return [ | ||
97 | + 'orders_delivery_id' => Yii::t('app', 'orders_delivery_id'), | ||
98 | + 'language_id' => Yii::t('app', 'language_id'), | ||
99 | + 'title' => Yii::t('app', 'title'), | ||
100 | + 'text' => Yii::t('app', 'text'), | ||
101 | + ]; | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * @return \yii\db\ActiveQuery | ||
106 | + */ | ||
107 | + public function getLanguage() | ||
108 | + { | ||
109 | + return $this->hasOne(Language::className(), [ 'language_id' => 'language_id' ]); | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * @return \yii\db\ActiveQuery | ||
114 | + */ | ||
115 | + public function getDelivery() | ||
116 | + { | ||
117 | + return $this->hasOne(Delivery::className(), [ 'id' => 'orders_delivery_id' ]); | ||
118 | + } | ||
80 | } | 119 | } |
81 | -} |