From 20cfd47674475e084087fe70b9814d0f51675368 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 21 Dec 2016 19:19:25 +0200 Subject: [PATCH] -Sizes in process --- controllers/BrandController.php | 32 +++++++++++++++++++++++++++++--- controllers/BrandSizeController.php | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------- models/BrandSize.php | 4 ++-- views/brand-size/_form.php | 26 +++++++++++++++++++++----- views/brand-size/create.php | 43 ++++++++++++++++++++++++++++--------------- views/brand-size/update.php | 58 +++++++++++++++++++++++++++++++++++++++++----------------- views/brand-size/view.php | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- views/brand/size.php | 40 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 413 insertions(+), 186 deletions(-) create mode 100755 views/brand/size.php diff --git a/controllers/BrandController.php b/controllers/BrandController.php index fefa714..f411692 100755 --- a/controllers/BrandController.php +++ b/controllers/BrandController.php @@ -2,9 +2,11 @@ namespace artweb\artbox\ecommerce\controllers; + use artweb\artbox\ecommerce\models\BrandSize; use Yii; use artweb\artbox\ecommerce\models\Brand; use artweb\artbox\ecommerce\models\BrandSearch; + use yii\data\ActiveDataProvider; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -172,11 +174,35 @@ return $this->redirect([ 'index' ]); } + public function actionSize($id) + { + $model = $this->findModel($id); + + $dataProvider = new ActiveDataProvider( + [ + 'query' => BrandSize::find() + ->where( + [ + 'brand_id' => $id, + ] + ), + ] + ); + + return $this->render( + 'size', + [ + 'model' => $model, + 'dataProvider' => $dataProvider, + ] + ); + } + public function actionDeleteImage($id) { $model = $this->findModel($id); - $model->image = null; - $model->updateAttributes(['image']); + $model->image = NULL; + $model->updateAttributes([ 'image' ]); return true; } @@ -194,7 +220,7 @@ if (( $model = Brand::find() ->with('lang') ->where([ 'id' => $id ]) - ->one() ) !== null + ->one() ) !== NULL ) { return $model; } else { diff --git a/controllers/BrandSizeController.php b/controllers/BrandSizeController.php index f4596f1..0e6edb4 100755 --- a/controllers/BrandSizeController.php +++ b/controllers/BrandSizeController.php @@ -1,124 +1,209 @@ [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], ], - ], - ]; - } - - /** - * Lists all BrandSize models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new BrandSizeSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single BrandSize model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new BrandSize model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new BrandSize(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } else { - return $this->render('create', [ - 'model' => $model, - ]); + ]; } - } - - /** - * Updates an existing BrandSize 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); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } else { - return $this->render('update', [ - 'model' => $model, - ]); + + /** + * Lists all BrandSize models. + * + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BrandSizeSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render( + 'index', + [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ] + ); } - } - - /** - * Deletes an existing BrandSize 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 BrandSize model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return BrandSize the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = BrandSize::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Displays a single BrandSize model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render( + 'view', + [ + 'model' => $this->findModel($id), + ] + ); + } + + /** + * Creates a new BrandSize model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionCreate() + { + $model = new BrandSize(); + + $categories = ArrayHelper::map( + Category::find() + ->with('lang') + ->asArray() + ->all(), + 'id', + 'lang.title' + ); + + $brands = ArrayHelper::map( + Brand::find() + ->with('lang') + ->asArray() + ->all(), + '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, + 'categories' => $categories, + 'brands' => $brands, + ] + ); + } + } + + /** + * Updates an existing BrandSize 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); + + $categories = ArrayHelper::map( + Category::find() + ->with('lang') + ->asArray() + ->all(), + 'id', + 'lang.title' + ); + + $brands = ArrayHelper::map( + Brand::find() + ->with('lang') + ->asArray() + ->all(), + 'id', + 'lang.title' + ); + + if (!empty(\Yii::$app->request->post('BrandSize')[ 'categories' ])) { + $model->unlinkAll('categories', true); + foreach (\Yii::$app->request->post('BrandSize')[ 'categories' ] as $item) { + if ($category = Category::findOne($item)) { + $model->link('categories', $category); + } + } + } + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } else { + return $this->render( + 'update', + [ + 'model' => $model, + 'categories' => $categories, + 'brands' => $brands, + ] + ); + } + } + + /** + * Deletes an existing BrandSize 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 BrandSize model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return BrandSize the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (( $model = BrandSize::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/models/BrandSize.php b/models/BrandSize.php index a87854a..d13a07e 100755 --- a/models/BrandSize.php +++ b/models/BrandSize.php @@ -59,8 +59,8 @@ class BrandSize extends \yii\db\ActiveRecord { return [ 'id' => Yii::t('app', 'ID'), - 'brand_id' => Yii::t('app', 'Brand ID'), - 'image' => Yii::t('app', 'Image'), + 'brand_id' => Yii::t('app', 'Брэнд'), + 'image' => Yii::t('app', 'Сетка'), ]; } diff --git a/views/brand-size/_form.php b/views/brand-size/_form.php index 9eb062c..dee388c 100755 --- a/views/brand-size/_form.php +++ b/views/brand-size/_form.php @@ -9,9 +9,11 @@ use artweb\artbox\components\artboximage\ArtboxImageHelper; /** - * @var View $this - * @var BrandSize $model + * @var View $this + * @var BrandSize $model * @var ActiveForm $form + * @var array $categories + * @var array $brands */ ?> @@ -20,7 +22,20 @@ field($model, 'brand_id') - ->textInput() ?> + ->widget( + Select2::className(), + [ + 'data' => $brands, + 'language' => 'ru', + 'options' => [ + 'placeholder' => Yii::t('product', 'Select categories'), + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowClear' => true, + ], + ] + ) ?> field($model, 'image') ->widget( @@ -65,7 +80,7 @@ ->widget( Select2::className(), [ - 'data' => [], + 'data' => $categories, 'language' => 'ru', 'options' => [ 'placeholder' => Yii::t('product', 'Select categories'), @@ -75,7 +90,8 @@ 'allowClear' => true, ], ] - )->label(\Yii::t('app', 'Категории')) ?> + ) + ->label(\Yii::t('app', 'Категории')) ?>
title = Yii::t('app', 'Create Brand Size'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Brand Sizes'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use artweb\artbox\ecommerce\models\BrandSize; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var BrandSize $model + * @var array $categories + * @var array $brands + */ + + $this->title = Yii::t('app', 'Create Brand Size'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Brand Sizes'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
-

title) ?>

- - render('_form', [ - 'model' => $model, - ]) ?> +

title) ?>

+ + render( + '_form', + [ + 'model' => $model, + 'categories' => $categories, + 'brands' => $brands, + ] + ) ?>
diff --git a/views/brand-size/update.php b/views/brand-size/update.php index 1031fe6..ce9c1c8 100755 --- a/views/brand-size/update.php +++ b/views/brand-size/update.php @@ -1,23 +1,47 @@ title = Yii::t('app', 'Update {modelClass}: ', [ - 'modelClass' => 'Brand Size', -]) . $model->id; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Brand Sizes'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; -$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); + + use artweb\artbox\ecommerce\models\BrandSize; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var BrandSize $model + * @var array $categories + * @var array $brands + */ + + $this->title = Yii::t( + 'app', + 'Update {modelClass}: ', + [ + 'modelClass' => 'Brand Size', + ] + ) . $model->id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Brand Sizes'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->id, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); ?>
-

title) ?>

