diff --git a/controllers/BrandController.php b/controllers/BrandController.php new file mode 100755 index 0000000..2952bbf --- /dev/null +++ b/controllers/BrandController.php @@ -0,0 +1,172 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'actions' => [ + 'logout', + 'index', + 'create', + 'update', + 'view', + 'delete', + ], + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'logout' => [ 'post' ], + ], + ], + ]; + } + + /** + * Lists all Brand models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BrandSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Brand model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Brand model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Brand(); + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { + return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ + 'view', + 'id' => $model->id, + ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); + } + } + return $this->render('create', [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ]); + } + + /** + * Updates an existing Brand 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, + 'modelLangs' => $model->modelLangs, + ]); + } + + /** + * Deletes an existing Brand 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 Brand model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Brand the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Brand::find()->with('lang')->where(['id' => $id])->one() ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/controllers/CategoryController.php b/controllers/CategoryController.php new file mode 100755 index 0000000..34b97eb --- /dev/null +++ b/controllers/CategoryController.php @@ -0,0 +1,235 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'logout' => [ 'post' ], + ], + ], + ]; + } + + /** + * Lists all Category models. + * + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + return $this->render( + 'index', + [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ] + ); + } + + /** + * Displays a single Category model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + $model = $this->findModel($id); + $tree = $model->getParents() + ->with('lang') + ->all(); + return $this->render( + 'view', + [ + 'model' => $model, + 'tree' => $tree, + ] + ); + } + + /** + * Creates a new Category model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionCreate() + { + $model = new Category(); + $model->generateLangs(); + if ($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if ($model->save() && $model->transactionStatus) { + return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); + } + } + if (!empty( Yii::$app->request->queryParams[ 'parent' ] )) { + $model->parent_id = Yii::$app->request->queryParams[ 'parent' ]; + } + + $parents = ArrayHelper::map( + Category::find() + ->joinWith('lang') + ->asArray() + ->all(), + 'id', + 'lang.title' + ); + + return $this->render( + 'create', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + 'categories' => ArtboxTreeHelper::treeMap( + Category::find() + ->getTree(), + 'id', + 'id', + '.' + ), + 'parents' => $parents, + ] + ); + } + + /** + * Updates an existing Category 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, + ] + ); + } + } + + $parents = ArrayHelper::map( + Category::find() + ->joinWith('lang') + ->where( + [ + '!=', + 'id', + $model->id, + ] + ) + ->asArray() + ->all(), + 'id', + 'lang.title' + ); + + return $this->render( + 'update', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + 'categories' => ArtboxTreeHelper::treeMap( + Category::find() + ->getTree(), + 'id', + 'id', + '.' + ), + 'parents' => $parents, + ] + ); + } + + /** + * Deletes an existing Category 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 Category model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Category the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (( $model = Category::find() + ->where([ 'id' => $id ]) + ->with('lang') + ->one() ) !== NULL + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/controllers/DeliveryController.php b/controllers/DeliveryController.php new file mode 100755 index 0000000..ddf3668 --- /dev/null +++ b/controllers/DeliveryController.php @@ -0,0 +1,164 @@ + [ + '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->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } + } + return $this->render('create', [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + '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, + 'modelLangs' => $model->modelLangs, + '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/controllers/LabelController.php b/controllers/LabelController.php new file mode 100755 index 0000000..ad9880e --- /dev/null +++ b/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, + 'modelLangs' => $model->modelLangs, + ]); + + } + + /** + * 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, + 'modelLangs' => $model->modelLangs, + ]); + + } + + /** + * 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/models/Label.php b/models/Label.php new file mode 100755 index 0000000..bd2128d --- /dev/null +++ b/models/Label.php @@ -0,0 +1,65 @@ + [ + 'class' => LanguageBehavior::className(), + 'objectLang' => OrderLabelLang::className(), + 'ownerKey' => 'id', + 'langKey' => 'order_label_id', + ], + ]; + } + } diff --git a/models/LabelSearch.php b/models/LabelSearch.php new file mode 100755 index 0000000..0a10916 --- /dev/null +++ b/models/LabelSearch.php @@ -0,0 +1,110 @@ +joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'sort' => [ + 'attributes' => [ + 'id', + 'label', + 'title' => [ + 'asc' => [ 'order_label_lang.title' => SORT_ASC ], + 'desc' => [ 'order_label_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, + ] + ); + + $query->andFilterWhere( + [ + 'like', + 'label', + $this->label, + ] + ) + ->andFilterWhere( + [ + 'like', + 'order_label_lang.title', + $this->title, + ] + ); + + return $dataProvider; + } + } diff --git a/models/OrderLabelLang.php b/models/OrderLabelLang.php new file mode 100755 index 0000000..0ebdc99 --- /dev/null +++ b/models/OrderLabelLang.php @@ -0,0 +1,108 @@ + 255, + ], + [ + [ + 'order_label_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'order_label_id', + 'language_id', + ], + 'message' => 'The combination of order Label ID and Language ID has already been taken.', + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'id' ], + ], + [ + [ 'order_label_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Label::className(), + 'targetAttribute' => [ 'order_label_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'order_label_id' => Yii::t('app', 'order Label ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'title' => Yii::t('app', 'Name'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLabel() + { + return $this->hasOne(Label::className(), [ 'id' => 'order_label_id' ]); + } + } diff --git a/views/brand/_form.php b/views/brand/_form.php new file mode 100755 index 0000000..d7ba90e --- /dev/null +++ b/views/brand/_form.php @@ -0,0 +1,66 @@ + + +
+ = Html::a(Yii::t('product', 'Create Brand'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + 'id', + [ + 'attribute' => 'brandName', + 'value' => 'lang.title', + ], + 'imageUrl:image', + [ + 'attribute' => 'in_menu', + 'content' => function($model) { + /** + * @var Brand $model + */ + return Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-'.($model->in_menu?'ok':'remove'), + ]); + }, + ], + [ 'class' => 'yii\grid\ActionColumn', + ], + ], + ]); ?> ++ = Html::a(Yii::t('product', 'Update'), [ + 'update', + 'id' => $model->id, + ], [ 'class' => 'btn btn-primary' ]) ?> + = Html::a(Yii::t('product', 'Delete'), [ + 'delete', + 'id' => $model->id, + ], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'lang.title', + 'lang.alias', + [ + 'attribute' => 'in_menu', + 'value' => Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-' . ( $model->in_menu ? 'ok' : 'remove' ), + ]), + 'format' => 'html', + ], + 'imageUrl:image', + 'lang.meta_title', + 'lang.meta_robots', + 'lang.meta_description', + 'lang.seo_text', + ], + ]) ?> + ++ = Html::a(Yii::t('product', 'Create Category'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + [ 'class' => 'yii\grid\SerialColumn' ], + 'id', + [ + 'attribute' => 'categoryName', + 'content' => function($data) { + /** + * @var Category $data + */ + $op = []; + foreach($data->getParents()->with('lang') + ->all() as $parent) { + $op[] = $parent->lang->title; + } + $op[] = $data->lang->title; + return implode(' → ', $op); + }, + ], + 'imageUrl:image', + [ + 'class' => 'yii\grid\ActionColumn', + ], + ], + 'panel' => [ + 'type' => 'success', + ], + ]); ?> ++ = Html::a(Yii::t('product', 'Update'), [ + 'update', + 'id' => $model->id, + ], [ 'class' => 'btn btn-primary' ]) ?> + = Html::a(Yii::t('product', 'Delete'), [ + 'delete', + 'id' => $model->id, + ], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> + = Html::a(Yii::t('product', 'Create Category'), [ 'category/create' ], [ 'class' => 'btn btn-success' ]) ?> + parent_id )) { + echo Html::a(Yii::t('product', 'Create category By {title}', [ 'title' => $model->parent->lang->title ]), [ 'category/create?parent=' . $model->parent->id ], [ 'class' => 'btn btn-success' ]); + } + ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + [ + 'label' => \Yii::t('product', 'Category tree'), + 'value' => $tree_string, + 'format' => 'html', + ], + 'imageUrl:image', + 'lang.alias', + 'lang.meta_title', + 'lang.meta_robots', + 'lang.meta_description', + 'lang.seo_text', + 'lang.h1', + ], + ]) ?> + ++ = Html::a('Create Delivery', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + + 'id', + [ + 'attribute' => 'title', + 'value' => 'lang.title', + ], + [ + 'attribute' => 'parentTitle', + 'value' => 'parent.lang.title', + ], + 'value', + [ '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' => 'Вид доставки', + 'value' => $parent_link, + 'format' => 'html', + ], + 'lang.title', + 'lang.text', + 'value', + 'sort', + ], + ]) ?> + ++ = Html::a('Create Label', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + 'id', + 'label', + [ + 'attribute' => 'title', + 'value' => 'lang.title', + ], + [ '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->title, + ], + ], + ]) ?> + +