Commit 0a6fda2435fdb3b9b5f776b60720aeb4790bfbb6
1 parent
8e73da4f
product admin views and controller
Showing
13 changed files
with
409 additions
and
10 deletions
Show diff stats
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace backend\controllers; | ||
| 4 | + | ||
| 5 | +use common\models\Product; | ||
| 6 | +use common\models\ProductSearch; | ||
| 7 | +use Yii; | ||
| 8 | +use yii\web\Controller; | ||
| 9 | +use yii\web\NotFoundHttpException; | ||
| 10 | + | ||
| 11 | +class ProductController extends Controller | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * Lists all Tile models. | ||
| 15 | + * @return mixed | ||
| 16 | + */ | ||
| 17 | + public function actionIndex() | ||
| 18 | + { | ||
| 19 | + $searchModel = new ProductSearch(); | ||
| 20 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
| 21 | + | ||
| 22 | + return $this->render('index', [ | ||
| 23 | + 'searchModel' => $searchModel, | ||
| 24 | + 'dataProvider' => $dataProvider, | ||
| 25 | + ]); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * Creates a new Tile model. | ||
| 30 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
| 31 | + * @return mixed | ||
| 32 | + */ | ||
| 33 | + public function actionCreate() | ||
| 34 | + { | ||
| 35 | + $model = new Product(); | ||
| 36 | + $model->generateLangs(); | ||
| 37 | + | ||
| 38 | + if ($model->loadWithLangs(\Yii::$app->request)) { | ||
| 39 | + if ($model->saveWithLangs()) { | ||
| 40 | + return $this->redirect( | ||
| 41 | + [ | ||
| 42 | + 'view', | ||
| 43 | + 'id' => $model->id, | ||
| 44 | + ] | ||
| 45 | + ); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + return $this->render( | ||
| 49 | + 'create', | ||
| 50 | + [ | ||
| 51 | + 'model' => $model, | ||
| 52 | + 'modelLangs' => $model->modelLangs, | ||
| 53 | + ] | ||
| 54 | + ); | ||
| 55 | + } | ||
| 56 | + public function actionView($id): string | ||
| 57 | + { | ||
| 58 | + return $this->render('view', [ | ||
| 59 | + 'model' => $this->findModel($id), | ||
| 60 | + ]); | ||
| 61 | + } | ||
| 62 | + public function actionDelete($id) | ||
| 63 | + { | ||
| 64 | + $this->findModel($id)->delete(); | ||
| 65 | + | ||
| 66 | + return $this->redirect(['index']); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + protected function findModel($id): Product | ||
| 70 | + { | ||
| 71 | + if (($model = Product::findOne($id)) !== null) { | ||
| 72 | + return $model; | ||
| 73 | + } else { | ||
| 74 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | +} | ||
| 0 | \ No newline at end of file | 78 | \ No newline at end of file |
backend/views/layouts/menu_items.php
| @@ -116,6 +116,11 @@ | @@ -116,6 +116,11 @@ | ||
| 116 | 'icon' => 'sun-o', | 116 | 'icon' => 'sun-o', |
| 117 | ], | 117 | ], |
| 118 | [ | 118 | [ |
| 119 | + 'label' => \Yii::t('core', 'Продукты'), | ||
| 120 | + 'url' => ['/product/index'], | ||
| 121 | + 'icon' => 'sun-o', | ||
| 122 | + ], | ||
| 123 | + [ | ||
| 119 | 'label' => \Yii::t('core', 'Комментарии'), | 124 | 'label' => \Yii::t('core', 'Комментарии'), |
| 120 | 'url' => ['/comment/index'], | 125 | 'url' => ['/comment/index'], |
| 121 | 'icon' => 'sun-o', | 126 | 'icon' => 'sun-o', |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use yii\helpers\Html; | ||
| 4 | + use yii\widgets\ActiveForm; | ||
| 5 | + use artbox\core\components\imagemanager\components\ImageManagerInputWidget; | ||
| 6 | + use artbox\core\widgets\LanguageForm; | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * @var \yii\web\View $this | ||
| 10 | + * @var \common\models\Objectkb $model | ||
| 11 | + * @var \common\models\ObjectkbLang[] $modelLangs | ||
| 12 | + * @var \common\models\Slider[] $sliders | ||
| 13 | + */ | ||
| 14 | +?> | ||
| 15 | + | ||
| 16 | +<div class="objectkb-form"> | ||
| 17 | + | ||
| 18 | + <?php | ||
| 19 | + $form = ActiveForm::begin(); | ||
| 20 | + ?> | ||
| 21 | + | ||
| 22 | + <?= LanguageForm::widget( | ||
| 23 | + [ | ||
| 24 | + 'modelLangs' => $modelLangs, | ||
| 25 | + 'formView' => '@backend/views/product/_form_language', | ||
| 26 | + 'form' => $form, | ||
| 27 | + ] | ||
| 28 | + ) ?> | ||
| 29 | + <?= $form->field($model, 'sku') | ||
| 30 | + ->textInput() ?> | ||
| 31 | + <?= $form->field($model, 'sort') | ||
| 32 | + ->textInput() ?> | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + <?= $form->field($model, 'image_id') | ||
| 36 | + ->widget( | ||
| 37 | + ImageManagerInputWidget::className(), | ||
| 38 | + [ | ||
| 39 | + 'aspectRatio' => ( 16 / 9 ), | ||
| 40 | + //set the aspect ratio | ||
| 41 | + 'showPreview' => true, | ||
| 42 | + //false to hide the preview | ||
| 43 | + 'showDeletePickedImageConfirm' => false, | ||
| 44 | + //on true show warning before detach image | ||
| 45 | + ] | ||
| 46 | + ) | ||
| 47 | + ?> | ||
| 48 | + | ||
| 49 | + <?= $form->field($model, 'status') | ||
| 50 | + ->checkbox() ?> | ||
| 51 | + | ||
| 52 | + <div class="form-group"> | ||
| 53 | + <?= Html::submitButton( | ||
| 54 | + $model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), | ||
| 55 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ||
| 56 | + ) ?> | ||
| 57 | + </div> | ||
| 58 | + | ||
| 59 | + <?php ActiveForm::end(); ?> | ||
| 60 | + | ||
| 61 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use artbox\core\models\Language; | ||
| 4 | +use yii\web\View; | ||
| 5 | +use yii\widgets\ActiveForm; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @var \artbox\core\models\SlideLang $model_lang | ||
| 9 | + * @var Language $language | ||
| 10 | + * @var ActiveForm $form | ||
| 11 | + * @var View $this | ||
| 12 | + */ | ||
| 13 | + | ||
| 14 | +$attributeField = $form->field($model_lang, '[' . $language->id . ']title') | ||
| 15 | + ->textInput(['maxlength' => true]); | ||
| 16 | + | ||
| 17 | +echo $attributeField; | ||
| 18 | +$attributeField2 = $form->field($model_lang, '[' . $language->id . ']link') | ||
| 19 | + ->textInput(['maxlength' => true]); | ||
| 20 | + | ||
| 21 | +echo $attributeField2; | ||
| 22 | + | ||
| 23 | +?> | ||
| 0 | \ No newline at end of file | 24 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\helpers\Html; | ||
| 4 | +use yii\widgets\ActiveForm; | ||
| 5 | + | ||
| 6 | +/* @var $this yii\web\View */ | ||
| 7 | +/* @var $model common\models\ProductSearch */ | ||
| 8 | +/* @var $form yii\widgets\ActiveForm */ | ||
| 9 | +?> | ||
| 10 | + | ||
| 11 | +<div class="objectkb-search"> | ||
| 12 | + | ||
| 13 | + <?php $form = ActiveForm::begin([ | ||
| 14 | + 'action' => ['index'], | ||
| 15 | + 'method' => 'get', | ||
| 16 | + ]); ?> | ||
| 17 | + | ||
| 18 | + <?= $form->field($model, 'id') ?> | ||
| 19 | + | ||
| 20 | + <?= $form->field($model, 'sku') ?> | ||
| 21 | + | ||
| 22 | + <?= $form->field($model, 'status')->checkbox() ?> | ||
| 23 | + | ||
| 24 | + <?= $form->field($model, 'sort') ?> | ||
| 25 | + | ||
| 26 | + <?= $form->field($model, 'image_id') ?> | ||
| 27 | + | ||
| 28 | + <div class="form-group"> | ||
| 29 | + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | ||
| 30 | + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | ||
| 31 | + </div> | ||
| 32 | + | ||
| 33 | + <?php ActiveForm::end(); ?> | ||
| 34 | + | ||
| 35 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\helpers\Html; | ||
| 4 | + | ||
| 5 | + /** | ||
| 6 | + * @var \yii\web\View $this | ||
| 7 | + * @var \common\models\Objectkb $model | ||
| 8 | + * @var \common\models\ObjectkbLang $modelLangs | ||
| 9 | + * @var \common\models\Slider[] $sliders | ||
| 10 | + */ | ||
| 11 | +$this->title = Yii::t('app', 'Create Product'); | ||
| 12 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Products'), 'url' => ['index']]; | ||
| 13 | +$this->params['breadcrumbs'][] = $this->title; | ||
| 14 | +?> | ||
| 15 | +<div class="objectkb-create"> | ||
| 16 | + | ||
| 17 | + <h1><?= Html::encode($this->title) ?></h1> | ||
| 18 | + | ||
| 19 | + <?= $this->render('_form', [ | ||
| 20 | + 'model' => $model, | ||
| 21 | + 'modelLangs' => $modelLangs, | ||
| 22 | + ]) ?> | ||
| 23 | + | ||
| 24 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\helpers\Html; | ||
| 4 | +use yii\grid\GridView; | ||
| 5 | +use yii\widgets\Pjax; | ||
| 6 | +/* @var $this yii\web\View */ | ||
| 7 | +/* @var $searchModel common\models\Product */ | ||
| 8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | ||
| 9 | + | ||
| 10 | +$this->title = Yii::t('app', 'Products'); | ||
| 11 | +$this->params['breadcrumbs'][] = $this->title; | ||
| 12 | +?> | ||
| 13 | +<div class="objectkb-index"> | ||
| 14 | + | ||
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | ||
| 16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | ||
| 17 | + | ||
| 18 | + <p> | ||
| 19 | + <?= Html::a(Yii::t('app', 'Create Product'), ['create'], ['class' => 'btn btn-success']) ?> | ||
| 20 | + </p> | ||
| 21 | +<?php Pjax::begin(); ?> <?= GridView::widget([ | ||
| 22 | + 'dataProvider' => $dataProvider, | ||
| 23 | + 'filterModel' => $searchModel, | ||
| 24 | + 'columns' => [ | ||
| 25 | + ['class' => 'yii\grid\SerialColumn'], | ||
| 26 | + | ||
| 27 | + 'id', | ||
| 28 | + 'sku', | ||
| 29 | + 'status:boolean', | ||
| 30 | + 'sort', | ||
| 31 | + 'image_id', | ||
| 32 | + | ||
| 33 | + ['class' => 'yii\grid\ActionColumn'], | ||
| 34 | + ], | ||
| 35 | + ]); ?> | ||
| 36 | +<?php Pjax::end(); ?></div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\helpers\Html; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @var $this yii\web\View | ||
| 7 | + * @var $model common\models\Product | ||
| 8 | + * @var \common\models\ProductLang $modelLangs | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +$this->title = Yii::t('app', 'Update {modelClass}: ', [ | ||
| 12 | + 'modelClass' => 'Product', | ||
| 13 | +]) . $model->id; | ||
| 14 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Products'), 'url' => ['index']]; | ||
| 15 | +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; | ||
| 16 | +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | ||
| 17 | +?> | ||
| 18 | +<div class="objectkb-update"> | ||
| 19 | + | ||
| 20 | + <h1><?= Html::encode($this->title) ?></h1> | ||
| 21 | + | ||
| 22 | + <?= $this->render('_form', [ | ||
| 23 | + 'model' => $model, | ||
| 24 | + 'modelLangs' => $modelLangs, | ||
| 25 | + ]) ?> | ||
| 26 | + | ||
| 27 | +</div> |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\helpers\Html; | ||
| 4 | +use yii\widgets\DetailView; | ||
| 5 | + | ||
| 6 | +/* @var $this yii\web\View */ | ||
| 7 | +/* @var $model common\models\Product */ | ||
| 8 | + | ||
| 9 | +$this->title = $model->id; | ||
| 10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Products'), 'url' => ['index']]; | ||
| 11 | +$this->params['breadcrumbs'][] = $this->title; | ||
| 12 | +?> | ||
| 13 | +<div class="objectkb-view"> | ||
| 14 | + | ||
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | ||
| 16 | + | ||
| 17 | + <p> | ||
| 18 | + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | ||
| 19 | + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ | ||
| 20 | + 'class' => 'btn btn-danger', | ||
| 21 | + 'data' => [ | ||
| 22 | + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), | ||
| 23 | + 'method' => 'post', | ||
| 24 | + ], | ||
| 25 | + ]) ?> | ||
| 26 | + </p> | ||
| 27 | + | ||
| 28 | + <?= DetailView::widget([ | ||
| 29 | + 'model' => $model, | ||
| 30 | + 'attributes' => [ | ||
| 31 | + 'id', | ||
| 32 | + 'sku', | ||
| 33 | + 'status:boolean', | ||
| 34 | + 'sort', | ||
| 35 | + 'image_id', | ||
| 36 | + ], | ||
| 37 | + ]) ?> | ||
| 38 | + | ||
| 39 | +</div> |
backend/views/tile/_search.php
| @@ -4,7 +4,7 @@ use yii\helpers\Html; | @@ -4,7 +4,7 @@ use yii\helpers\Html; | ||
| 4 | use yii\widgets\ActiveForm; | 4 | use yii\widgets\ActiveForm; |
| 5 | 5 | ||
| 6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
| 7 | -/* @var $model common\models\ObjectkbSearch */ | 7 | +/* @var $model common\models\TileSearch */ |
| 8 | /* @var $form yii\widgets\ActiveForm */ | 8 | /* @var $form yii\widgets\ActiveForm */ |
| 9 | ?> | 9 | ?> |
| 10 | 10 | ||
| @@ -17,13 +17,11 @@ use yii\widgets\ActiveForm; | @@ -17,13 +17,11 @@ use yii\widgets\ActiveForm; | ||
| 17 | 17 | ||
| 18 | <?= $form->field($model, 'id') ?> | 18 | <?= $form->field($model, 'id') ?> |
| 19 | 19 | ||
| 20 | - <?= $form->field($model, 'slider_id') ?> | ||
| 21 | - | ||
| 22 | <?= $form->field($model, 'status')->checkbox() ?> | 20 | <?= $form->field($model, 'status')->checkbox() ?> |
| 23 | 21 | ||
| 24 | <?= $form->field($model, 'sort') ?> | 22 | <?= $form->field($model, 'sort') ?> |
| 25 | 23 | ||
| 26 | - <?= $form->field($model, 'image_mini_id') ?> | 24 | + <?= $form->field($model, 'image_id') ?> |
| 27 | 25 | ||
| 28 | <div class="form-group"> | 26 | <div class="form-group"> |
| 29 | <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | 27 | <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> |
backend/views/tile/update.php
| @@ -4,15 +4,15 @@ use yii\helpers\Html; | @@ -4,15 +4,15 @@ use yii\helpers\Html; | ||
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * @var $this yii\web\View | 6 | * @var $this yii\web\View |
| 7 | - * @var $model common\models\Objectkb | ||
| 8 | - * @var \common\models\ObjectkbLang $modelLangs | 7 | + * @var $model common\models\Tile |
| 8 | + * @var \common\models\TileLang $modelLangs | ||
| 9 | * @var \common\models\Slider[] $sliders | 9 | * @var \common\models\Slider[] $sliders |
| 10 | */ | 10 | */ |
| 11 | 11 | ||
| 12 | $this->title = Yii::t('app', 'Update {modelClass}: ', [ | 12 | $this->title = Yii::t('app', 'Update {modelClass}: ', [ |
| 13 | - 'modelClass' => 'Objectkb', | 13 | + 'modelClass' => 'Tile', |
| 14 | ]) . $model->id; | 14 | ]) . $model->id; |
| 15 | -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Objectkbs'), 'url' => ['index']]; | 15 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Tiles'), 'url' => ['index']]; |
| 16 | $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; | 16 | $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; |
| 17 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | 17 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); |
| 18 | ?> | 18 | ?> |
| @@ -23,7 +23,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | @@ -23,7 +23,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | ||
| 23 | <?= $this->render('_form', [ | 23 | <?= $this->render('_form', [ |
| 24 | 'model' => $model, | 24 | 'model' => $model, |
| 25 | 'modelLangs' => $modelLangs, | 25 | 'modelLangs' => $modelLangs, |
| 26 | - 'sliders' => $sliders, | 26 | + //'sliders' => $sliders, |
| 27 | ]) ?> | 27 | ]) ?> |
| 28 | 28 | ||
| 29 | </div> | 29 | </div> |
backend/views/tile/view.php
| @@ -32,7 +32,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -32,7 +32,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
| 32 | 'slider_id', | 32 | 'slider_id', |
| 33 | 'status:boolean', | 33 | 'status:boolean', |
| 34 | 'sort', | 34 | 'sort', |
| 35 | - 'image_mini_id', | 35 | + 'image_id', |
| 36 | ], | 36 | ], |
| 37 | ]) ?> | 37 | ]) ?> |
| 38 | 38 |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace common\models; | ||
| 4 | + | ||
| 5 | +use yii\base\Model; | ||
| 6 | +use yii\data\ActiveDataProvider; | ||
| 7 | + | ||
| 8 | +class ProductSearch extends Product | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * @inheritdoc | ||
| 12 | + */ | ||
| 13 | + public function rules() | ||
| 14 | + { | ||
| 15 | + return [ | ||
| 16 | + [['id', 'sort', 'image_id'], 'integer'], | ||
| 17 | + [['status'], 'boolean'], | ||
| 18 | + [['sku'], 'string'], | ||
| 19 | + ]; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * @inheritdoc | ||
| 24 | + */ | ||
| 25 | + public function scenarios() | ||
| 26 | + { | ||
| 27 | + // bypass scenarios() implementation in the parent class | ||
| 28 | + return Model::scenarios(); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public function behaviors() | ||
| 32 | + { | ||
| 33 | + return []; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Creates data provider instance with search query applied | ||
| 38 | + * | ||
| 39 | + * @param array $params | ||
| 40 | + * | ||
| 41 | + * @return ActiveDataProvider | ||
| 42 | + */ | ||
| 43 | + public function search($params) | ||
| 44 | + { | ||
| 45 | + $query = Product::find(); | ||
| 46 | + | ||
| 47 | + // add conditions that should always apply here | ||
| 48 | + | ||
| 49 | + $dataProvider = new ActiveDataProvider([ | ||
| 50 | + 'query' => $query, | ||
| 51 | + ]); | ||
| 52 | + | ||
| 53 | + $this->load($params); | ||
| 54 | + | ||
| 55 | + if (!$this->validate()) { | ||
| 56 | + // uncomment the following line if you do not want to return any records when validation fails | ||
| 57 | + // $query->where('0=1'); | ||
| 58 | + return $dataProvider; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + // grid filtering conditions | ||
| 62 | + $query->andFilterWhere( | ||
| 63 | + [ | ||
| 64 | + 'id' => $this->id, | ||
| 65 | + 'status' => $this->status, | ||
| 66 | + 'sort' => $this->sort, | ||
| 67 | + 'image_id' => $this->image_id, | ||
| 68 | + 'sku'=>$this->sku, | ||
| 69 | + ] | ||
| 70 | + ); | ||
| 71 | + | ||
| 72 | + return $dataProvider; | ||
| 73 | + } | ||
| 74 | +} | ||
| 0 | \ No newline at end of file | 75 | \ No newline at end of file |