diff --git a/backend/controllers/DeliveryController.php b/backend/controllers/DeliveryController.php index 793f18e..8019f03 100755 --- a/backend/controllers/DeliveryController.php +++ b/backend/controllers/DeliveryController.php @@ -73,18 +73,20 @@ ->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, - ]); + 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('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + 'parent_items' => $parent_items, + ]); } /** diff --git a/backend/controllers/LabelController.php b/backend/controllers/LabelController.php new file mode 100644 index 0000000..36b166e --- /dev/null +++ b/backend/controllers/LabelController.php @@ -0,0 +1,150 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Label models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new LabelSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Label model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Label model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Label(); + $model->generateLangs(); + + 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('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); + + } + + /** + * Updates an existing Label 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(); + + 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, + ]); + + } + + /** + * Deletes an existing Label 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 Label model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Label the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Label::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/backend/models/Label.php b/backend/models/Label.php index 7421573..78e5ed6 100755 --- a/backend/models/Label.php +++ b/backend/models/Label.php @@ -1,50 +1,64 @@ [ - 'class' => LanguageBehavior::className(), - ], - ]; + + public function rules() + { + return [ + [ + [ 'label' ], + 'string', + ], + ]; + } + + public static function tableName() + { + return 'orders_label'; + } + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + 'object_lang' => OrdersLabelLang::className(), + 'ownerKey' => 'id', + 'langKey' => 'orders_label_id', + ], + ]; + } } -} diff --git a/backend/models/LabelSearch.php b/backend/models/LabelSearch.php new file mode 100644 index 0000000..8af7a64 --- /dev/null +++ b/backend/models/LabelSearch.php @@ -0,0 +1,102 @@ +joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'sort' => [ + 'attributes' => [ + 'id', + 'label', + 'name' => [ + 'asc' => [ 'orders_label_lang.name' => SORT_ASC ], + 'desc' => [ 'orders_label_lang.name' => 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, + ]); + + $query->andFilterWhere([ + 'like', + 'label', + $this->label, + ]) + ->andFilterWhere([ + 'like', + 'orders_label_lang.name', + $this->name, + ]); + + return $dataProvider; + } + } diff --git a/backend/models/OrdersLabelLang.php b/backend/models/OrdersLabelLang.php index afad50f..7318871 100755 --- a/backend/models/OrdersLabelLang.php +++ b/backend/models/OrdersLabelLang.php @@ -1,78 +1,107 @@ 255], - [['orders_label_id', 'language_id'], 'unique', 'targetAttribute' => ['orders_label_id', 'language_id'], 'message' => 'The combination of Orders Label ID and Language ID has already been taken.'], - [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], - [['orders_label_id'], 'exist', 'skipOnError' => true, 'targetClass' => OrdersLabel::className(), 'targetAttribute' => ['orders_label_id' => 'id']], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'orders_label_id' => Yii::t('app', 'Orders Label ID'), - 'language_id' => Yii::t('app', 'Language ID'), - 'name' => Yii::t('app', 'Name'), - ]; - } - - /** - * @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_label_lang". + * @property integer $orders_label_id + * @property integer $language_id + * @property string $name + * @property Language $language + * @property Label $label */ - public function getLabel() + class OrdersLabelLang extends ActiveRecord { - return $this->hasOne(Label::className(), ['id' => 'orders_label_id']); + + public static function primaryKey() + { + return [ + 'orders_label_id', + 'language_id', + ]; + } + + /** + * @inheritdoc + */ + public static function tableName() + { + return 'orders_label_lang'; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'name' ], + 'required', + ], + [ + [ 'name' ], + 'string', + 'max' => 255, + ], + [ + [ + 'orders_label_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'orders_label_id', + 'language_id', + ], + 'message' => 'The combination of Orders Label ID and Language ID has already been taken.', + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'language_id' ], + ], + [ + [ 'orders_label_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Label::className(), + 'targetAttribute' => [ 'orders_label_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'orders_label_id' => Yii::t('app', 'Orders Label ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'language_id' => 'language_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLabel() + { + return $this->hasOne(Label::className(), [ 'id' => 'orders_label_id' ]); + } } -} diff --git a/backend/views/label/_form.php b/backend/views/label/_form.php new file mode 100644 index 0000000..d15ad5f --- /dev/null +++ b/backend/views/label/_form.php @@ -0,0 +1,36 @@ + + +
+ + + + field($model, 'label')->textInput(['maxlength' => true]) ?> + + $model_langs, + 'formView' => '@backend/views/label/_form_language', + 'form' => $form, + ]) ?> + +
+ isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/label/_form_language.php b/backend/views/label/_form_language.php new file mode 100755 index 0000000..d5388b1 --- /dev/null +++ b/backend/views/label/_form_language.php @@ -0,0 +1,15 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> diff --git a/backend/views/label/_search.php b/backend/views/label/_search.php new file mode 100644 index 0000000..b989f4f --- /dev/null +++ b/backend/views/label/_search.php @@ -0,0 +1,29 @@ + + + diff --git a/backend/views/label/create.php b/backend/views/label/create.php new file mode 100644 index 0000000..19360d8 --- /dev/null +++ b/backend/views/label/create.php @@ -0,0 +1,27 @@ +title = 'Create Label'; +$this->params['breadcrumbs'][] = ['label' => 'Labels', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]) ?> + +
diff --git a/backend/views/label/index.php b/backend/views/label/index.php new file mode 100644 index 0000000..2fe14db --- /dev/null +++ b/backend/views/label/index.php @@ -0,0 +1,39 @@ +title = 'Labels'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success' ]) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + 'id', + 'label', + [ + 'attribute' => 'name', + 'value' => 'lang.name', + ], + [ 'class' => 'yii\grid\ActionColumn' ], + ], + ]); ?> +
diff --git a/backend/views/label/update.php b/backend/views/label/update.php new file mode 100644 index 0000000..5976b0d --- /dev/null +++ b/backend/views/label/update.php @@ -0,0 +1,37 @@ +title = 'Update Label: ' . $model->lang->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Labels', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->lang->name, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]) ?> + +
diff --git a/backend/views/label/view.php b/backend/views/label/view.php new file mode 100644 index 0000000..10f0e4f --- /dev/null +++ b/backend/views/label/view.php @@ -0,0 +1,53 @@ +title = $model->lang->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Labels', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id, + ], [ 'class' => 'btn btn-primary' ]) ?> + $model->id, + ], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'label', + [ + 'label' => 'Name', + 'value' => $model->lang->name, + ], + ], + ]) ?> + +
diff --git a/backend/views/layouts/main-sidebar.php b/backend/views/layouts/main-sidebar.php index c1a5c0e..4f41d2a 100755 --- a/backend/views/layouts/main-sidebar.php +++ b/backend/views/layouts/main-sidebar.php @@ -23,6 +23,7 @@ use yii\widgets\Menu; 'active' => preg_match('/^manage.*$/', $this->context->id) || preg_match('/^category.*$/', $this->context->id) || preg_match('/^delivery.*$/', $this->context->id) || + preg_match('/^label.*$/', $this->context->id) || preg_match('/^brand.*$/', $this->context->id) || preg_match('/^product-unit.*$/', $this->context->id) || preg_match('/^import.*$/', $this->context->id) || @@ -41,6 +42,11 @@ use yii\widgets\Menu; 'options' => ['class'=>\Yii::$app->user->can('delivery') ? '' :'hide'] ], [ + 'label' => 'Статус товара', + 'url' => ['/label'], + 'options' => ['class'=>\Yii::$app->user->can('label') ? '' :'hide'] + ], + [ 'label' => 'Категории', 'url' => ['/category'], 'options' => ['class'=>\Yii::$app->user->can('category') ? '' :'hide'], -- libgit2 0.21.4