diff --git a/backend/config/main.php b/backend/config/main.php index 34090c5..2f069e2 100644 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -27,14 +27,26 @@ 'components' => [ 'assetManager' => [ 'bundles' => [ - 'yiister\gentelella\assets\ThemeAsset' => [ - 'basePath' => '@webroot', - 'baseUrl' => '@web', +// 'yiister\gentelella\assets\ThemeAsset' => [ +// 'basePath' => '@webroot', +// 'baseUrl' => '@web', +// 'js' => [ +// 'js/custom.js', +// ], +// 'css' => [ +// 'css/custom.css', +// ], +// ], + 'yiister\gentelella\assets\ThemeSrcAsset' => [ + 'sourcePath' => null, // не опубликовывать комплект 'js' => [ - 'js/custom.js', + 'admin/js/custom.js', ], - 'css' => [ - 'css/custom.css', + ], + 'yiister\gentelella\assets\ThemeBuildAsset'=> [ + 'sourcePath' => null, // не опубликовывать комплект + 'css' => [ + 'admin/css/custom.css', ], ], ], diff --git a/backend/controllers/SlideController.php b/backend/controllers/SlideController.php new file mode 100644 index 0000000..34afb72 --- /dev/null +++ b/backend/controllers/SlideController.php @@ -0,0 +1,186 @@ +findSlider($slider_id); + $searchModel = new SlideSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $slider); + + return $this->render( + 'index', + [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'slider' => $slider, + ] + ); + } + + /** + * Displays a single Slide model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render( + 'view', + [ + 'model' => $this->findModel($id), + ] + ); + } + + /** + * Creates a new Slide model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @param int $slider_id + * + * @return mixed + */ + public function actionCreate(int $slider_id) + { + $slider = $this->findSlider($slider_id); + + $model = new Slide(); + $model->generateLangs(); + + if ($model->loadWithLangs(\Yii::$app->request)) { + if ($model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } + } + return $this->render( + 'create', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + 'slider' => $slider, + ] + ); + } + + /** + * Updates an existing Slide 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(); + + $slider = $this->findSlider($model->slider_id); + + if ($model->loadWithLangs(\Yii::$app->request)) { + if ($model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } + } + return $this->render( + 'update', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + 'slider' => $slider, + ] + ); + } + + /** + * Deletes an existing Slide model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + + $slider_id = $model->slider_id; + $model->delete(); + return $this->redirect( + [ + 'index', + 'slider_id' => $slider_id, + ] + ); + } + + /** + * Finds the Slide model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Slide the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (( $model = Slide::findOne($id) ) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + /** + * Finds the Slider model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Slider the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findSlider($id) + { + if (( $model = Slider::findOne($id) ) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } \ No newline at end of file diff --git a/backend/controllers/SliderController.php b/backend/controllers/SliderController.php new file mode 100644 index 0000000..8bb43c9 --- /dev/null +++ b/backend/controllers/SliderController.php @@ -0,0 +1,144 @@ +search(Yii::$app->request->queryParams); + + return $this->render( + 'index', + [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ] + ); + } + + /** + * Displays a single Slider model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render( + 'view', + [ + 'model' => $this->findModel($id), + ] + ); + } + + /** + * Creates a new Slider model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionCreate() + { + $model = new Slider(); + + 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 Slider 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, + ] + ); + } + } + + /** + * Deletes an existing Slider 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 Slider model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Slider the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (( $model = Slider::findOne($id) ) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } \ No newline at end of file diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php index 6850801..4c8c87f 100644 --- a/backend/views/layouts/menu_items.php +++ b/backend/views/layouts/menu_items.php @@ -78,5 +78,10 @@ 'url' => [ '/imagemanager' ], 'icon' => 'image', ], + [ + 'label' => \Yii::t('core', 'Slider'), + 'url' => ['/slider/index'], + 'icon' => 'bolt', + ], ] ); \ No newline at end of file diff --git a/backend/views/slide/_form.php b/backend/views/slide/_form.php new file mode 100755 index 0000000..d5deba2 --- /dev/null +++ b/backend/views/slide/_form.php @@ -0,0 +1,52 @@ + + +
+ + + + field($model, 'slider_id') + ->hiddenInput([ 'value' => $slider->id ]) + ->label(false) ?> + + $modelLangs, + 'formView' => '@artbox/core/views/slide/_form_language', + 'form' => $form, + ] + ) ?> + + field($model, 'status') + ->checkbox( + [ + 'class' => 'flat', + ] + ) ?> + + field($model, 'sort') + ->input('number') ?> + +
+ isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + ) ?> +
+ + + +
diff --git a/backend/views/slide/_form_language.php b/backend/views/slide/_form_language.php new file mode 100755 index 0000000..0e8c46c --- /dev/null +++ b/backend/views/slide/_form_language.php @@ -0,0 +1,30 @@ +field($model_lang, '[' . $language->id . ']image_id') + ->widget( + ImageManagerInputWidget::className(), + [ + 'aspectRatio' => ( 16 / 9 ), + //set the aspect ratio + 'showPreview' => true, + //false to hide the preview + 'showDeletePickedImageConfirm' => false, + //on true show warning before detach image + ] + ); + echo $form->field($model_lang, '[' . $language->id . ']title') + ->textInput([ 'maxlength' => true ]); + echo $form->field($model_lang, '[' . $language->id . ']link') + ->textInput([ 'maxlength' => true ]); +?> \ No newline at end of file diff --git a/backend/views/slide/_search.php b/backend/views/slide/_search.php new file mode 100755 index 0000000..004b118 --- /dev/null +++ b/backend/views/slide/_search.php @@ -0,0 +1,37 @@ + + + diff --git a/backend/views/slide/create.php b/backend/views/slide/create.php new file mode 100755 index 0000000..b0a65b1 --- /dev/null +++ b/backend/views/slide/create.php @@ -0,0 +1,36 @@ +title = Yii::t('core', 'Create Slide'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('core', 'Slides'), + 'url' => [ + 'index', + 'slider_id' => $slider->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ + render( + '_form', + [ + 'model' => $model, + 'modelLangs' => $modelLangs, + 'slider' => $slider, + ] + ) ?> + +
diff --git a/backend/views/slide/index.php b/backend/views/slide/index.php new file mode 100755 index 0000000..6c35b5e --- /dev/null +++ b/backend/views/slide/index.php @@ -0,0 +1,60 @@ +title = Yii::t('core', 'Slides'); + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

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

+ $slider->id, + ], + [ 'class' => 'btn btn-success' ] + ) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + [ 'class' => 'yii\grid\SerialColumn' ], + + 'id', + [ + 'attribute' => 'image_id', + 'value' => function (\artbox\core\models\Slide $model) { + if (empty($model->lang->image)) { + return ''; + } else { + return Html::img( + $model->lang->image->getUrl(), + [ + 'width' => '400px', + ] + ); + } + }, + 'format' => 'html', + ], + 'status:boolean', + 'sort', + + [ 'class' => 'yii\grid\ActionColumn' ], + ], + ] + ); ?> +
diff --git a/backend/views/slide/update.php b/backend/views/slide/update.php new file mode 100755 index 0000000..a889880 --- /dev/null +++ b/backend/views/slide/update.php @@ -0,0 +1,49 @@ +title = Yii::t( + 'core', + 'Update {modelClass}: ', + [ + 'modelClass' => 'Slide', + ] + ) . $model->id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('core', 'Slides'), + 'url' => [ + 'index', + 'slider_id' => $slider->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->id, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); +?> +
+ +

