From c882dc756ae56b48eb9139ddbe079a6db3229ffc Mon Sep 17 00:00:00 2001 From: yarik Date: Wed, 9 Nov 2016 13:07:03 +0200 Subject: [PATCH] first commit --- Module.php | 12 ++++++++++++ composer.json | 15 +++++++++++++++ controllers/BannerController.php | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ controllers/BgController.php | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ controllers/SliderController.php | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ controllers/SliderImageController.php | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/Banner.php | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/BannerLang.php | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/BannerSearch.php | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/Bg.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/BgLang.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/BgSearch.php | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/Slider.php | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/SliderImage.php | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/SliderImageLang.php | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/SliderImageSearch.php | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/SliderSearch.php | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ widgets/Slider.php | 33 +++++++++++++++++++++++++++++++++ widgets/views/slider.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 19 files changed, 2018 insertions(+), 0 deletions(-) create mode 100755 Module.php create mode 100644 composer.json create mode 100755 controllers/BannerController.php create mode 100755 controllers/BgController.php create mode 100755 controllers/SliderController.php create mode 100755 controllers/SliderImageController.php create mode 100755 models/Banner.php create mode 100755 models/BannerLang.php create mode 100755 models/BannerSearch.php create mode 100755 models/Bg.php create mode 100755 models/BgLang.php create mode 100755 models/BgSearch.php create mode 100755 models/Slider.php create mode 100755 models/SliderImage.php create mode 100755 models/SliderImageLang.php create mode 100755 models/SliderImageSearch.php create mode 100755 models/SliderSearch.php create mode 100644 widgets/Slider.php create mode 100644 widgets/views/slider.php diff --git a/Module.php b/Module.php new file mode 100755 index 0000000..96903e3 --- /dev/null +++ b/Module.php @@ -0,0 +1,12 @@ +=7.0", + "yiisoft/yii2": "*", + "developeruz/yii2-db-rbac": "*" + }, + "autoload": { + "psr-4": { + "artweb\\artbox\\seo\\": "" + } + } +} \ No newline at end of file diff --git a/controllers/BannerController.php b/controllers/BannerController.php new file mode 100755 index 0000000..77d5756 --- /dev/null +++ b/controllers/BannerController.php @@ -0,0 +1,162 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Banner models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BannerSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Banner model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Banner model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Banner(); + $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 Banner 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 Banner 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 Banner model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Banner the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Banner::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/controllers/BgController.php b/controllers/BgController.php new file mode 100755 index 0000000..189ab2a --- /dev/null +++ b/controllers/BgController.php @@ -0,0 +1,167 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Bg models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BgSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Bg model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Bg model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Bg(); + $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 Bg 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 Bg 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 Bg model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Bg the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Bg::find() + ->where([ 'id' => $id ]) + ->with('lang') + ->one() ) !== NULL + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/controllers/SliderController.php b/controllers/SliderController.php new file mode 100755 index 0000000..5b955c8 --- /dev/null +++ b/controllers/SliderController.php @@ -0,0 +1,160 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Slider models. + * + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SliderSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + /** + * @var ActiveQuery $query + */ + $query = $dataProvider->query; + $query->with('sliderImages'); + + return $this->render( + 'index', + [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ] + ); + } + + /** + * 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( + [ + 'index', + ] + ); + } 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( + [ + 'index', + ] + ); + } 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.'); + } + } + } diff --git a/controllers/SliderImageController.php b/controllers/SliderImageController.php new file mode 100755 index 0000000..d576dfe --- /dev/null +++ b/controllers/SliderImageController.php @@ -0,0 +1,215 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + '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(); + $model->generateLangs(); + if ($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + $model->slider_id = $slider_id; + if ($model->save() && $model->transactionStatus) { + return $this->redirect( + [ + 'view', + 'slider_id' => $slider_id, + 'id' => $model->id, + ] + ); + } + } + $slider = Slider::findOne($slider_id); + return $this->render( + 'create', + [ + 'slider_id' => $slider_id, + 'model' => $model, + 'modelLangs' => $model->modelLangs, + '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); + $model->generateLangs(); + if ($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if ($model->save() && $model->transactionStatus) { + return $this->redirect( + [ + 'view', + 'slider_id' => $slider_id, + 'id' => $model->id, + ] + ); + } + } + $slider = Slider::findOne($slider_id); + return $this->render( + 'update', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + '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) + { + /** + * @var SliderImage $model + */ + if (( $model = SliderImage::find() + ->where( + [ + 'id' => $id, + 'slider_id' => $slider_id, + ] + ) + ->one() ) !== null + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/models/Banner.php b/models/Banner.php new file mode 100755 index 0000000..d52608e --- /dev/null +++ b/models/Banner.php @@ -0,0 +1,87 @@ + [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'status' ], + 'integer', + ], + [ + [ 'url' ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'id'), + 'url' => Yii::t('app', 'url'), + 'status' => Yii::t('app', 'status'), + ]; + } + } diff --git a/models/BannerLang.php b/models/BannerLang.php new file mode 100755 index 0000000..67bbed2 --- /dev/null +++ b/models/BannerLang.php @@ -0,0 +1,134 @@ + SaveImgBehavior::className(), + 'isLanguage' => true, + 'fields' => [ + [ + 'name' => 'image', + 'directory' => 'banner', + ], + ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'alt', + 'title', + 'image', + ], + 'string', + 'max' => 255, + ], + [ + [ + 'banner_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'banner_id', + 'language_id', + ], + 'message' => 'The combination of Banner ID and Language ID has already been taken.', + ], + [ + [ 'banner_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Banner::className(), + 'targetAttribute' => [ 'banner_id' => 'id' ], + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'banner_id' => Yii::t('app', 'banner_id'), + 'language_id' => Yii::t('app', 'language_id'), + 'alt' => Yii::t('app', 'alt'), + 'title' => Yii::t('app', 'title'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBanner() + { + return $this->hasOne(Banner::className(), [ 'id' => 'banner_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); + } + } diff --git a/models/BannerSearch.php b/models/BannerSearch.php new file mode 100755 index 0000000..41e75c7 --- /dev/null +++ b/models/BannerSearch.php @@ -0,0 +1,117 @@ +joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'sort' => [ + 'attributes' => [ + 'id', + 'url', + 'status', + 'title' => [ + 'asc' => [ 'banner_lang.title' => SORT_ASC ], + 'desc' => [ 'banner_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, + 'status' => $this->status, + ] + ); + + $query->andFilterWhere( + [ + 'like', + 'url', + $this->url, + ] + ) + ->andFilterWhere( + [ + 'like', + 'banner_lang.title', + $this->title, + ] + ); + + return $dataProvider; + } + } diff --git a/models/Bg.php b/models/Bg.php new file mode 100755 index 0000000..da4bdeb --- /dev/null +++ b/models/Bg.php @@ -0,0 +1,88 @@ + SaveImgBehavior::className(), + 'fields' => [ + [ + 'name' => 'image', + 'directory' => 'bg', + ], + ], + ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + public function rules() + { + return [ + [ + [ 'url' ], + 'string', + ], + ]; + } + + public function attributeLabels() + { + return [ + 'image' => Yii::t('app', 'image'), + 'url' => Yii::t('app', 'url'), + ]; + } + } diff --git a/models/BgLang.php b/models/BgLang.php new file mode 100755 index 0000000..7f0bf28 --- /dev/null +++ b/models/BgLang.php @@ -0,0 +1,107 @@ + 255, + ], + [ + [ + 'bg_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'bg_id', + 'language_id', + ], + 'message' => 'The combination of Bg ID and Language ID has already been taken.', + ], + [ + [ 'bg_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Bg::className(), + 'targetAttribute' => [ 'bg_id' => 'id' ], + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'bg_id' => Yii::t('app', 'bg_id'), + 'language_id' => Yii::t('app', 'language_id'), + 'title' => Yii::t('app', 'title'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBg() + { + return $this->hasOne(Bg::className(), [ 'id' => 'bg_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); + } + } diff --git a/models/BgSearch.php b/models/BgSearch.php new file mode 100755 index 0000000..4a9b4bd --- /dev/null +++ b/models/BgSearch.php @@ -0,0 +1,112 @@ +joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'sort' => [ + 'attributes' => [ + 'id', + 'url', + 'title' => [ + 'asc' => [ 'bg_lang.title' => SORT_ASC ], + 'desc' => [ 'bg_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', + 'url', + $this->url, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'bg_lang.title', + $this->title, + ] + ); + + return $dataProvider; + } + } diff --git a/models/Slider.php b/models/Slider.php new file mode 100755 index 0000000..69d0bb2 --- /dev/null +++ b/models/Slider.php @@ -0,0 +1,100 @@ + 200, + ], + [ + [ + 'width', + 'height', + 'title', + ], + 'required', + ], + [ + 'title', + 'unique', + 'targetClass' => '\common\models\Slider', + 'message' => Yii::t( + 'app', + 'message', + [ + 'field' => 'Title', + ] + ), + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'slider_id'), + 'speed' => Yii::t('app', 'speed'), + 'duration' => Yii::t('app', 'duration'), + 'title' => Yii::t('app', 'title'), + 'status' => Yii::t('app', 'status'), + 'width' => Yii::t('app', 'width'), + 'height' => Yii::t('app', 'height'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSliderImages() + { + return $this->hasMany(SliderImage::className(), [ 'slider_id' => 'id' ]) + ->where([ SliderImage::tableName() . '.status' => 1 ]); + } + + } diff --git a/models/SliderImage.php b/models/SliderImage.php new file mode 100755 index 0000000..51b7e5f --- /dev/null +++ b/models/SliderImage.php @@ -0,0 +1,131 @@ + 255, + ], + [ + [ 'slider_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Slider::className(), + 'targetAttribute' => [ 'slider_id' => 'id' ], + ], + ]; + } + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + [ + 'class' => SaveImgBehavior::className(), + 'fields' => [ + [ + 'name' => 'image', + 'directory' => 'slider', + ], + ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'slider_image_id'), + 'slider_id' => Yii::t('app', 'slider_id'), + 'image' => Yii::t('app', 'image'), + 'url' => Yii::t('app', 'url'), + 'status' => Yii::t('app', 'status'), + 'sort' => Yii::t('app', 'sort'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSlider() + { + return $this->hasOne(Slider::className(), [ 'id' => 'slider_id' ]); + } + } diff --git a/models/SliderImageLang.php b/models/SliderImageLang.php new file mode 100755 index 0000000..20d3397 --- /dev/null +++ b/models/SliderImageLang.php @@ -0,0 +1,109 @@ + 255, + ], + [ + [ + 'slider_image_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'slider_image_id', + 'language_id', + ], + 'message' => 'The combination of Slider Image ID and Language ID has already been taken.', + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'id' ], + ], + [ + [ 'slider_image_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => SliderImage::className(), + 'targetAttribute' => [ 'slider_image_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'slider_image_id' => Yii::t('app', 'slider_image_id'), + 'language_id' => Yii::t('app', 'language_id'), + 'title' => Yii::t('app', 'title'), + 'alt' => Yii::t('app', 'alt'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSliderImage() + { + return $this->hasOne(SliderImage::className(), [ 'id' => 'slider_image_id' ]); + } + } diff --git a/models/SliderImageSearch.php b/models/SliderImageSearch.php new file mode 100755 index 0000000..7a7ca9e --- /dev/null +++ b/models/SliderImageSearch.php @@ -0,0 +1,101 @@ + $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' => $slider_id, + 'status' => $this->status, + 'sort' => $this->sort, + ] + ); + + $query->andFilterWhere( + [ + 'like', + 'url', + $this->url, + ] + ); + + return $dataProvider; + } + } diff --git a/models/SliderSearch.php b/models/SliderSearch.php new file mode 100755 index 0000000..77a4630 --- /dev/null +++ b/models/SliderSearch.php @@ -0,0 +1,90 @@ + $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, + ] + ); + + $query->andFilterWhere( + [ + 'like', + 'title', + $this->title, + ] + ); + + return $dataProvider; + } + } diff --git a/widgets/Slider.php b/widgets/Slider.php new file mode 100644 index 0000000..91d1fbd --- /dev/null +++ b/widgets/Slider.php @@ -0,0 +1,33 @@ +where([\common\models\Slider::tableName().'.title'=>$this->title])->joinWith("sliderImage")->one(); + if($slider instanceof \common\models\Slider){ + return $this->render('slider',[ + 'slider'=>$slider, + 'title'=>$this->title + ]); + + } + + + } + +} \ No newline at end of file diff --git a/widgets/views/slider.php b/widgets/views/slider.php new file mode 100644 index 0000000..a2803ee --- /dev/null +++ b/widgets/views/slider.php @@ -0,0 +1,78 @@ + + + + +duration ? $slider->duration : 5000; +$speed = $slider->speed ? $slider->speed : 500; +$js=" $(\"#$title\").owlCarousel({ + navigation : true, // Show next and prev buttons + slideSpeed : 500, + autoplayTimeout:$dur, + paginationSpeed : $speed, + singleItem:true, + autoPlay:true + + }); + var owl = $(\"#$title\"); + $('#next_slide').click(function() { + owl.trigger('owl.next'); + }) + $('#prev_slide').click(function() { + owl.trigger('owl.prev'); + }) + "; + +$this->registerJs($js,View::POS_READY); + +?> -- libgit2 0.21.4