- - render('_form', [ - 'model' => $model, - ]) ?> +

title) ?>

+ + render( + '_form', + [ + 'model' => $model, + 'categories' => $categories, + 'brands' => $brands, + ] + ) ?>
diff --git a/views/brand-size/view.php b/views/brand-size/view.php index 7fa427c..97de248 100755 --- a/views/brand-size/view.php +++ b/views/brand-size/view.php @@ -1,37 +1,60 @@ title = $model->id; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Brand Sizes'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use artweb\artbox\ecommerce\models\BrandSize; + use yii\helpers\Html; + use yii\web\View; + use yii\widgets\DetailView; + + /** + * @var View $this + * @var BrandSize $model + */ + + $this->title = $model->id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Brand Sizes'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
-

title) ?>

+

title) ?>

-

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

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

+ + $model, + 'attributes' => [ + 'id', + 'brand_id', + 'image', ], - ]) ?> -

- - $model, - 'attributes' => [ - 'id', - 'brand_id', - 'image', - ], - ]) ?> + ] + ) ?>
diff --git a/views/brand/size.php b/views/brand/size.php new file mode 100755 index 0000000..b73b770 --- /dev/null +++ b/views/brand/size.php @@ -0,0 +1,40 @@ +title = Yii::t('app', 'Brand Sizes'); + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

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

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

+ $dataProvider, + 'columns' => [ + [ 'class' => 'yii\grid\SerialColumn' ], + + 'id', + 'brand_id', + 'image', + + [ 'class' => 'yii\grid\ActionColumn' ], + ], + ] + ); ?> +
-- libgit2 0.21.4