title) ?>

+ + render( + '_form', + [ + 'model' => $model, + 'modelLangs' => $modelLangs, + 'slider' => $slider, + ] + ) ?> + +
diff --git a/backend/views/slide/view.php b/backend/views/slide/view.php new file mode 100755 index 0000000..bfc20f4 --- /dev/null +++ b/backend/views/slide/view.php @@ -0,0 +1,61 @@ +title = $model->id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('core', 'Slides'), + 'url' => [ + 'index', + 'slider_id' => $model->slider_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ +

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

+ + $model, + 'attributes' => [ + 'id', + 'slider_id', + 'status:boolean', + 'sort', + ], + ] + ) ?> + +
diff --git a/backend/views/slider/_form.php b/backend/views/slider/_form.php new file mode 100755 index 0000000..2598ec8 --- /dev/null +++ b/backend/views/slider/_form.php @@ -0,0 +1,38 @@ + + +
+ + + + field($model, 'status') + ->checkbox([ + 'class' => 'flat', + ]) ?> + + field($model, 'sort') + ->input('number') ?> + + field($model, 'on_home_page') + ->checkbox([ + 'class' => 'flat', + ]) ?> + +
+ isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + ) ?> +
+ + + +
diff --git a/backend/views/slider/_search.php b/backend/views/slider/_search.php new file mode 100755 index 0000000..6242edc --- /dev/null +++ b/backend/views/slider/_search.php @@ -0,0 +1,35 @@ + + + diff --git a/backend/views/slider/create.php b/backend/views/slider/create.php new file mode 100755 index 0000000..e1c7385 --- /dev/null +++ b/backend/views/slider/create.php @@ -0,0 +1,27 @@ +title = Yii::t('core', 'Create Slider'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('core', 'Sliders'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ + render( + '_form', + [ + 'model' => $model, + ] + ) ?> + +
diff --git a/backend/views/slider/index.php b/backend/views/slider/index.php new file mode 100755 index 0000000..2efc8a6 --- /dev/null +++ b/backend/views/slider/index.php @@ -0,0 +1,68 @@ +title = Yii::t('core', 'Sliders'); + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

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

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

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + [ 'class' => 'yii\grid\SerialColumn' ], + + 'id', + 'status:boolean', + [ + 'attribute' => 'sort', + 'filter' => false, + ], + [ + 'class' => 'yii\grid\ActionColumn', + 'buttons' => [ + 'slides' => function ($url, $model, $key) { + /** + * @var \artbox\core\models\Slider $model + */ + return Html::a( + Html::tag( + 'i', + '', + [ + 'class' => 'glyphicon glyphicon-picture', + ] + ), + [ + 'slide/index', + 'slider_id' => $model->id, + ], + [ + 'title' => \Yii::t('core', 'Slides'), + 'data' => [ + 'pjax' => 0, + ], + ] + ); + }, + ], + 'template' => '{slides} {view} {update} {delete}', + ], + ], + ] + ); ?> +
diff --git a/backend/views/slider/update.php b/backend/views/slider/update.php new file mode 100755 index 0000000..2485a80 --- /dev/null +++ b/backend/views/slider/update.php @@ -0,0 +1,40 @@ +title = Yii::t( + 'core', + 'Update {modelClass}: ', + [ + 'modelClass' => 'Slider', + ] + ) . $model->id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('core', 'Sliders'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->id, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); +?> +
+ +

