diff --git a/backend/controllers/DeliveryController.php b/backend/controllers/DeliveryController.php
new file mode 100755
index 0000000..793f18e
--- /dev/null
+++ b/backend/controllers/DeliveryController.php
@@ -0,0 +1,162 @@
+ [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => [ 'POST' ],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Lists all Delivery models.
+ * @return mixed
+ */
+ public function actionIndex()
+ {
+ $searchModel = new DeliverySearch();
+ $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+
+ return $this->render('index', [
+ 'dataProvider' => $dataProvider,
+ 'searchModel' => $searchModel,
+ ]);
+ }
+
+ /**
+ * Displays a single Delivery model.
+ *
+ * @param integer $id
+ *
+ * @return mixed
+ */
+ public function actionView($id)
+ {
+ return $this->render('view', [
+ 'model' => $this->findModel($id),
+ ]);
+ }
+
+ /**
+ * Creates a new Delivery model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return mixed
+ */
+ public function actionCreate()
+ {
+ $model = new Delivery();
+ $model->generateLangs();
+ $parent_items = Delivery::find()
+ ->with('lang')
+ ->all();
+ $parent_items = ArrayHelper::map($parent_items, 'id', 'lang.title');
+ if($model->load(Yii::$app->request->post()) && $model->save()) {
+ return $this->redirect([
+ 'view',
+ 'id' => $model->id,
+ ]);
+ } else {
+ return $this->render('create', [
+ 'model' => $model,
+ 'model_langs' => $model->model_langs,
+ 'parent_items' => $parent_items,
+ ]);
+ }
+ }
+
+ /**
+ * Updates an existing Delivery model.
+ * If update is successful, the browser will be redirected to the 'view' page.
+ *
+ * @param integer $id
+ *
+ * @return mixed
+ */
+ public function actionUpdate($id)
+ {
+ $model = $this->findModel($id);
+ $model->generateLangs();
+ $parent_items = Delivery::find()
+ ->with('lang')
+ ->all();
+ $parent_items = ArrayHelper::map($parent_items, 'id', 'lang.title');
+
+ if($model->load(Yii::$app->request->post())) {
+ $model->loadLangs(\Yii::$app->request);
+ if($model->save() && $model->transactionStatus) {
+ return $this->redirect([
+ 'view',
+ 'id' => $model->id,
+ ]);
+ }
+ }
+ return $this->render('update', [
+ 'model' => $model,
+ 'model_langs' => $model->model_langs,
+ 'parent_items' => $parent_items,
+ ]);
+ }
+
+ /**
+ * Deletes an existing Delivery model.
+ * If deletion is successful, the browser will be redirected to the 'index' page.
+ *
+ * @param integer $id
+ *
+ * @return mixed
+ */
+ public function actionDelete($id)
+ {
+ $this->findModel($id)
+ ->delete();
+
+ return $this->redirect([ 'index' ]);
+ }
+
+ /**
+ * Finds the Delivery model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ *
+ * @param integer $id
+ *
+ * @return Delivery the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if(( $model = Delivery::find()
+ ->with('parent')
+ ->where([
+ 'id' => $id,
+ ])
+ ->one() ) !== NULL
+ ) {
+ return $model;
+ } else {
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+ }
+ }
diff --git a/backend/views/delivery/_form.php b/backend/views/delivery/_form.php
new file mode 100755
index 0000000..f048ff9
--- /dev/null
+++ b/backend/views/delivery/_form.php
@@ -0,0 +1,43 @@
+
+
+
diff --git a/backend/views/delivery/_form_language.php b/backend/views/delivery/_form_language.php
new file mode 100755
index 0000000..745f719
--- /dev/null
+++ b/backend/views/delivery/_form_language.php
@@ -0,0 +1,18 @@
+
+= $form->field($model_lang, '[' . $language->language_id . ']title')
+ ->textInput([ 'maxlength' => true ]); ?>
+
+= $form->field($model_lang, '[' . $language->language_id . ']text')
+ ->textarea(); ?>
diff --git a/backend/views/delivery/_search.php b/backend/views/delivery/_search.php
new file mode 100644
index 0000000..92fed1c
--- /dev/null
+++ b/backend/views/delivery/_search.php
@@ -0,0 +1,33 @@
+
+
+
+
+ ['index'],
+ 'method' => 'get',
+ ]); ?>
+
+ = $form->field($model, 'id') ?>
+
+ = $form->field($model, 'parent_id') ?>
+
+ = $form->field($model, 'value') ?>
+
+ = $form->field($model, 'sort') ?>
+
+
+ = Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
+ = Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
+
+
+
+
+
diff --git a/backend/views/delivery/create.php b/backend/views/delivery/create.php
new file mode 100755
index 0000000..1f54616
--- /dev/null
+++ b/backend/views/delivery/create.php
@@ -0,0 +1,23 @@
+title = 'Create Delivery';
+$this->params['breadcrumbs'][] = ['label' => 'Deliveries', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ 'model_langs' => $model_langs,
+ 'parent_items' => $parent_items,
+ ]) ?>
+
+
diff --git a/backend/views/delivery/index.php b/backend/views/delivery/index.php
new file mode 100755
index 0000000..8d59ec9
--- /dev/null
+++ b/backend/views/delivery/index.php
@@ -0,0 +1,43 @@
+title = 'Deliveries';
+ $this->params[ 'breadcrumbs' ][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+ = Html::a('Create Delivery', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?>
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'filterModel' => $searchModel,
+ 'columns' => [
+
+ 'id',
+ [
+ 'attribute' => 'title',
+ 'value' => 'lang.title',
+ ],
+ [
+ 'attribute' => 'parent_title',
+ 'value' => 'parent.lang.title',
+ ],
+ 'value',
+ [ 'class' => 'yii\grid\ActionColumn' ],
+ ],
+ ]); ?>
+
diff --git a/backend/views/delivery/update.php b/backend/views/delivery/update.php
new file mode 100755
index 0000000..6d5244c
--- /dev/null
+++ b/backend/views/delivery/update.php
@@ -0,0 +1,39 @@
+title = 'Update Delivery: ' . $model->lang->title;
+ $this->params[ 'breadcrumbs' ][] = [
+ 'label' => 'Deliveries',
+ 'url' => [ 'index' ],
+ ];
+ $this->params[ 'breadcrumbs' ][] = [
+ 'label' => $model->lang->title,
+ 'url' => [
+ 'view',
+ 'id' => $model->id,
+ ],
+ ];
+ $this->params[ 'breadcrumbs' ][] = 'Update';
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ 'model_langs' => $model_langs,
+ 'parent_items' => $parent_items,
+ ]) ?>
+
+
diff --git a/backend/views/delivery/view.php b/backend/views/delivery/view.php
new file mode 100755
index 0000000..5d7e28b
--- /dev/null
+++ b/backend/views/delivery/view.php
@@ -0,0 +1,65 @@
+title = $model->lang->title;
+ $this->params[ 'breadcrumbs' ][] = [
+ 'label' => 'Deliveries',
+ 'url' => [ 'index' ],
+ ];
+ $this->params[ 'breadcrumbs' ][] = $this->title;
+
+ $parent_link = '';
+ if(!empty( $model->parent )) {
+ $parent_link = Html::a($model->parent->lang->title, [
+ 'view',
+ 'id' => $model->parent->id,
+ ]);
+ }
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+ = Html::a('Update', [
+ 'update',
+ 'id' => $model->id,
+ ], [ 'class' => 'btn btn-primary' ]) ?>
+ = Html::a('Delete', [
+ 'delete',
+ 'id' => $model->id,
+ ], [
+ 'class' => 'btn btn-danger',
+ 'data' => [
+ 'confirm' => 'Are you sure you want to delete this item?',
+ 'method' => 'post',
+ ],
+ ]) ?>
+
+
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'id',
+ [
+ 'label' => 'Вид доставки',
+ 'value' => $parent_link,
+ 'format' => 'html',
+ ],
+ 'lang.title',
+ 'lang.text',
+ 'value',
+ 'sort',
+ ],
+ ]) ?>
+
+
diff --git a/backend/views/layouts/main-sidebar.php b/backend/views/layouts/main-sidebar.php
index f01ea02..c1a5c0e 100755
--- a/backend/views/layouts/main-sidebar.php
+++ b/backend/views/layouts/main-sidebar.php
@@ -22,6 +22,7 @@ use yii\widgets\Menu;
'url' => ['/product/manage'],
'active' => preg_match('/^manage.*$/', $this->context->id) ||
preg_match('/^category.*$/', $this->context->id) ||
+ preg_match('/^delivery.*$/', $this->context->id) ||
preg_match('/^brand.*$/', $this->context->id) ||
preg_match('/^product-unit.*$/', $this->context->id) ||
preg_match('/^import.*$/', $this->context->id) ||
@@ -34,11 +35,11 @@ use yii\widgets\Menu;
'url' => ['/product/manage'],
'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide']
],
-// [
-// 'label' => 'Модификации',
-// 'url' => ['/product/variant'],
-// 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide']
-// ],
+ [
+ 'label' => 'Доставка',
+ 'url' => ['/delivery'],
+ 'options' => ['class'=>\Yii::$app->user->can('delivery') ? '' :'hide']
+ ],
[
'label' => 'Категории',
'url' => ['/category'],
diff --git a/common/behaviors/ImageBehavior.php b/common/behaviors/ImageBehavior.php
old mode 100644
new mode 100755
index a458740..a458740
--- a/common/behaviors/ImageBehavior.php
+++ b/common/behaviors/ImageBehavior.php
diff --git a/common/behaviors/MultipleImgBehavior.php b/common/behaviors/MultipleImgBehavior.php
old mode 100644
new mode 100755
index 4926e94..4926e94
--- a/common/behaviors/MultipleImgBehavior.php
+++ b/common/behaviors/MultipleImgBehavior.php
diff --git a/common/behaviors/SaveMultipleFileBehavior.php b/common/behaviors/SaveMultipleFileBehavior.php
old mode 100644
new mode 100755
index d8b3351..d8b3351
--- a/common/behaviors/SaveMultipleFileBehavior.php
+++ b/common/behaviors/SaveMultipleFileBehavior.php
diff --git a/common/models/Delivery.php b/common/models/Delivery.php
index dbc452c..4204ba8 100755
--- a/common/models/Delivery.php
+++ b/common/models/Delivery.php
@@ -10,21 +10,26 @@
/**
* Class Delivery
* * From language behavior *
- * @property OrdersDeliveryLang $lang
- * @property OrdersDeliveryLang[] $langs
- * @property OrdersDeliveryLang $object_lang
- * @property string $ownerKey
- * @property string $langKey
- * @property OrdersDeliveryLang[] $model_langs
- * @property bool $transactionStatus
+ * @property OrdersDeliveryLang $lang
+ * @property OrdersDeliveryLang[] $langs
+ * @property OrdersDeliveryLang $object_lang
+ * @property string $ownerKey
+ * @property string $langKey
+ * @property OrdersDeliveryLang[] $model_langs
+ * @property integer $id
+ * @property integer $parent_id
+ * @property integer $sort
+ * @property integer $value
+ * @property bool $transactionStatus
+ * @property Delivery $parent
* @method string getOwnerKey()
- * @method void setOwnerKey(string $value)
+ * @method void setOwnerKey( string $value )
* @method string getLangKey()
- * @method void setLangKey(string $value)
+ * @method void setLangKey( string $value )
* @method ActiveQuery getLangs()
* @method ActiveQuery getLang( integer $language_id )
* @method OrdersDeliveryLang[] generateLangs()
- * @method void loadLangs(Request $request)
+ * @method void loadLangs( Request $request )
* @method bool linkLangs()
* @method bool saveLangs()
* @method bool getTransactionStatus()
@@ -37,7 +42,12 @@
{
return [
'language' => [
- 'class' => LanguageBehavior::className(),
+ 'class' => LanguageBehavior::className(),
+ 'object_lang' => OrdersDeliveryLang::className(),
+ // optional, default to {TableLang}::className()
+ 'ownerKey' => 'id',
+ //optional, default to {Table}->primaryKey()[0]
+ 'langKey' => 'orders_delivery_id',
],
];
}
@@ -47,4 +57,22 @@
return 'orders_delivery';
}
+ public function rules()
+ {
+ return [
+ [
+ [
+ 'value',
+ 'parent_id',
+ 'sort',
+ ],
+ 'integer',
+ ],
+ ];
+ }
+
+ public function getParent()
+ {
+ return $this->hasOne(self::className(), [ 'id' => 'parent_id' ]);
+ }
}
\ No newline at end of file
diff --git a/common/models/DeliverySearch.php b/common/models/DeliverySearch.php
new file mode 100755
index 0000000..757ca05
--- /dev/null
+++ b/common/models/DeliverySearch.php
@@ -0,0 +1,106 @@
+joinWith('lang')
+ ->joinWith([ 'parent as parent' ]);
+
+ // add conditions that should always apply here
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => $query,
+ 'sort' => [
+ 'attributes' => [
+ 'id',
+ 'value',
+ 'title' => [
+ 'asc' => [ 'orders_delivery_lang.title' => SORT_ASC ],
+ 'desc' => [ 'orders_delivery_lang.title' => SORT_DESC ],
+ ],
+ ],
+ ],
+ ]);
+
+ $this->load($params);
+
+ if(!$this->validate()) {
+ // uncomment the following line if you do not want to return any records when validation fails
+ // $query->where('0=1');
+ return $dataProvider;
+ }
+
+ // grid filtering conditions
+ $query->andFilterWhere([
+ 'id' => $this->id,
+ 'value' => $this->value,
+ 'sort' => $this->sort,
+ ])
+ ->andFilterWhere([
+ 'like',
+ 'orders_delivery_lang.title',
+ $this->title,
+ ]);
+
+ return $dataProvider;
+ }
+ }
diff --git a/common/models/OrdersDeliveryLang.php b/common/models/OrdersDeliveryLang.php
index d7dacc3..8e261ab 100755
--- a/common/models/OrdersDeliveryLang.php
+++ b/common/models/OrdersDeliveryLang.php
@@ -1,81 +1,119 @@
255],
- [['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.'],
- [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']],
- [['orders_delivery_id'], 'exist', 'skipOnError' => true, 'targetClass' => Delivery::className(), 'targetAttribute' => ['orders_delivery_id' => 'id']],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'orders_delivery_id' => Yii::t('app', 'orders_delivery_id'),
- 'language_id' => Yii::t('app', 'language_id'),
- 'title' => Yii::t('app', 'title'),
- 'text' => Yii::t('app', 'text'),
- ];
- }
-
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getLanguage()
- {
- return $this->hasOne(Language::className(), ['language_id' => 'language_id']);
- }
-
- /**
- * @return \yii\db\ActiveQuery
+ * This is the model class for table "orders_delivery_lang".
+ * @property integer $orders_delivery_id
+ * @property integer $language_id
+ * @property string $title
+ * @property string $text
+ * @property Language $language
+ * @property Delivery $delivery
*/
- public function getDelivery()
+ class OrdersDeliveryLang extends ActiveRecord
{
- return $this->hasOne(Delivery::className(), ['id' => 'orders_delivery_id']);
+
+ /**
+ * @inheritdoc
+ */
+ public static function primaryKey()
+ {
+ return [
+ 'orders_delivery_id',
+ 'language_id',
+ ];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public static function tableName()
+ {
+ return 'orders_delivery_lang';
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function rules()
+ {
+ return [
+ [
+ [
+ 'title',
+ 'text',
+ ],
+ 'required',
+ ],
+ [
+ [ 'text' ],
+ 'string',
+ ],
+ [
+ [ 'title' ],
+ 'string',
+ 'max' => 255,
+ ],
+ [
+ [
+ '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.',
+ ],
+ [
+ [ 'language_id' ],
+ 'exist',
+ 'skipOnError' => true,
+ 'targetClass' => Language::className(),
+ 'targetAttribute' => [ 'language_id' => 'language_id' ],
+ ],
+ [
+ [ 'orders_delivery_id' ],
+ 'exist',
+ 'skipOnError' => true,
+ 'targetClass' => Delivery::className(),
+ 'targetAttribute' => [ 'orders_delivery_id' => 'id' ],
+ ],
+ ];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'orders_delivery_id' => Yii::t('app', 'orders_delivery_id'),
+ 'language_id' => Yii::t('app', 'language_id'),
+ 'title' => Yii::t('app', 'title'),
+ 'text' => Yii::t('app', 'text'),
+ ];
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getLanguage()
+ {
+ return $this->hasOne(Language::className(), [ 'language_id' => 'language_id' ]);
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getDelivery()
+ {
+ return $this->hasOne(Delivery::className(), [ 'id' => 'orders_delivery_id' ]);
+ }
}
-}
--
libgit2 0.21.4