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 @@ + + +
+ = Html::a('Create Label', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + 'id', + 'label', + [ + 'attribute' => 'name', + 'value' => 'lang.name', + ], + [ 'class' => 'yii\grid\ActionColumn' ], + ], + ]); ?> ++ = 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', + [ + 'label' => 'Name', + 'value' => $model->lang->name, + ], + ], + ]) ?> + +