title) ?>

+ + render( + '_form', + [ + 'model' => $model, + ] + ) ?> + +
diff --git a/backend/views/slider/view.php b/backend/views/slider/view.php new file mode 100755 index 0000000..310962d --- /dev/null +++ b/backend/views/slider/view.php @@ -0,0 +1,57 @@ +title = $model->id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('core', 'Sliders'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ +

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

+ + $model, + 'attributes' => [ + 'id', + 'status:boolean', + 'sort', + ], + ] + ) ?> + +
diff --git a/backend/web/assets/.gitignore b/backend/web/assets/.gitignore old mode 100644 new mode 100755 index d6b7ef3..d6b7ef3 --- a/backend/web/assets/.gitignore +++ b/backend/web/assets/.gitignore diff --git a/common/messages/ru/app.php b/common/messages/ru/app.php index bbdded7..dfbbce4 100644 --- a/common/messages/ru/app.php +++ b/common/messages/ru/app.php @@ -121,4 +121,5 @@ return [ 'sect3_21' => 'Обратиться к нам и', 'Office {office}' => 'Офис {office}', 'Contact us' => 'Связаться с нами', + "Show on home page" => "Показать на главной странице", ]; \ No newline at end of file diff --git a/common/models/Slide.php b/common/models/Slide.php new file mode 100755 index 0000000..2efd202 --- /dev/null +++ b/common/models/Slide.php @@ -0,0 +1,128 @@ + [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'slider_id' ], + 'required', + ], + [ + [ + 'slider_id', + 'sort', + ], + 'integer', + ], + [ + [ 'status' ], + 'boolean', + ], + [ + [ 'slider_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Slider::className(), + 'targetAttribute' => [ 'slider_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('core', 'ID'), + 'slider_id' => Yii::t('core', 'Slider ID'), + 'status' => Yii::t('core', 'Status'), + 'sort' => Yii::t('core', 'Sort'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSlider() + { + return $this->hasOne(Slider::className(), [ 'id' => 'slider_id' ]) + ->inverseOf('slides'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSlideLangs() + { + return $this->hasMany(SlideLang::className(), [ 'slide_id' => 'id' ]) + ->inverseOf('slide'); + } + } diff --git a/common/models/SlideLang.php b/common/models/SlideLang.php new file mode 100755 index 0000000..7eca1cc --- /dev/null +++ b/common/models/SlideLang.php @@ -0,0 +1,10 @@ +where([ 'slider_id' => $slider->id ]); + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + ] + ); + + $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, + 'slider_id' => $this->slider_id, + 'status' => $this->status, + 'sort' => $this->sort, + ] + ); + + return $dataProvider; + } + } diff --git a/common/models/Slider.php b/common/models/Slider.php new file mode 100755 index 0000000..24fa872 --- /dev/null +++ b/common/models/Slider.php @@ -0,0 +1,60 @@ + Yii::t('core', 'ID'), + 'status' => Yii::t('core', 'Status'), + 'sort' => Yii::t('core', 'Sort'), + 'on_home_page' => Yii::t('app', "Show on home page"), + ]; + } + +// /** +// * @return \yii\db\ActiveQuery +// */ +// public function getSlides() +// { +// return $this->hasMany(Slide::className(), [ 'slider_id' => 'id' ]) +// ->inverseOf('slider'); +// } + } diff --git a/common/models/SliderSearch.php b/common/models/SliderSearch.php new file mode 100755 index 0000000..d5ba080 --- /dev/null +++ b/common/models/SliderSearch.php @@ -0,0 +1,80 @@ + $query, + ] + ); + + $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, + 'status' => $this->status, + 'sort' => $this->sort, + ] + ); + + return $dataProvider; + } + } diff --git a/console/migrations/m180124_130301_add_on_home_page_column_to_slider_table.php b/console/migrations/m180124_130301_add_on_home_page_column_to_slider_table.php new file mode 100644 index 0000000..ce61da4 --- /dev/null +++ b/console/migrations/m180124_130301_add_on_home_page_column_to_slider_table.php @@ -0,0 +1,25 @@ +addColumn('slider', 'on_home_page', $this->boolean()); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropColumn('slider', 'on_home_page'); + } +} diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 28ee218..65daf75 100644 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -3,6 +3,7 @@ use artbox\core\models\Feedback; use common\models\Settings; + use common\models\Slider; use Yii; use yii\filters\VerbFilter; use yii\swiftmailer\Mailer; @@ -49,7 +50,16 @@ */ public function actionIndex() { - return $this->render('index'); + + $slider = Slider::find()->with("slides.lang.image") + ->where(['on_home_page'=>true])->one(); + + return $this->render( + 'index', + [ + 'slider' => $slider, + ] + ); } /** diff --git a/frontend/views/site/index.php b/frontend/views/site/index.php index 8783e45..213ace1 100644 --- a/frontend/views/site/index.php +++ b/frontend/views/site/index.php @@ -1,7 +1,10 @@ registerJs($js, View::POS_END);
+ +
-- libgit2 0.21.4