diff --git a/Module.php b/Module.php new file mode 100755 index 0000000..d3eddb1 --- /dev/null +++ b/Module.php @@ -0,0 +1,12 @@ +=7.0", "yiisoft/yii2": "*", - "developeruz/yii2-db-rbac": "*" + "developeruz/yii2-db-rbac": "*", + "artweb/artbox": "dev-master", + "artweb/artbox/language": "dev-master" }, "autoload": { "psr-4": { diff --git a/controllers/SeoCategoryController.php b/controllers/SeoCategoryController.php new file mode 100755 index 0000000..5ee21a7 --- /dev/null +++ b/controllers/SeoCategoryController.php @@ -0,0 +1,164 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + + ], + ]; + } + + /** + * Lists all SeoCategory models. + * + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SeoCategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render( + 'index', + [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ] + ); + } + + /** + * Creates a new SeoCategory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionCreate() + { + $model = new SeoCategory(); + $model->generateLangs(); + + if ($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if ($model->save() && $model->transactionStatus) { + return $this->redirect( + [ + 'index', + ] + ); + } + } + return $this->render( + 'create', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ] + ); + } + + /** + * Updates an existing SeoCategory 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 SeoCategory 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 SeoCategory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return SeoCategory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (( $model = SeoCategory::find() + ->where([ 'id' => $id ]) + ->with('lang') + ->one() ) !== null + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/controllers/SeoController.php b/controllers/SeoController.php new file mode 100755 index 0000000..5e9dafe --- /dev/null +++ b/controllers/SeoController.php @@ -0,0 +1,182 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + + ], + ]; + } + + /** + * Lists all Seo models. + * + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SeoSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render( + 'index', + [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ] + ); + } + + /** + * Displays a single Seo model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render( + 'view', + [ + 'model' => $this->findModel($id), + ] + ); + } + + /** + * Creates a new Seo model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionCreate() + { + $model = new Seo(); + $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 Seo 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 Seo 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 Seo model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Seo the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (( $model = Seo::find() + ->where([ 'id' => $id ]) + ->with('lang') + ->one() ) !== null + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/controllers/SeoDynamicController.php b/controllers/SeoDynamicController.php new file mode 100755 index 0000000..a4ae161 --- /dev/null +++ b/controllers/SeoDynamicController.php @@ -0,0 +1,216 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + + ], + ]; + } + + /** + * Lists all SeoDynamic models. + * + * @param int $seo_category_id + * + * @return mixed + */ + public function actionIndex($seo_category_id) + { + $seo_category = $this->findCategory($seo_category_id); + $searchModel = new SeoDynamicSearch(); + $dataProvider = $searchModel->search($seo_category_id, Yii::$app->request->queryParams); + + return $this->render( + 'index', + [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'seo_category' => $seo_category, + ] + ); + } + + /** + * Displays a single SeoDynamic model. + * + * @param integer $seo_category_id + * @param integer $id + * + * @return mixed + */ + public function actionView($seo_category_id, $id) + { + $seo_category = $this->findCategory($seo_category_id); + return $this->render( + 'view', + [ + 'model' => $this->findModel($id), + 'seo_category' => $seo_category, + ] + ); + } + + /** + * Creates a new SeoDynamic model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @param integer $seo_category_id + * + * @return mixed + */ + public function actionCreate($seo_category_id) + { + $seo_category = $this->findCategory($seo_category_id); + $model = new SeoDynamic(); + $model->generateLangs(); + if ($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + $model->seo_category_id = $seo_category_id; + if ($model->save() && $model->transactionStatus) { + return $this->redirect( + [ + 'index', + 'seo_category_id' => $seo_category_id, + ] + ); + } + } + return $this->render( + 'create', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + 'seo_category' => $seo_category, + ] + ); + } + + /** + * Updates an existing SeoDynamic model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $seo_category_id + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($seo_category_id, $id) + { + $seo_category = $this->findCategory($seo_category_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( + [ + 'index', + 'seo_category_id' => $seo_category_id, + ] + ); + } + } + return $this->render( + 'update', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + 'seo_category' => $seo_category, + ] + ); + } + + /** + * Deletes an existing SeoDynamic model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $seo_category_id + * @param integer $id + * + * @return mixed + */ + public function actionDelete($seo_category_id, $id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect( + [ + 'index', + 'seo_category_id' => $seo_category_id, + ] + ); + } + + /** + * Finds the SeoDynamic model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return SeoDynamic the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (( $model = SeoDynamic::find() + ->where([ 'id' => $id ]) + ->with('lang') + ->one() ) !== null + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + protected function findCategory($id) + { + if (( $model = SeoCategory::find() + ->where([ 'id' => $id ]) + ->with('lang') + ->one() ) !== null + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/models/Seo.php b/models/Seo.php new file mode 100755 index 0000000..eba94b6 --- /dev/null +++ b/models/Seo.php @@ -0,0 +1,85 @@ + [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'url' ], + 'required', + ], + [ + [ 'url' ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'seo_id'), + 'url' => Yii::t('app', 'url'), + ]; + } + } diff --git a/models/SeoCategory.php b/models/SeoCategory.php new file mode 100755 index 0000000..81217d5 --- /dev/null +++ b/models/SeoCategory.php @@ -0,0 +1,96 @@ + [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'status' ], + 'integer', + ], + [ + [ 'controller' ], + 'string', + 'max' => 100, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'seo_category_id'), + 'controller' => Yii::t('app', 'controller'), + 'status' => Yii::t('app', 'status'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoDynamics() + { + return $this->hasMany(SeoDynamic::className(), [ 'seo_category_id' => 'id' ]); + } + } diff --git a/models/SeoCategoryLang.php b/models/SeoCategoryLang.php new file mode 100755 index 0000000..2116793 --- /dev/null +++ b/models/SeoCategoryLang.php @@ -0,0 +1,104 @@ + 255, + ], + [ + [ + 'seo_category_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'seo_category_id', + 'language_id', + ], + 'message' => 'The combination of Seo Category ID and Language ID has already been taken.', + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'id' ], + ], + [ + [ 'seo_category_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => SeoCategory::className(), + 'targetAttribute' => [ 'seo_category_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_category_id' => Yii::t('app', 'seo_category_id'), + 'language_id' => Yii::t('app', 'language_id'), + 'title' => Yii::t('app', 'name'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoCategory() + { + return $this->hasOne(SeoCategory::className(), [ 'id' => 'seo_category_id' ]); + } + } diff --git a/models/SeoCategorySearch.php b/models/SeoCategorySearch.php new file mode 100755 index 0000000..1796400 --- /dev/null +++ b/models/SeoCategorySearch.php @@ -0,0 +1,118 @@ +joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'sort' => [ + 'attributes' => [ + 'id', + 'controller', + 'status', + 'title' => [ + 'asc' => [ 'seo_category_lang.title' => SORT_ASC ], + 'desc' => [ 'seo_category_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', + 'controller', + $this->controller, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'seo_category_lang.title', + $this->title, + ] + ); + + return $dataProvider; + } + } diff --git a/models/SeoDynamic.php b/models/SeoDynamic.php new file mode 100755 index 0000000..0d28f7d --- /dev/null +++ b/models/SeoDynamic.php @@ -0,0 +1,122 @@ + [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'seo_category_id', + 'status', + ], + 'integer', + ], + [ + [ + 'action', + ], + 'string', + 'max' => 200, + ], + [ + [ + 'fields', + 'param', + ], + 'string', + 'max' => 255, + ], + [ + [ 'seo_category_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => SeoCategory::className(), + 'targetAttribute' => [ 'seo_category_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'seo_dynamic_id'), + 'seo_category_id' => Yii::t('app', 'seo_category_id'), + 'action' => Yii::t('app', 'action'), + 'fields' => Yii::t('app', 'fields'), + 'status' => Yii::t('app', 'status'), + 'param' => Yii::t('app', 'param'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoCategory() + { + return $this->hasOne(SeoCategory::className(), [ 'id' => 'seo_category_id' ]); + } + } diff --git a/models/SeoDynamicLang.php b/models/SeoDynamicLang.php new file mode 100755 index 0000000..e433c99 --- /dev/null +++ b/models/SeoDynamicLang.php @@ -0,0 +1,129 @@ + 255, + ], + [ + [ + 'seo_dynamic_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'seo_dynamic_id', + 'language_id', + ], + 'message' => 'The combination of Seo Dynamic ID and Language ID has already been taken.', + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'id' ], + ], + [ + [ 'seo_dynamic_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => SeoDynamic::className(), + 'targetAttribute' => [ 'seo_dynamic_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_dynamic_id' => Yii::t('app', 'seo_dynamic_id'), + 'language_id' => Yii::t('app', 'language_id'), + 'title' => Yii::t('app', 'name'), + 'meta_title' => Yii::t('app', 'title'), + 'h1' => Yii::t('app', 'h1'), + 'key' => Yii::t('app', 'key'), + 'meta' => Yii::t('app', 'meta'), + 'meta_description' => Yii::t('app', 'meta_description'), + 'seo_text' => Yii::t('app', 'seo_text'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoDynamic() + { + return $this->hasOne(SeoDynamic::className(), [ 'id' => 'seo_dynamic_id' ]); + } + } diff --git a/models/SeoDynamicSearch.php b/models/SeoDynamicSearch.php new file mode 100755 index 0000000..dce042a --- /dev/null +++ b/models/SeoDynamicSearch.php @@ -0,0 +1,142 @@ +joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'sort' => [ + 'attributes' => [ + 'id', + 'action', + 'fields', + 'status', + 'param', + 'title' => [ + 'asc' => [ 'seo_dynamic_lang.title' => SORT_ASC ], + 'desc' => [ 'seo_dynamic_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->andWhere( + [ + 'seo_category_id' => $seo_category_id, + ] + ) + ->andFilterWhere( + [ + 'id' => $this->id, + 'status' => $this->status, + ] + ); + + $query->andFilterWhere( + [ + 'ilike', + 'action', + $this->action, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'fields', + $this->fields, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'param', + $this->param, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'seo_dynamic_lang.title', + $this->title, + ] + ); + + return $dataProvider; + } + } diff --git a/models/SeoLang.php b/models/SeoLang.php new file mode 100755 index 0000000..a4db5b2 --- /dev/null +++ b/models/SeoLang.php @@ -0,0 +1,123 @@ + 255, + ], + [ + [ + 'seo_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'seo_id', + 'language_id', + ], + 'message' => 'The combination of Seo ID and Language ID has already been taken.', + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'id' ], + ], + [ + [ 'seo_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Seo::className(), + 'targetAttribute' => [ 'seo_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_id' => Yii::t('app', 'seo_id'), + 'language_id' => Yii::t('app', 'language_id'), + 'title' => Yii::t('app', 'title'), + 'meta_description' => Yii::t('app', 'meta_description'), + 'h1' => Yii::t('app', 'h1'), + 'meta' => Yii::t('app', 'meta'), + 'seo_text' => Yii::t('app', 'seo_text'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeo() + { + return $this->hasOne(Seo::className(), [ 'id' => 'seo_id' ]); + } + } diff --git a/models/SeoSearch.php b/models/SeoSearch.php new file mode 100755 index 0000000..03e7754 --- /dev/null +++ b/models/SeoSearch.php @@ -0,0 +1,168 @@ +joinWith('lang'); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'sort' => [ + 'attributes' => [ + 'id', + 'url', + 'title' => [ + 'asc' => [ 'seo_lang.title' => SORT_ASC ], + 'desc' => [ 'seo_lang.title' => SORT_DESC ], + ], + 'meta_description' => [ + 'asc' => [ 'seo_lang.meta_description' => SORT_ASC ], + 'desc' => [ 'seo_lang.meta_description' => SORT_DESC ], + ], + 'h1' => [ + 'asc' => [ 'seo_lang.h1' => SORT_ASC ], + 'desc' => [ 'seo_lang.h1' => SORT_DESC ], + ], + 'meta' => [ + 'asc' => [ 'seo_lang.meta' => SORT_ASC ], + 'desc' => [ 'seo_lang.meta' => SORT_DESC ], + ], + 'seo_text' => [ + 'asc' => [ 'seo_lang.seo_text' => SORT_ASC ], + 'desc' => [ 'seo_lang.seo_text' => 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', + 'seo_lang.title', + $this->title, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'seo_lang.meta_description', + $this->meta_description, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'seo_lang.h1', + $this->h1, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'seo_lang.meta', + $this->meta, + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'seo_lang.seo_text', + $this->seo_text, + ] + ); + + return $dataProvider; + } + } diff --git a/widget/Seo.php b/widget/Seo.php new file mode 100644 index 0000000..88da831 --- /dev/null +++ b/widget/Seo.php @@ -0,0 +1,448 @@ +url = \Yii::$app->request->url; + $this->project_name = \Yii::$app->name; + if(empty(self::$optionsList)){ + self::$optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); + } + + parent::init(); + + } + + + public function run() + { + + $seoData = $this->getViewData(); + foreach ($seoData as $key => $value) { + $this->$key = $value; + } + + + switch ($this->row) { + case self::SEO_TEXT: + + + $filter = \Yii::$app->request->get('filters', []); + $sort = \Yii::$app->request->get('sort', []); + $paginate = \Yii::$app->request->get('page', []); + + if(empty($filter) && empty($sort) && empty($paginate) ){ + + return $this->selectSeoData(self::SEO_TEXT); + + } else { + + $widgetData = static::findSeoByUrl($this->url); + + $result = ''; + + if ($widgetData instanceof \artweb\artbox\seo\models\Seo) { + + $result = $widgetData->{self::SEO_TEXT}; + + } else { + + $widgetData = $this->findSeoByDynamic(); + + if ($widgetData instanceof SeoDynamic) { + + $result = $widgetData->{self::SEO_TEXT}; + + } + + } + + return $this->replaceData($result); + } + + + break; + case self::H1: + + $filter = \Yii::$app->request->get('filters', []); + + $default = $this->selectSeoData(self::H1); + + if ($default != $this->{self::H1}) { + + return $default; + + + } else if(!empty($filter) && !$this->checkFilter($filter)){ + + $array = $this->arrayBuilder($filter); + return $this->getNameString($array); + } + else { + + return $default; + } + break; + case self::TITLE: + + $filter = \Yii::$app->request->get('filters', []); + + + $title = $this->selectSeoData(self::TITLE); + + + if(!empty($filter) && $title == $this->title || !empty($filter) && empty($title)) { + + $array = $this->arrayBuilder($filter); + + $title_string = $this->getTitleString($array); + + if($title_string){ + return $title_string; + } + + } + + if (!empty($title)) { + + return $title; + } else { + return $this->project_name; + } + + break; + case self::DESCRIPTION: + $description = $this->selectSeoData(self::DESCRIPTION); + + if (!empty($description)) { + + $this->getView()->registerMetaTag([ + 'name' => 'description', + 'content' => $description + ]); + + } else { + + $filter = \Yii::$app->request->get('filters', []); + + if(!empty($filter)){ + $array = $this->arrayBuilder($filter); + $this->getView()->registerMetaTag([ + 'name' => 'description', + 'content' => $this->getDescriptionString($array) + ]); + } + + } + + break; + case self::META: + + $meta = $this->selectSeoData(self::META); + + $filter = \Yii::$app->request->get('filters', []); + $sort = \Yii::$app->request->get('sort', []); + $paginate = \Yii::$app->request->get('page', []); + + + + if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) { + + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => $meta + ]); + + } else if(!empty($filter['special'])){ + + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => 'noindex,follow' + ]); + + } else if ( + isset($filter['brands']) && count($filter['brands']) > 1 + || isset($filter) && $this->checkFilter($filter) + + ) { + + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => 'noindex,nofollow' + ]); + + } else if ( + isset($filter['brands']) && count($filter['brands']) > 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 4 + || isset($filter) && count($filter, COUNT_RECURSIVE) > 4 + || !empty($sort) || !empty($paginate) || isset($filter['prices']) + ) { + + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => 'noindex,nofollow' + ]); + } else { + + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => 'index,follow' + ]); + } + + + + + break; + } + + + } + + protected function replaceData($str) + { + + if (!empty($this->fields)) { + foreach ($this->fields as $field_name => $field_value) { + $str = str_replace('{' . $field_name . '}', $field_value, $str); + } + } + $str = str_replace('{project_name}', $this->project_name, $str); + return $str; + } + + protected static function findSeoByUrl($url) + { + if(empty(self::$check_url_bool)){ + self::$check_url = \artweb\artbox\seo\models\Seo::findOne(['url' => $url]); + self::$check_url_bool = true; + } + return self::$check_url; + } + + protected function findSeoByDynamic() + { + + if(!empty($this->key)){ + + $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]); + } else { + + + $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id]); + } + + return $query->one(); + } + + + protected function findSeoByDynamicForFilters(){ + return SeoDynamic::find()->joinWith('seoCategory')->where(['param' =>'filters'])->one(); + } + + + protected function getViewData() + { + $params = $this->getView()->params; + if (isset($params['seo'])) { + return $params['seo']; + } else { + return []; + } + } + + protected function selectSeoData($param) + { + + $result = ''; + + $widgetData = static::findSeoByUrl($this->url); + + if ($widgetData instanceof \artweb\artbox\seo\models\Seo) { + + $result = $widgetData->$param; + + } else if (!empty($this->$param)) { + + $result = $this->$param; + + } else { + + $widgetData = $this->findSeoByDynamic(); + + if ($widgetData instanceof SeoDynamic) { + + $result = $widgetData->$param; + + } + + } + + return $this->replaceData($result); + + } + + public function getTitleString($array){ + // "{Название раздела: Название блока фильтра | Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3} - купить в Киеве, Украине - интернет магазин Лінія Світла"; + $row = ''; + foreach($array as $name => $field){ + + if($name == 'category' ){ + $row = $field.' | '.$row; + } else { + $row .= $field['name'] .' '.$field['value'].' | ' ; + } + + + + } + $row = substr($row, 0,-2 ); + $row .= " - купить в Киеве, Украине - интернет магазин Лінія Світла"; + return $row; +// $template = SeoDynamic::find()->select('title')->where(['param' =>'filters'])->one(); +// if($template instanceof SeoDynamic){ +// foreach ($array as $field_name => $field_value) { +// $template->title = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template->title); +// } +// $template = preg_replace('/\{.[^\}]*\}\s/','',$template->title); +// return $template; +// } +// +// return false; + + } + + + public function getDescriptionString($array){ + // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; + $row = 'Лучшие цены на '; + foreach($array as $name => $field){ + + if($name == 'category' ){ + $row = $field.' | '.$row; + } else { + $row .= $field['name'] .' '.$field['value'].' | ' ; + } + + + + } + $row = substr($row, 0,-2 ); + $row .= ". Лінія Світла"; + return $row; + + } + + + public function getNameString($array){ + // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; + $row = ''; + foreach($array as $name => $field){ + + if($name == 'category' ){ + $row = $field.' | '.$row; + } else { + $row .= $field['name'] .' '.$field['value'].' | ' ; + } + + + + } + $row = substr($row, 0,-2 ); + return $row; + + } + + public function arrayBuilder($filter) + { + + $array = [ + 'category' => $this->category_name + ]; + + + if (isset($filter['brands']) && count($filter['brands']) == 1) { + $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); + if (!$model instanceof Brand) { + + \Yii::$app->response->redirect(['/site/error'], 404); + } else { + $array['brand']['name'] = 'Бренд'; + $array['brand']['value'] = $model->name; + } + + } + + + $optionsList = ArrayHelper::map(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(), 'alias', 'name'); + + + foreach ($optionsList as $optionList => $name) { + + + if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) { + + $model = TaxOption::find()->where(['alias' => $filter[$optionList]])->one(); + if (!$model instanceof TaxOption) { + + \Yii::$app->response->redirect(['site/error'], 404); + } else { + $array[$optionList]['value'] = $model->value; + $array[$optionList]['name'] = $name; + } + + + } + + + } + + return $array; + + } + + protected function checkFilter($filter){ + foreach(self::$optionsList as $optionList){ + + if(isset($filter[$optionList]) && count($filter[$optionList]) > 1){ + return true; + } + + } + return false; + } + + +} \ No newline at end of file -- libgit2 0.21.4