diff --git a/.gitignore b/.gitignore index 9e49b7d..cc82398 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ phpunit.phar /backend/web/assets/ /frontend/web/assets/ /frontend/web/css/node_modules/ +/frontend/views/вертска composer.lock tests/_output/* \ No newline at end of file diff --git a/backend/controllers/SliderImageController.php b/backend/controllers/SliderImageController.php new file mode 100755 index 0000000..f01301a --- /dev/null +++ b/backend/controllers/SliderImageController.php @@ -0,0 +1,144 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all SliderImage models. + * @param $slider_id Slider id + * @return mixed + */ + public function actionIndex($slider_id) + { + $searchModel = new SliderImageSearch(); + $dataProvider = $searchModel->search($slider_id, Yii::$app->request->queryParams); + + return $this->render('index', [ + 'slider_id' => $slider_id, + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single SliderImage model. + * @param integer $id + * @param $slider_id Slider id + * @return mixed + */ + public function actionView($slider_id, $id) + { + return $this->render('view', [ + 'slider_id' => $slider_id, + 'model' => $this->findModel($slider_id, $id), + ]); + } + + /** + * Creates a new SliderImage model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @param $slider_id Slider id + * @return mixed + */ + public function actionCreate($slider_id) + { + $model = new SliderImage(); + + if ($model->load(Yii::$app->request->post())) { + $model->slider_id = $slider_id; + $model->save(); + return $this->redirect(['view', 'slider_id'=>$slider_id, 'id' => $model->slider_image_id]); + } else { + + $slider = Slider::findOne($slider_id); + + return $this->render('create', [ + 'slider_id' => $slider_id, + 'model' => $model, + 'slider' => $slider, + ]); + } + } + + /** + * Updates an existing SliderImage model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param $slider_id Slider id + * @param integer $id + * @return mixed + */ + public function actionUpdate($slider_id, $id) + { + $model = $this->findModel($slider_id, $id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'slider_id'=>$slider_id, 'id' => $model->slider_image_id]); + } else { + + $slider = Slider::findOne($slider_id); + return $this->render('update', [ + 'model' => $model, + 'slider_id' => $slider_id, + 'slider' => $slider, + ]); + } + } + + /** + * Deletes an existing SliderImage model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param $slider_id Slider id + * @param integer $id + * @return mixed + */ + public function actionDelete($slider_id, $id) + { + $this->findModel($slider_id, $id)->delete(); + + return $this->redirect(['index','slider_id'=>$slider_id]); + } + + /** + * Finds the SliderImage model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param $slider_id Slider id + * @param integer $id + * @return SliderImage the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($slider_id,$id) + { + if (($model = SliderImage::find()->where(['slider_image_id'=> $id, 'slider_id'=>$slider_id])->one()) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/views/slider-image/_form.php b/backend/views/slider-image/_form.php new file mode 100755 index 0000000..92148bd --- /dev/null +++ b/backend/views/slider-image/_form.php @@ -0,0 +1,58 @@ + + +
diff --git a/backend/views/slider-image/_search.php b/backend/views/slider-image/_search.php new file mode 100755 index 0000000..32edbf9 --- /dev/null +++ b/backend/views/slider-image/_search.php @@ -0,0 +1,41 @@ + + + diff --git a/backend/views/slider-image/create.php b/backend/views/slider-image/create.php new file mode 100755 index 0000000..c660146 --- /dev/null +++ b/backend/views/slider-image/create.php @@ -0,0 +1,25 @@ +title = Yii::t('app', 'Create Slider Image'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Slider Images'), 'url' => Url::toRoute(['index','slider_id'=>$slider_id])]; +$this->params['breadcrumbs'][] = $this->title; +?> + diff --git a/backend/views/slider-image/index.php b/backend/views/slider-image/index.php new file mode 100755 index 0000000..9859251 --- /dev/null +++ b/backend/views/slider-image/index.php @@ -0,0 +1,74 @@ +title = Yii::t('app', 'Slider Images'); +$this->params['breadcrumbs'][] = $this->title; +?> + diff --git a/backend/views/slider-image/update.php b/backend/views/slider-image/update.php new file mode 100755 index 0000000..9e50b6e --- /dev/null +++ b/backend/views/slider-image/update.php @@ -0,0 +1,27 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Slider Image', +]) . $model->title; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Slider Images'), 'url' => Url::toRoute(['index','slider_id'=>$slider_id])]; +$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => Url::toRoute(['view', 'slider_id'=>$slider_id, 'id' => $model->slider_image_id])]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> + diff --git a/backend/views/slider-image/view.php b/backend/views/slider-image/view.php new file mode 100755 index 0000000..8ffd104 --- /dev/null +++ b/backend/views/slider-image/view.php @@ -0,0 +1,43 @@ +title = $model->title; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Slider Images'), 'url' => Url::toRoute(['index','slider_id'=>$slider_id])]; +$this->params['breadcrumbs'][] = $this->title; +?> + diff --git a/common/models/SliderImage.php b/common/models/SliderImage.php new file mode 100644 index 0000000..22a0abd --- /dev/null +++ b/common/models/SliderImage.php @@ -0,0 +1,70 @@ + 255], + [['slider_id'], 'exist', 'skipOnError' => true, 'targetClass' => Slider::className(), 'targetAttribute' => ['slider_id' => 'slider_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'slider_image_id' => Yii::t('app', 'Slider Image ID'), + 'slider_id' => Yii::t('app', 'Slider ID'), + 'image' => Yii::t('app', 'Image'), + 'alt' => Yii::t('app', 'Alt'), + 'title' => Yii::t('app', 'Title'), + 'url' => Yii::t('app', 'Url'), + 'status' => Yii::t('app', 'Status'), + 'sort' => Yii::t('app', 'Sort'), + 'price' => Yii::t('app', 'Price'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSlider() + { + return $this->hasOne(Slider::className(), ['slider_id' => 'slider_id']); + } +} diff --git a/common/models/SliderImageSearch.php b/common/models/SliderImageSearch.php new file mode 100755 index 0000000..df1dd31 --- /dev/null +++ b/common/models/SliderImageSearch.php @@ -0,0 +1,77 @@ + $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([ + 'slider_image_id' => $this->slider_image_id, + 'slider_id' => $slider_id, + 'status' => $this->status, + 'sort' => $this->sort, + ]); + + $query->andFilterWhere(['like', 'image', $this->image]) + ->andFilterWhere(['like', 'alt', $this->alt]) + ->andFilterWhere(['like', 'title', $this->title]) + ->andFilterWhere(['like', 'url', $this->url]); + + return $dataProvider; + } +} diff --git a/console/migrations/m160405_101056_create_slider_images.php b/console/migrations/m160405_101056_create_slider_images.php index 1093157..1e32b54 100755 --- a/console/migrations/m160405_101056_create_slider_images.php +++ b/console/migrations/m160405_101056_create_slider_images.php @@ -21,6 +21,7 @@ class m160405_101056_create_slider_images extends Migration 'url' => $this->string(255), 'status' => $this->smallInteger(1), 'sort' => $this->integer(6), + 'price' => $this->float(), ]); $this->addForeignKey('slider_slider_image_fk', 'slider_image', 'slider_id', 'slider', 'slider_id', 'CASCADE', 'CASCADE'); } diff --git a/frontend/widgets/views/slider.php b/frontend/widgets/views/slider.php index 4dc6d95..974a2e2 100644 --- a/frontend/widgets/views/slider.php +++ b/frontend/widgets/views/slider.php @@ -7,44 +7,43 @@ use yii\helpers\Url; ?>