Commit feffea0a9c9c22fd83dcd54fe4131a840adb9ae9
1 parent
28bbf968
Namespaces
Showing
15 changed files
with
2112 additions
and
1 deletions
Show diff stats
composer.json
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace backend\controllers; | |
| 4 | + | |
| 5 | + use Yii; | |
| 6 | + use artweb\artbox\models\SeoCategory; | |
| 7 | + use artweb\artbox\models\SeoCategorySearch; | |
| 8 | + use yii\web\Controller; | |
| 9 | + use yii\web\NotFoundHttpException; | |
| 10 | + use yii\filters\VerbFilter; | |
| 11 | + use developeruz\db_rbac\behaviors\AccessBehavior; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * SeoCategoryController implements the CRUD actions for SeoCategory model. | |
| 15 | + */ | |
| 16 | + class SeoCategoryController extends Controller | |
| 17 | + { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * @inheritdoc | |
| 21 | + */ | |
| 22 | + public function behaviors() | |
| 23 | + { | |
| 24 | + return [ | |
| 25 | + 'access' => [ | |
| 26 | + 'class' => AccessBehavior::className(), | |
| 27 | + 'rules' => [ | |
| 28 | + 'site' => [ | |
| 29 | + [ | |
| 30 | + 'actions' => [ | |
| 31 | + 'login', | |
| 32 | + 'error', | |
| 33 | + ], | |
| 34 | + 'allow' => true, | |
| 35 | + ], | |
| 36 | + ], | |
| 37 | + ], | |
| 38 | + ], | |
| 39 | + 'verbs' => [ | |
| 40 | + 'class' => VerbFilter::className(), | |
| 41 | + | |
| 42 | + ], | |
| 43 | + ]; | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Lists all SeoCategory models. | |
| 48 | + * | |
| 49 | + * @return mixed | |
| 50 | + */ | |
| 51 | + public function actionIndex() | |
| 52 | + { | |
| 53 | + $searchModel = new SeoCategorySearch(); | |
| 54 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
| 55 | + | |
| 56 | + return $this->render( | |
| 57 | + 'index', | |
| 58 | + [ | |
| 59 | + 'searchModel' => $searchModel, | |
| 60 | + 'dataProvider' => $dataProvider, | |
| 61 | + ] | |
| 62 | + ); | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Creates a new SeoCategory model. | |
| 67 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
| 68 | + * | |
| 69 | + * @return mixed | |
| 70 | + */ | |
| 71 | + public function actionCreate() | |
| 72 | + { | |
| 73 | + $model = new SeoCategory(); | |
| 74 | + $model->generateLangs(); | |
| 75 | + | |
| 76 | + if ($model->load(Yii::$app->request->post())) { | |
| 77 | + $model->loadLangs(\Yii::$app->request); | |
| 78 | + if ($model->save() && $model->transactionStatus) { | |
| 79 | + return $this->redirect( | |
| 80 | + [ | |
| 81 | + 'index', | |
| 82 | + ] | |
| 83 | + ); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + return $this->render( | |
| 87 | + 'create', | |
| 88 | + [ | |
| 89 | + 'model' => $model, | |
| 90 | + 'modelLangs' => $model->modelLangs, | |
| 91 | + ] | |
| 92 | + ); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Updates an existing SeoCategory model. | |
| 97 | + * If update is successful, the browser will be redirected to the 'view' page. | |
| 98 | + * | |
| 99 | + * @param integer $id | |
| 100 | + * | |
| 101 | + * @return mixed | |
| 102 | + */ | |
| 103 | + public function actionUpdate($id) | |
| 104 | + { | |
| 105 | + $model = $this->findModel($id); | |
| 106 | + $model->generateLangs(); | |
| 107 | + if ($model->load(Yii::$app->request->post())) { | |
| 108 | + $model->loadLangs(\Yii::$app->request); | |
| 109 | + if ($model->save() && $model->transactionStatus) { | |
| 110 | + return $this->redirect( | |
| 111 | + [ | |
| 112 | + 'view', | |
| 113 | + 'id' => $model->id, | |
| 114 | + ] | |
| 115 | + ); | |
| 116 | + } | |
| 117 | + } | |
| 118 | + return $this->render( | |
| 119 | + 'update', | |
| 120 | + [ | |
| 121 | + 'model' => $model, | |
| 122 | + 'modelLangs' => $model->modelLangs, | |
| 123 | + ] | |
| 124 | + ); | |
| 125 | + } | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * Deletes an existing SeoCategory model. | |
| 129 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
| 130 | + * | |
| 131 | + * @param integer $id | |
| 132 | + * | |
| 133 | + * @return mixed | |
| 134 | + */ | |
| 135 | + public function actionDelete($id) | |
| 136 | + { | |
| 137 | + $this->findModel($id) | |
| 138 | + ->delete(); | |
| 139 | + | |
| 140 | + return $this->redirect([ 'index' ]); | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Finds the SeoCategory model based on its primary key value. | |
| 145 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
| 146 | + * | |
| 147 | + * @param integer $id | |
| 148 | + * | |
| 149 | + * @return SeoCategory the loaded model | |
| 150 | + * @throws NotFoundHttpException if the model cannot be found | |
| 151 | + */ | |
| 152 | + protected function findModel($id) | |
| 153 | + { | |
| 154 | + if (( $model = SeoCategory::find() | |
| 155 | + ->where([ 'id' => $id ]) | |
| 156 | + ->with('lang') | |
| 157 | + ->one() ) !== null | |
| 158 | + ) { | |
| 159 | + return $model; | |
| 160 | + } else { | |
| 161 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace backend\controllers; | |
| 4 | + | |
| 5 | + use Yii; | |
| 6 | + use artweb\artbox\models\Seo; | |
| 7 | + use artweb\artbox\models\SeoSearch; | |
| 8 | + use yii\web\Controller; | |
| 9 | + use yii\web\NotFoundHttpException; | |
| 10 | + use yii\filters\VerbFilter; | |
| 11 | + use developeruz\db_rbac\behaviors\AccessBehavior; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * SeoController implements the CRUD actions for Seo model. | |
| 15 | + */ | |
| 16 | + class SeoController extends Controller | |
| 17 | + { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * @inheritdoc | |
| 21 | + */ | |
| 22 | + public function behaviors() | |
| 23 | + { | |
| 24 | + return [ | |
| 25 | + 'access' => [ | |
| 26 | + 'class' => AccessBehavior::className(), | |
| 27 | + 'rules' => [ | |
| 28 | + 'site' => [ | |
| 29 | + [ | |
| 30 | + 'actions' => [ | |
| 31 | + 'login', | |
| 32 | + 'error', | |
| 33 | + ], | |
| 34 | + 'allow' => true, | |
| 35 | + ], | |
| 36 | + ], | |
| 37 | + ], | |
| 38 | + ], | |
| 39 | + 'verbs' => [ | |
| 40 | + 'class' => VerbFilter::className(), | |
| 41 | + | |
| 42 | + ], | |
| 43 | + ]; | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Lists all Seo models. | |
| 48 | + * | |
| 49 | + * @return mixed | |
| 50 | + */ | |
| 51 | + public function actionIndex() | |
| 52 | + { | |
| 53 | + $searchModel = new SeoSearch(); | |
| 54 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
| 55 | + | |
| 56 | + return $this->render( | |
| 57 | + 'index', | |
| 58 | + [ | |
| 59 | + 'searchModel' => $searchModel, | |
| 60 | + 'dataProvider' => $dataProvider, | |
| 61 | + ] | |
| 62 | + ); | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Displays a single Seo model. | |
| 67 | + * | |
| 68 | + * @param integer $id | |
| 69 | + * | |
| 70 | + * @return mixed | |
| 71 | + */ | |
| 72 | + public function actionView($id) | |
| 73 | + { | |
| 74 | + return $this->render( | |
| 75 | + 'view', | |
| 76 | + [ | |
| 77 | + 'model' => $this->findModel($id), | |
| 78 | + ] | |
| 79 | + ); | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Creates a new Seo model. | |
| 84 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
| 85 | + * | |
| 86 | + * @return mixed | |
| 87 | + */ | |
| 88 | + public function actionCreate() | |
| 89 | + { | |
| 90 | + $model = new Seo(); | |
| 91 | + $model->generateLangs(); | |
| 92 | + | |
| 93 | + if ($model->load(Yii::$app->request->post())) { | |
| 94 | + $model->loadLangs(\Yii::$app->request); | |
| 95 | + if ($model->save() && $model->transactionStatus) { | |
| 96 | + return $this->redirect( | |
| 97 | + [ | |
| 98 | + 'view', | |
| 99 | + 'id' => $model->id, | |
| 100 | + ] | |
| 101 | + ); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + return $this->render( | |
| 105 | + 'create', | |
| 106 | + [ | |
| 107 | + 'model' => $model, | |
| 108 | + 'modelLangs' => $model->modelLangs, | |
| 109 | + ] | |
| 110 | + ); | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Updates an existing Seo model. | |
| 115 | + * If update is successful, the browser will be redirected to the 'view' page. | |
| 116 | + * | |
| 117 | + * @param integer $id | |
| 118 | + * | |
| 119 | + * @return mixed | |
| 120 | + */ | |
| 121 | + public function actionUpdate($id) | |
| 122 | + { | |
| 123 | + $model = $this->findModel($id); | |
| 124 | + $model->generateLangs(); | |
| 125 | + if ($model->load(Yii::$app->request->post())) { | |
| 126 | + $model->loadLangs(\Yii::$app->request); | |
| 127 | + if ($model->save() && $model->transactionStatus) { | |
| 128 | + return $this->redirect( | |
| 129 | + [ | |
| 130 | + 'view', | |
| 131 | + 'id' => $model->id, | |
| 132 | + ] | |
| 133 | + ); | |
| 134 | + } | |
| 135 | + } | |
| 136 | + return $this->render( | |
| 137 | + 'update', | |
| 138 | + [ | |
| 139 | + 'model' => $model, | |
| 140 | + 'modelLangs' => $model->modelLangs, | |
| 141 | + ] | |
| 142 | + ); | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * Deletes an existing Seo model. | |
| 147 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
| 148 | + * | |
| 149 | + * @param integer $id | |
| 150 | + * | |
| 151 | + * @return mixed | |
| 152 | + */ | |
| 153 | + public function actionDelete($id) | |
| 154 | + { | |
| 155 | + $this->findModel($id) | |
| 156 | + ->delete(); | |
| 157 | + | |
| 158 | + return $this->redirect([ 'index' ]); | |
| 159 | + } | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * Finds the Seo model based on its primary key value. | |
| 163 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
| 164 | + * | |
| 165 | + * @param integer $id | |
| 166 | + * | |
| 167 | + * @return Seo the loaded model | |
| 168 | + * @throws NotFoundHttpException if the model cannot be found | |
| 169 | + */ | |
| 170 | + protected function findModel($id) | |
| 171 | + { | |
| 172 | + if (( $model = Seo::find() | |
| 173 | + ->where([ 'id' => $id ]) | |
| 174 | + ->with('lang') | |
| 175 | + ->one() ) !== null | |
| 176 | + ) { | |
| 177 | + return $model; | |
| 178 | + } else { | |
| 179 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 180 | + } | |
| 181 | + } | |
| 182 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace backend\controllers; | |
| 4 | + | |
| 5 | + use artweb\artbox\models\SeoCategory; | |
| 6 | + use Yii; | |
| 7 | + use artweb\artbox\models\SeoDynamic; | |
| 8 | + use artweb\artbox\models\SeoDynamicSearch; | |
| 9 | + use yii\web\Controller; | |
| 10 | + use yii\web\NotFoundHttpException; | |
| 11 | + use yii\filters\VerbFilter; | |
| 12 | + use developeruz\db_rbac\behaviors\AccessBehavior; | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * SeoDynamicController implements the CRUD actions for SeoDynamic model. | |
| 16 | + */ | |
| 17 | + class SeoDynamicController extends Controller | |
| 18 | + { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * @inheritdoc | |
| 22 | + */ | |
| 23 | + public function behaviors() | |
| 24 | + { | |
| 25 | + return [ | |
| 26 | + 'access' => [ | |
| 27 | + 'class' => AccessBehavior::className(), | |
| 28 | + 'rules' => [ | |
| 29 | + 'site' => [ | |
| 30 | + [ | |
| 31 | + 'actions' => [ | |
| 32 | + 'login', | |
| 33 | + 'error', | |
| 34 | + ], | |
| 35 | + 'allow' => true, | |
| 36 | + ], | |
| 37 | + ], | |
| 38 | + ], | |
| 39 | + ], | |
| 40 | + 'verbs' => [ | |
| 41 | + 'class' => VerbFilter::className(), | |
| 42 | + | |
| 43 | + ], | |
| 44 | + ]; | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Lists all SeoDynamic models. | |
| 49 | + * | |
| 50 | + * @param int $seo_category_id | |
| 51 | + * | |
| 52 | + * @return mixed | |
| 53 | + */ | |
| 54 | + public function actionIndex($seo_category_id) | |
| 55 | + { | |
| 56 | + $seo_category = $this->findCategory($seo_category_id); | |
| 57 | + $searchModel = new SeoDynamicSearch(); | |
| 58 | + $dataProvider = $searchModel->search($seo_category_id, Yii::$app->request->queryParams); | |
| 59 | + | |
| 60 | + return $this->render( | |
| 61 | + 'index', | |
| 62 | + [ | |
| 63 | + 'searchModel' => $searchModel, | |
| 64 | + 'dataProvider' => $dataProvider, | |
| 65 | + 'seo_category' => $seo_category, | |
| 66 | + ] | |
| 67 | + ); | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * Displays a single SeoDynamic model. | |
| 72 | + * | |
| 73 | + * @param integer $seo_category_id | |
| 74 | + * @param integer $id | |
| 75 | + * | |
| 76 | + * @return mixed | |
| 77 | + */ | |
| 78 | + public function actionView($seo_category_id, $id) | |
| 79 | + { | |
| 80 | + $seo_category = $this->findCategory($seo_category_id); | |
| 81 | + return $this->render( | |
| 82 | + 'view', | |
| 83 | + [ | |
| 84 | + 'model' => $this->findModel($id), | |
| 85 | + 'seo_category' => $seo_category, | |
| 86 | + ] | |
| 87 | + ); | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Creates a new SeoDynamic model. | |
| 92 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
| 93 | + * | |
| 94 | + * @param integer $seo_category_id | |
| 95 | + * | |
| 96 | + * @return mixed | |
| 97 | + */ | |
| 98 | + public function actionCreate($seo_category_id) | |
| 99 | + { | |
| 100 | + $seo_category = $this->findCategory($seo_category_id); | |
| 101 | + $model = new SeoDynamic(); | |
| 102 | + $model->generateLangs(); | |
| 103 | + if ($model->load(Yii::$app->request->post())) { | |
| 104 | + $model->loadLangs(\Yii::$app->request); | |
| 105 | + $model->seo_category_id = $seo_category_id; | |
| 106 | + if ($model->save() && $model->transactionStatus) { | |
| 107 | + return $this->redirect( | |
| 108 | + [ | |
| 109 | + 'index', | |
| 110 | + 'seo_category_id' => $seo_category_id, | |
| 111 | + ] | |
| 112 | + ); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + return $this->render( | |
| 116 | + 'create', | |
| 117 | + [ | |
| 118 | + 'model' => $model, | |
| 119 | + 'modelLangs' => $model->modelLangs, | |
| 120 | + 'seo_category' => $seo_category, | |
| 121 | + ] | |
| 122 | + ); | |
| 123 | + } | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * Updates an existing SeoDynamic model. | |
| 127 | + * If update is successful, the browser will be redirected to the 'view' page. | |
| 128 | + * | |
| 129 | + * @param integer $seo_category_id | |
| 130 | + * @param integer $id | |
| 131 | + * | |
| 132 | + * @return mixed | |
| 133 | + */ | |
| 134 | + public function actionUpdate($seo_category_id, $id) | |
| 135 | + { | |
| 136 | + $seo_category = $this->findCategory($seo_category_id); | |
| 137 | + $model = $this->findModel($id); | |
| 138 | + $model->generateLangs(); | |
| 139 | + if ($model->load(Yii::$app->request->post())) { | |
| 140 | + $model->loadLangs(\Yii::$app->request); | |
| 141 | + if ($model->save() && $model->transactionStatus) { | |
| 142 | + return $this->redirect( | |
| 143 | + [ | |
| 144 | + 'index', | |
| 145 | + 'seo_category_id' => $seo_category_id, | |
| 146 | + ] | |
| 147 | + ); | |
| 148 | + } | |
| 149 | + } | |
| 150 | + return $this->render( | |
| 151 | + 'update', | |
| 152 | + [ | |
| 153 | + 'model' => $model, | |
| 154 | + 'modelLangs' => $model->modelLangs, | |
| 155 | + 'seo_category' => $seo_category, | |
| 156 | + ] | |
| 157 | + ); | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Deletes an existing SeoDynamic model. | |
| 162 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
| 163 | + * | |
| 164 | + * @param integer $seo_category_id | |
| 165 | + * @param integer $id | |
| 166 | + * | |
| 167 | + * @return mixed | |
| 168 | + */ | |
| 169 | + public function actionDelete($seo_category_id, $id) | |
| 170 | + { | |
| 171 | + $this->findModel($id) | |
| 172 | + ->delete(); | |
| 173 | + | |
| 174 | + return $this->redirect( | |
| 175 | + [ | |
| 176 | + 'index', | |
| 177 | + 'seo_category_id' => $seo_category_id, | |
| 178 | + ] | |
| 179 | + ); | |
| 180 | + } | |
| 181 | + | |
| 182 | + /** | |
| 183 | + * Finds the SeoDynamic model based on its primary key value. | |
| 184 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
| 185 | + * | |
| 186 | + * @param integer $id | |
| 187 | + * | |
| 188 | + * @return SeoDynamic the loaded model | |
| 189 | + * @throws NotFoundHttpException if the model cannot be found | |
| 190 | + */ | |
| 191 | + protected function findModel($id) | |
| 192 | + { | |
| 193 | + if (( $model = SeoDynamic::find() | |
| 194 | + ->where([ 'id' => $id ]) | |
| 195 | + ->with('lang') | |
| 196 | + ->one() ) !== null | |
| 197 | + ) { | |
| 198 | + return $model; | |
| 199 | + } else { | |
| 200 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 201 | + } | |
| 202 | + } | |
| 203 | + | |
| 204 | + protected function findCategory($id) | |
| 205 | + { | |
| 206 | + if (( $model = SeoCategory::find() | |
| 207 | + ->where([ 'id' => $id ]) | |
| 208 | + ->with('lang') | |
| 209 | + ->one() ) !== null | |
| 210 | + ) { | |
| 211 | + return $model; | |
| 212 | + } else { | |
| 213 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 214 | + } | |
| 215 | + } | |
| 216 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\behaviors\LanguageBehavior; | |
| 6 | + use Yii; | |
| 7 | + use yii\db\ActiveQuery; | |
| 8 | + use yii\db\ActiveRecord; | |
| 9 | + use yii\web\Request; | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * This is the model class for table "seo". | |
| 13 | + * | |
| 14 | + * @property integer $id | |
| 15 | + * @property string $url | |
| 16 | + * * From language behavior * | |
| 17 | + * @property SeoLang $lang | |
| 18 | + * @property SeoLang[] $langs | |
| 19 | + * @property SeoLang $objectLang | |
| 20 | + * @property string $ownerKey | |
| 21 | + * @property string $langKey | |
| 22 | + * @property SeoLang[] $modelLangs | |
| 23 | + * @property bool $transactionStatus | |
| 24 | + * @method string getOwnerKey() | |
| 25 | + * @method void setOwnerKey( string $value ) | |
| 26 | + * @method string getLangKey() | |
| 27 | + * @method void setLangKey( string $value ) | |
| 28 | + * @method ActiveQuery getLangs() | |
| 29 | + * @method ActiveQuery getLang( integer $language_id ) | |
| 30 | + * @method SeoLang[] generateLangs() | |
| 31 | + * @method void loadLangs( Request $request ) | |
| 32 | + * @method bool linkLangs() | |
| 33 | + * @method bool saveLangs() | |
| 34 | + * @method bool getTransactionStatus() | |
| 35 | + * * End language behavior * | |
| 36 | + */ | |
| 37 | + class Seo extends ActiveRecord | |
| 38 | + { | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * @inheritdoc | |
| 42 | + */ | |
| 43 | + public static function tableName() | |
| 44 | + { | |
| 45 | + return 'seo'; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public function behaviors() | |
| 49 | + { | |
| 50 | + return [ | |
| 51 | + 'language' => [ | |
| 52 | + 'class' => LanguageBehavior::className(), | |
| 53 | + ], | |
| 54 | + ]; | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * @inheritdoc | |
| 59 | + */ | |
| 60 | + public function rules() | |
| 61 | + { | |
| 62 | + return [ | |
| 63 | + [ | |
| 64 | + [ 'url' ], | |
| 65 | + 'required', | |
| 66 | + ], | |
| 67 | + [ | |
| 68 | + [ 'url' ], | |
| 69 | + 'string', | |
| 70 | + 'max' => 255, | |
| 71 | + ], | |
| 72 | + ]; | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * @inheritdoc | |
| 77 | + */ | |
| 78 | + public function attributeLabels() | |
| 79 | + { | |
| 80 | + return [ | |
| 81 | + 'id' => Yii::t('app', 'seo_id'), | |
| 82 | + 'url' => Yii::t('app', 'url'), | |
| 83 | + ]; | |
| 84 | + } | |
| 85 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\behaviors\LanguageBehavior; | |
| 6 | + use Yii; | |
| 7 | + use yii\db\ActiveQuery; | |
| 8 | + use yii\db\ActiveRecord; | |
| 9 | + use yii\web\Request; | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * This is the model class for table "seo_category". | |
| 13 | + * | |
| 14 | + * @property integer $id | |
| 15 | + * @property string $controller | |
| 16 | + * @property integer $status | |
| 17 | + * * From language behavior * | |
| 18 | + * @property SeoCategoryLang $lang | |
| 19 | + * @property SeoCategoryLang[] $langs | |
| 20 | + * @property SeoCategoryLang $objectLang | |
| 21 | + * @property string $ownerKey | |
| 22 | + * @property string $langKey | |
| 23 | + * @property SeoCategoryLang[] $modelLangs | |
| 24 | + * @property bool $transactionStatus | |
| 25 | + * @method string getOwnerKey() | |
| 26 | + * @method void setOwnerKey( string $value ) | |
| 27 | + * @method string getLangKey() | |
| 28 | + * @method void setLangKey( string $value ) | |
| 29 | + * @method ActiveQuery getLangs() | |
| 30 | + * @method ActiveQuery getLang( integer $language_id ) | |
| 31 | + * @method SeoCategoryLang[] generateLangs() | |
| 32 | + * @method void loadLangs( Request $request ) | |
| 33 | + * @method bool linkLangs() | |
| 34 | + * @method bool saveLangs() | |
| 35 | + * @method bool getTransactionStatus() | |
| 36 | + * * End language behavior * | |
| 37 | + * @property SeoDynamic[] $seoDynamics | |
| 38 | + */ | |
| 39 | + class SeoCategory extends ActiveRecord | |
| 40 | + { | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * @inheritdoc | |
| 44 | + */ | |
| 45 | + public static function tableName() | |
| 46 | + { | |
| 47 | + return 'seo_category'; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public function behaviors() | |
| 51 | + { | |
| 52 | + return [ | |
| 53 | + 'language' => [ | |
| 54 | + 'class' => LanguageBehavior::className(), | |
| 55 | + ], | |
| 56 | + ]; | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * @inheritdoc | |
| 61 | + */ | |
| 62 | + public function rules() | |
| 63 | + { | |
| 64 | + return [ | |
| 65 | + [ | |
| 66 | + [ 'status' ], | |
| 67 | + 'integer', | |
| 68 | + ], | |
| 69 | + [ | |
| 70 | + [ 'controller' ], | |
| 71 | + 'string', | |
| 72 | + 'max' => 100, | |
| 73 | + ], | |
| 74 | + ]; | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * @inheritdoc | |
| 79 | + */ | |
| 80 | + public function attributeLabels() | |
| 81 | + { | |
| 82 | + return [ | |
| 83 | + 'id' => Yii::t('app', 'seo_category_id'), | |
| 84 | + 'controller' => Yii::t('app', 'controller'), | |
| 85 | + 'status' => Yii::t('app', 'status'), | |
| 86 | + ]; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * @return \yii\db\ActiveQuery | |
| 91 | + */ | |
| 92 | + public function getSeoDynamics() | |
| 93 | + { | |
| 94 | + return $this->hasMany(SeoDynamic::className(), [ 'seo_category_id' => 'id' ]); | |
| 95 | + } | |
| 96 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\models\Language; | |
| 6 | + use Yii; | |
| 7 | + use yii\db\ActiveRecord; | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * This is the model class for table "seo_category_lang". | |
| 11 | + * | |
| 12 | + * @property integer $seo_category_id | |
| 13 | + * @property integer $language_id | |
| 14 | + * @property string $title | |
| 15 | + * @property Language $language | |
| 16 | + * @property SeoCategory $seoCategory | |
| 17 | + */ | |
| 18 | + class SeoCategoryLang extends ActiveRecord | |
| 19 | + { | |
| 20 | + | |
| 21 | + public static function primaryKey() | |
| 22 | + { | |
| 23 | + return [ | |
| 24 | + 'seo_category_id', | |
| 25 | + 'language_id', | |
| 26 | + ]; | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * @inheritdoc | |
| 31 | + */ | |
| 32 | + public static function tableName() | |
| 33 | + { | |
| 34 | + return 'seo_category_lang'; | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * @inheritdoc | |
| 39 | + */ | |
| 40 | + public function rules() | |
| 41 | + { | |
| 42 | + return [ | |
| 43 | + [ | |
| 44 | + [ 'title' ], | |
| 45 | + 'string', | |
| 46 | + 'max' => 255, | |
| 47 | + ], | |
| 48 | + [ | |
| 49 | + [ | |
| 50 | + 'seo_category_id', | |
| 51 | + 'language_id', | |
| 52 | + ], | |
| 53 | + 'unique', | |
| 54 | + 'targetAttribute' => [ | |
| 55 | + 'seo_category_id', | |
| 56 | + 'language_id', | |
| 57 | + ], | |
| 58 | + 'message' => 'The combination of Seo Category ID and Language ID has already been taken.', | |
| 59 | + ], | |
| 60 | + [ | |
| 61 | + [ 'language_id' ], | |
| 62 | + 'exist', | |
| 63 | + 'skipOnError' => true, | |
| 64 | + 'targetClass' => Language::className(), | |
| 65 | + 'targetAttribute' => [ 'language_id' => 'id' ], | |
| 66 | + ], | |
| 67 | + [ | |
| 68 | + [ 'seo_category_id' ], | |
| 69 | + 'exist', | |
| 70 | + 'skipOnError' => true, | |
| 71 | + 'targetClass' => SeoCategory::className(), | |
| 72 | + 'targetAttribute' => [ 'seo_category_id' => 'id' ], | |
| 73 | + ], | |
| 74 | + ]; | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * @inheritdoc | |
| 79 | + */ | |
| 80 | + public function attributeLabels() | |
| 81 | + { | |
| 82 | + return [ | |
| 83 | + 'seo_category_id' => Yii::t('app', 'seo_category_id'), | |
| 84 | + 'language_id' => Yii::t('app', 'language_id'), | |
| 85 | + 'title' => Yii::t('app', 'name'), | |
| 86 | + ]; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * @return \yii\db\ActiveQuery | |
| 91 | + */ | |
| 92 | + public function getLanguage() | |
| 93 | + { | |
| 94 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * @return \yii\db\ActiveQuery | |
| 99 | + */ | |
| 100 | + public function getSeoCategory() | |
| 101 | + { | |
| 102 | + return $this->hasOne(SeoCategory::className(), [ 'id' => 'seo_category_id' ]); | |
| 103 | + } | |
| 104 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use yii\base\Model; | |
| 6 | + use yii\data\ActiveDataProvider; | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * SeoCategorySearch represents the model behind the search form about | |
| 10 | + * `artweb\artbox\models\SeoCategory`. | |
| 11 | + */ | |
| 12 | + class SeoCategorySearch extends SeoCategory | |
| 13 | + { | |
| 14 | + | |
| 15 | + public $title; | |
| 16 | + | |
| 17 | + public function behaviors() | |
| 18 | + { | |
| 19 | + return []; | |
| 20 | + } | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * @inheritdoc | |
| 24 | + */ | |
| 25 | + public function rules() | |
| 26 | + { | |
| 27 | + return [ | |
| 28 | + [ | |
| 29 | + [ | |
| 30 | + 'id', | |
| 31 | + 'status', | |
| 32 | + ], | |
| 33 | + 'integer', | |
| 34 | + ], | |
| 35 | + [ | |
| 36 | + [ | |
| 37 | + 'controller', | |
| 38 | + 'title', | |
| 39 | + ], | |
| 40 | + 'safe', | |
| 41 | + ], | |
| 42 | + ]; | |
| 43 | + } | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @inheritdoc | |
| 47 | + */ | |
| 48 | + public function scenarios() | |
| 49 | + { | |
| 50 | + // bypass scenarios() implementation in the parent class | |
| 51 | + return Model::scenarios(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Creates data provider instance with search query applied | |
| 56 | + * | |
| 57 | + * @param array $params | |
| 58 | + * | |
| 59 | + * @return ActiveDataProvider | |
| 60 | + */ | |
| 61 | + public function search($params) | |
| 62 | + { | |
| 63 | + $query = SeoCategory::find() | |
| 64 | + ->joinWith('lang'); | |
| 65 | + | |
| 66 | + // add conditions that should always apply here | |
| 67 | + | |
| 68 | + $dataProvider = new ActiveDataProvider( | |
| 69 | + [ | |
| 70 | + 'query' => $query, | |
| 71 | + 'sort' => [ | |
| 72 | + 'attributes' => [ | |
| 73 | + 'id', | |
| 74 | + 'controller', | |
| 75 | + 'status', | |
| 76 | + 'title' => [ | |
| 77 | + 'asc' => [ 'seo_category_lang.title' => SORT_ASC ], | |
| 78 | + 'desc' => [ 'seo_category_lang.title' => SORT_DESC ], | |
| 79 | + ], | |
| 80 | + ], | |
| 81 | + ], | |
| 82 | + ] | |
| 83 | + ); | |
| 84 | + | |
| 85 | + $this->load($params); | |
| 86 | + | |
| 87 | + if (!$this->validate()) { | |
| 88 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 89 | + // $query->where('0=1'); | |
| 90 | + return $dataProvider; | |
| 91 | + } | |
| 92 | + | |
| 93 | + // grid filtering conditions | |
| 94 | + $query->andFilterWhere( | |
| 95 | + [ | |
| 96 | + 'id' => $this->id, | |
| 97 | + 'status' => $this->status, | |
| 98 | + ] | |
| 99 | + ); | |
| 100 | + | |
| 101 | + $query->andFilterWhere( | |
| 102 | + [ | |
| 103 | + 'like', | |
| 104 | + 'controller', | |
| 105 | + $this->controller, | |
| 106 | + ] | |
| 107 | + ) | |
| 108 | + ->andFilterWhere( | |
| 109 | + [ | |
| 110 | + 'ilike', | |
| 111 | + 'seo_category_lang.title', | |
| 112 | + $this->title, | |
| 113 | + ] | |
| 114 | + ); | |
| 115 | + | |
| 116 | + return $dataProvider; | |
| 117 | + } | |
| 118 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\behaviors\LanguageBehavior; | |
| 6 | + use Yii; | |
| 7 | + use yii\db\ActiveQuery; | |
| 8 | + use yii\db\ActiveRecord; | |
| 9 | + use yii\web\Request; | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * This is the model class for table "seo_dynamic". | |
| 13 | + * | |
| 14 | + * @property integer $id | |
| 15 | + * @property integer $seo_category_id | |
| 16 | + * @property string $action | |
| 17 | + * @property string $fields | |
| 18 | + * @property integer $status | |
| 19 | + * @property string $param | |
| 20 | + * * From language behavior * | |
| 21 | + * @property SeoDynamicLang $lang | |
| 22 | + * @property SeoDynamicLang[] $langs | |
| 23 | + * @property SeoDynamicLang $objectLang | |
| 24 | + * @property string $ownerKey | |
| 25 | + * @property string $langKey | |
| 26 | + * @property SeoDynamicLang[] $modelLangs | |
| 27 | + * @property bool $transactionStatus | |
| 28 | + * @method string getOwnerKey() | |
| 29 | + * @method void setOwnerKey( string $value ) | |
| 30 | + * @method string getLangKey() | |
| 31 | + * @method void setLangKey( string $value ) | |
| 32 | + * @method ActiveQuery getLangs() | |
| 33 | + * @method ActiveQuery getLang( integer $language_id ) | |
| 34 | + * @method SeoDynamicLang[] generateLangs() | |
| 35 | + * @method void loadLangs( Request $request ) | |
| 36 | + * @method bool linkLangs() | |
| 37 | + * @method bool saveLangs() | |
| 38 | + * @method bool getTransactionStatus() | |
| 39 | + * * End language behavior * | |
| 40 | + * @property SeoCategory $seoCategory | |
| 41 | + */ | |
| 42 | + class SeoDynamic extends ActiveRecord | |
| 43 | + { | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @inheritdoc | |
| 47 | + */ | |
| 48 | + public static function tableName() | |
| 49 | + { | |
| 50 | + return 'seo_dynamic'; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public function behaviors() | |
| 54 | + { | |
| 55 | + return [ | |
| 56 | + 'language' => [ | |
| 57 | + 'class' => LanguageBehavior::className(), | |
| 58 | + ], | |
| 59 | + ]; | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * @inheritdoc | |
| 64 | + */ | |
| 65 | + public function rules() | |
| 66 | + { | |
| 67 | + return [ | |
| 68 | + [ | |
| 69 | + [ | |
| 70 | + 'seo_category_id', | |
| 71 | + 'status', | |
| 72 | + ], | |
| 73 | + 'integer', | |
| 74 | + ], | |
| 75 | + [ | |
| 76 | + [ | |
| 77 | + 'action', | |
| 78 | + ], | |
| 79 | + 'string', | |
| 80 | + 'max' => 200, | |
| 81 | + ], | |
| 82 | + [ | |
| 83 | + [ | |
| 84 | + 'fields', | |
| 85 | + 'param', | |
| 86 | + ], | |
| 87 | + 'string', | |
| 88 | + 'max' => 255, | |
| 89 | + ], | |
| 90 | + [ | |
| 91 | + [ 'seo_category_id' ], | |
| 92 | + 'exist', | |
| 93 | + 'skipOnError' => true, | |
| 94 | + 'targetClass' => SeoCategory::className(), | |
| 95 | + 'targetAttribute' => [ 'seo_category_id' => 'id' ], | |
| 96 | + ], | |
| 97 | + ]; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * @inheritdoc | |
| 102 | + */ | |
| 103 | + public function attributeLabels() | |
| 104 | + { | |
| 105 | + return [ | |
| 106 | + 'id' => Yii::t('app', 'seo_dynamic_id'), | |
| 107 | + 'seo_category_id' => Yii::t('app', 'seo_category_id'), | |
| 108 | + 'action' => Yii::t('app', 'action'), | |
| 109 | + 'fields' => Yii::t('app', 'fields'), | |
| 110 | + 'status' => Yii::t('app', 'status'), | |
| 111 | + 'param' => Yii::t('app', 'param'), | |
| 112 | + ]; | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * @return \yii\db\ActiveQuery | |
| 117 | + */ | |
| 118 | + public function getSeoCategory() | |
| 119 | + { | |
| 120 | + return $this->hasOne(SeoCategory::className(), [ 'id' => 'seo_category_id' ]); | |
| 121 | + } | |
| 122 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\models\Language; | |
| 6 | + use Yii; | |
| 7 | + use yii\db\ActiveRecord; | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * This is the model class for table "seo_dynamic_lang". | |
| 11 | + * | |
| 12 | + * @property integer $seo_dynamic_id | |
| 13 | + * @property integer $language_id | |
| 14 | + * @property string $title | |
| 15 | + * @property string $meta_title | |
| 16 | + * @property string $h1 | |
| 17 | + * @property string $key | |
| 18 | + * @property string $meta | |
| 19 | + * @property string $meta_description | |
| 20 | + * @property string $seo_text | |
| 21 | + * @property Language $language | |
| 22 | + * @property SeoDynamic $seoDynamic | |
| 23 | + */ | |
| 24 | + class SeoDynamicLang extends ActiveRecord | |
| 25 | + { | |
| 26 | + | |
| 27 | + public static function primaryKey() | |
| 28 | + { | |
| 29 | + return [ | |
| 30 | + 'seo_dynamic_id', | |
| 31 | + 'language_id', | |
| 32 | + ]; | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @inheritdoc | |
| 37 | + */ | |
| 38 | + public static function tableName() | |
| 39 | + { | |
| 40 | + return 'seo_dynamic_lang'; | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @inheritdoc | |
| 45 | + */ | |
| 46 | + public function rules() | |
| 47 | + { | |
| 48 | + return [ | |
| 49 | + [ | |
| 50 | + [ | |
| 51 | + 'meta_title', | |
| 52 | + 'meta_description', | |
| 53 | + 'seo_text', | |
| 54 | + ], | |
| 55 | + 'string', | |
| 56 | + ], | |
| 57 | + [ | |
| 58 | + [ | |
| 59 | + 'title', | |
| 60 | + 'h1', | |
| 61 | + 'key', | |
| 62 | + 'meta', | |
| 63 | + ], | |
| 64 | + 'string', | |
| 65 | + 'max' => 255, | |
| 66 | + ], | |
| 67 | + [ | |
| 68 | + [ | |
| 69 | + 'seo_dynamic_id', | |
| 70 | + 'language_id', | |
| 71 | + ], | |
| 72 | + 'unique', | |
| 73 | + 'targetAttribute' => [ | |
| 74 | + 'seo_dynamic_id', | |
| 75 | + 'language_id', | |
| 76 | + ], | |
| 77 | + 'message' => 'The combination of Seo Dynamic ID and Language ID has already been taken.', | |
| 78 | + ], | |
| 79 | + [ | |
| 80 | + [ 'language_id' ], | |
| 81 | + 'exist', | |
| 82 | + 'skipOnError' => true, | |
| 83 | + 'targetClass' => Language::className(), | |
| 84 | + 'targetAttribute' => [ 'language_id' => 'id' ], | |
| 85 | + ], | |
| 86 | + [ | |
| 87 | + [ 'seo_dynamic_id' ], | |
| 88 | + 'exist', | |
| 89 | + 'skipOnError' => true, | |
| 90 | + 'targetClass' => SeoDynamic::className(), | |
| 91 | + 'targetAttribute' => [ 'seo_dynamic_id' => 'id' ], | |
| 92 | + ], | |
| 93 | + ]; | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * @inheritdoc | |
| 98 | + */ | |
| 99 | + public function attributeLabels() | |
| 100 | + { | |
| 101 | + return [ | |
| 102 | + 'seo_dynamic_id' => Yii::t('app', 'seo_dynamic_id'), | |
| 103 | + 'language_id' => Yii::t('app', 'language_id'), | |
| 104 | + 'title' => Yii::t('app', 'name'), | |
| 105 | + 'meta_title' => Yii::t('app', 'title'), | |
| 106 | + 'h1' => Yii::t('app', 'h1'), | |
| 107 | + 'key' => Yii::t('app', 'key'), | |
| 108 | + 'meta' => Yii::t('app', 'meta'), | |
| 109 | + 'meta_description' => Yii::t('app', 'meta_description'), | |
| 110 | + 'seo_text' => Yii::t('app', 'seo_text'), | |
| 111 | + ]; | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * @return \yii\db\ActiveQuery | |
| 116 | + */ | |
| 117 | + public function getLanguage() | |
| 118 | + { | |
| 119 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * @return \yii\db\ActiveQuery | |
| 124 | + */ | |
| 125 | + public function getSeoDynamic() | |
| 126 | + { | |
| 127 | + return $this->hasOne(SeoDynamic::className(), [ 'id' => 'seo_dynamic_id' ]); | |
| 128 | + } | |
| 129 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use yii\base\Model; | |
| 6 | + use yii\data\ActiveDataProvider; | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * SeoDynamicSearch represents the model behind the search form about | |
| 10 | + * `artweb\artbox\models\SeoDynamic`. | |
| 11 | + */ | |
| 12 | + class SeoDynamicSearch extends SeoDynamic | |
| 13 | + { | |
| 14 | + | |
| 15 | + public $title; | |
| 16 | + | |
| 17 | + public function behaviors() | |
| 18 | + { | |
| 19 | + return []; | |
| 20 | + } | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * @inheritdoc | |
| 24 | + */ | |
| 25 | + public function rules() | |
| 26 | + { | |
| 27 | + return [ | |
| 28 | + [ | |
| 29 | + [ | |
| 30 | + 'id', | |
| 31 | + 'status', | |
| 32 | + ], | |
| 33 | + 'integer', | |
| 34 | + ], | |
| 35 | + [ | |
| 36 | + [ | |
| 37 | + 'action', | |
| 38 | + 'fields', | |
| 39 | + 'title', | |
| 40 | + 'param', | |
| 41 | + ], | |
| 42 | + 'safe', | |
| 43 | + ], | |
| 44 | + ]; | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * @inheritdoc | |
| 49 | + */ | |
| 50 | + public function scenarios() | |
| 51 | + { | |
| 52 | + // bypass scenarios() implementation in the parent class | |
| 53 | + return Model::scenarios(); | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Creates data provider instance with search query applied | |
| 58 | + * | |
| 59 | + * @param integer $seo_category_id | |
| 60 | + * @param array $params | |
| 61 | + * | |
| 62 | + * @return ActiveDataProvider | |
| 63 | + */ | |
| 64 | + public function search($seo_category_id, $params) | |
| 65 | + { | |
| 66 | + $query = SeoDynamic::find() | |
| 67 | + ->joinWith('lang'); | |
| 68 | + | |
| 69 | + // add conditions that should always apply here | |
| 70 | + | |
| 71 | + $dataProvider = new ActiveDataProvider( | |
| 72 | + [ | |
| 73 | + 'query' => $query, | |
| 74 | + 'sort' => [ | |
| 75 | + 'attributes' => [ | |
| 76 | + 'id', | |
| 77 | + 'action', | |
| 78 | + 'fields', | |
| 79 | + 'status', | |
| 80 | + 'param', | |
| 81 | + 'title' => [ | |
| 82 | + 'asc' => [ 'seo_dynamic_lang.title' => SORT_ASC ], | |
| 83 | + 'desc' => [ 'seo_dynamic_lang.title' => SORT_DESC ], | |
| 84 | + ], | |
| 85 | + ], | |
| 86 | + ], | |
| 87 | + ] | |
| 88 | + ); | |
| 89 | + | |
| 90 | + $this->load($params); | |
| 91 | + | |
| 92 | + if (!$this->validate()) { | |
| 93 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 94 | + // $query->where('0=1'); | |
| 95 | + return $dataProvider; | |
| 96 | + } | |
| 97 | + | |
| 98 | + // grid filtering conditions | |
| 99 | + $query->andWhere( | |
| 100 | + [ | |
| 101 | + 'seo_category_id' => $seo_category_id, | |
| 102 | + ] | |
| 103 | + ) | |
| 104 | + ->andFilterWhere( | |
| 105 | + [ | |
| 106 | + 'id' => $this->id, | |
| 107 | + 'status' => $this->status, | |
| 108 | + ] | |
| 109 | + ); | |
| 110 | + | |
| 111 | + $query->andFilterWhere( | |
| 112 | + [ | |
| 113 | + 'ilike', | |
| 114 | + 'action', | |
| 115 | + $this->action, | |
| 116 | + ] | |
| 117 | + ) | |
| 118 | + ->andFilterWhere( | |
| 119 | + [ | |
| 120 | + 'ilike', | |
| 121 | + 'fields', | |
| 122 | + $this->fields, | |
| 123 | + ] | |
| 124 | + ) | |
| 125 | + ->andFilterWhere( | |
| 126 | + [ | |
| 127 | + 'ilike', | |
| 128 | + 'param', | |
| 129 | + $this->param, | |
| 130 | + ] | |
| 131 | + ) | |
| 132 | + ->andFilterWhere( | |
| 133 | + [ | |
| 134 | + 'ilike', | |
| 135 | + 'seo_dynamic_lang.title', | |
| 136 | + $this->title, | |
| 137 | + ] | |
| 138 | + ); | |
| 139 | + | |
| 140 | + return $dataProvider; | |
| 141 | + } | |
| 142 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\models\Language; | |
| 6 | + use Yii; | |
| 7 | + use yii\db\ActiveRecord; | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * This is the model class for table "seo_lang". | |
| 11 | + * | |
| 12 | + * @property integer $seo_id | |
| 13 | + * @property integer $language_id | |
| 14 | + * @property string $title | |
| 15 | + * @property string $meta_description | |
| 16 | + * @property string $h1 | |
| 17 | + * @property string $meta | |
| 18 | + * @property string $seo_text | |
| 19 | + * @property Language $language | |
| 20 | + * @property Seo $seo | |
| 21 | + */ | |
| 22 | + class SeoLang extends ActiveRecord | |
| 23 | + { | |
| 24 | + | |
| 25 | + public static function primaryKey() | |
| 26 | + { | |
| 27 | + return [ | |
| 28 | + 'seo_id', | |
| 29 | + 'language_id', | |
| 30 | + ]; | |
| 31 | + } | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * @inheritdoc | |
| 35 | + */ | |
| 36 | + public static function tableName() | |
| 37 | + { | |
| 38 | + return 'seo_lang'; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @inheritdoc | |
| 43 | + */ | |
| 44 | + public function rules() | |
| 45 | + { | |
| 46 | + return [ | |
| 47 | + [ | |
| 48 | + [ | |
| 49 | + 'meta_description', | |
| 50 | + 'seo_text', | |
| 51 | + ], | |
| 52 | + 'string', | |
| 53 | + ], | |
| 54 | + [ | |
| 55 | + [ | |
| 56 | + 'title', | |
| 57 | + 'h1', | |
| 58 | + 'meta', | |
| 59 | + ], | |
| 60 | + 'string', | |
| 61 | + 'max' => 255, | |
| 62 | + ], | |
| 63 | + [ | |
| 64 | + [ | |
| 65 | + 'seo_id', | |
| 66 | + 'language_id', | |
| 67 | + ], | |
| 68 | + 'unique', | |
| 69 | + 'targetAttribute' => [ | |
| 70 | + 'seo_id', | |
| 71 | + 'language_id', | |
| 72 | + ], | |
| 73 | + 'message' => 'The combination of Seo ID and Language ID has already been taken.', | |
| 74 | + ], | |
| 75 | + [ | |
| 76 | + [ 'language_id' ], | |
| 77 | + 'exist', | |
| 78 | + 'skipOnError' => true, | |
| 79 | + 'targetClass' => Language::className(), | |
| 80 | + 'targetAttribute' => [ 'language_id' => 'id' ], | |
| 81 | + ], | |
| 82 | + [ | |
| 83 | + [ 'seo_id' ], | |
| 84 | + 'exist', | |
| 85 | + 'skipOnError' => true, | |
| 86 | + 'targetClass' => Seo::className(), | |
| 87 | + 'targetAttribute' => [ 'seo_id' => 'id' ], | |
| 88 | + ], | |
| 89 | + ]; | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * @inheritdoc | |
| 94 | + */ | |
| 95 | + public function attributeLabels() | |
| 96 | + { | |
| 97 | + return [ | |
| 98 | + 'seo_id' => Yii::t('app', 'seo_id'), | |
| 99 | + 'language_id' => Yii::t('app', 'language_id'), | |
| 100 | + 'title' => Yii::t('app', 'title'), | |
| 101 | + 'meta_description' => Yii::t('app', 'meta_description'), | |
| 102 | + 'h1' => Yii::t('app', 'h1'), | |
| 103 | + 'meta' => Yii::t('app', 'meta'), | |
| 104 | + 'seo_text' => Yii::t('app', 'seo_text'), | |
| 105 | + ]; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * @return \yii\db\ActiveQuery | |
| 110 | + */ | |
| 111 | + public function getLanguage() | |
| 112 | + { | |
| 113 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * @return \yii\db\ActiveQuery | |
| 118 | + */ | |
| 119 | + public function getSeo() | |
| 120 | + { | |
| 121 | + return $this->hasOne(Seo::className(), [ 'id' => 'seo_id' ]); | |
| 122 | + } | |
| 123 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\seo\models; | |
| 4 | + | |
| 5 | + use yii\base\Model; | |
| 6 | + use yii\data\ActiveDataProvider; | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * SeoSearch represents the model behind the search form about `artweb\artbox\models\Seo`. | |
| 10 | + */ | |
| 11 | + class SeoSearch extends Seo | |
| 12 | + { | |
| 13 | + | |
| 14 | + public $title; | |
| 15 | + | |
| 16 | + public $meta_description; | |
| 17 | + | |
| 18 | + public $h1; | |
| 19 | + | |
| 20 | + public $meta; | |
| 21 | + | |
| 22 | + public $seo_text; | |
| 23 | + | |
| 24 | + public function behaviors() | |
| 25 | + { | |
| 26 | + return []; | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * @inheritdoc | |
| 31 | + */ | |
| 32 | + public function rules() | |
| 33 | + { | |
| 34 | + return [ | |
| 35 | + [ | |
| 36 | + [ 'id' ], | |
| 37 | + 'integer', | |
| 38 | + ], | |
| 39 | + [ | |
| 40 | + [ | |
| 41 | + 'url', | |
| 42 | + 'title', | |
| 43 | + 'meta_description', | |
| 44 | + 'h1', | |
| 45 | + 'meta', | |
| 46 | + 'seo_text', | |
| 47 | + ], | |
| 48 | + 'safe', | |
| 49 | + ], | |
| 50 | + ]; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @inheritdoc | |
| 55 | + */ | |
| 56 | + public function scenarios() | |
| 57 | + { | |
| 58 | + // bypass scenarios() implementation in the parent class | |
| 59 | + return Model::scenarios(); | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Creates data provider instance with search query applied | |
| 64 | + * | |
| 65 | + * @param array $params | |
| 66 | + * | |
| 67 | + * @return ActiveDataProvider | |
| 68 | + */ | |
| 69 | + public function search($params) | |
| 70 | + { | |
| 71 | + $query = Seo::find() | |
| 72 | + ->joinWith('lang'); | |
| 73 | + | |
| 74 | + // add conditions that should always apply here | |
| 75 | + | |
| 76 | + $dataProvider = new ActiveDataProvider( | |
| 77 | + [ | |
| 78 | + 'query' => $query, | |
| 79 | + 'sort' => [ | |
| 80 | + 'attributes' => [ | |
| 81 | + 'id', | |
| 82 | + 'url', | |
| 83 | + 'title' => [ | |
| 84 | + 'asc' => [ 'seo_lang.title' => SORT_ASC ], | |
| 85 | + 'desc' => [ 'seo_lang.title' => SORT_DESC ], | |
| 86 | + ], | |
| 87 | + 'meta_description' => [ | |
| 88 | + 'asc' => [ 'seo_lang.meta_description' => SORT_ASC ], | |
| 89 | + 'desc' => [ 'seo_lang.meta_description' => SORT_DESC ], | |
| 90 | + ], | |
| 91 | + 'h1' => [ | |
| 92 | + 'asc' => [ 'seo_lang.h1' => SORT_ASC ], | |
| 93 | + 'desc' => [ 'seo_lang.h1' => SORT_DESC ], | |
| 94 | + ], | |
| 95 | + 'meta' => [ | |
| 96 | + 'asc' => [ 'seo_lang.meta' => SORT_ASC ], | |
| 97 | + 'desc' => [ 'seo_lang.meta' => SORT_DESC ], | |
| 98 | + ], | |
| 99 | + 'seo_text' => [ | |
| 100 | + 'asc' => [ 'seo_lang.seo_text' => SORT_ASC ], | |
| 101 | + 'desc' => [ 'seo_lang.seo_text' => SORT_DESC ], | |
| 102 | + ], | |
| 103 | + ], | |
| 104 | + ], | |
| 105 | + ] | |
| 106 | + ); | |
| 107 | + | |
| 108 | + $this->load($params); | |
| 109 | + | |
| 110 | + if (!$this->validate()) { | |
| 111 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 112 | + // $query->where('0=1'); | |
| 113 | + return $dataProvider; | |
| 114 | + } | |
| 115 | + | |
| 116 | + // grid filtering conditions | |
| 117 | + $query->andFilterWhere( | |
| 118 | + [ | |
| 119 | + 'id' => $this->id, | |
| 120 | + ] | |
| 121 | + ); | |
| 122 | + | |
| 123 | + $query->andFilterWhere( | |
| 124 | + [ | |
| 125 | + 'like', | |
| 126 | + 'url', | |
| 127 | + $this->url, | |
| 128 | + ] | |
| 129 | + ) | |
| 130 | + ->andFilterWhere( | |
| 131 | + [ | |
| 132 | + 'ilike', | |
| 133 | + 'seo_lang.title', | |
| 134 | + $this->title, | |
| 135 | + ] | |
| 136 | + ) | |
| 137 | + ->andFilterWhere( | |
| 138 | + [ | |
| 139 | + 'ilike', | |
| 140 | + 'seo_lang.meta_description', | |
| 141 | + $this->meta_description, | |
| 142 | + ] | |
| 143 | + ) | |
| 144 | + ->andFilterWhere( | |
| 145 | + [ | |
| 146 | + 'ilike', | |
| 147 | + 'seo_lang.h1', | |
| 148 | + $this->h1, | |
| 149 | + ] | |
| 150 | + ) | |
| 151 | + ->andFilterWhere( | |
| 152 | + [ | |
| 153 | + 'ilike', | |
| 154 | + 'seo_lang.meta', | |
| 155 | + $this->meta, | |
| 156 | + ] | |
| 157 | + ) | |
| 158 | + ->andFilterWhere( | |
| 159 | + [ | |
| 160 | + 'ilike', | |
| 161 | + 'seo_lang.seo_text', | |
| 162 | + $this->seo_text, | |
| 163 | + ] | |
| 164 | + ); | |
| 165 | + | |
| 166 | + return $dataProvider; | |
| 167 | + } | |
| 168 | + } | ... | ... |
| 1 | +<?php | |
| 2 | +namespace frontend\widgets; | |
| 3 | + | |
| 4 | +use artweb\artbox\seo\models\SeoDynamic; | |
| 5 | +use artweb\artbox\ecommerce\models\Brand; | |
| 6 | +use artweb\artbox\ecommerce\models\TaxGroup; | |
| 7 | +use artweb\artbox\ecommerce\models\TaxOption; | |
| 8 | +use yii\base\Widget; | |
| 9 | +use yii\helpers\ArrayHelper; | |
| 10 | + | |
| 11 | +class Seo extends Widget | |
| 12 | +{ | |
| 13 | + private $url; | |
| 14 | + public $row; | |
| 15 | + public $own_attr; | |
| 16 | + public $fields; | |
| 17 | + public $category_name; | |
| 18 | + public $description; | |
| 19 | + public $title; | |
| 20 | + public $meta; | |
| 21 | + public $seo_text; | |
| 22 | + public $h1; | |
| 23 | + public $key; | |
| 24 | + public $name; | |
| 25 | + public $project_name; | |
| 26 | + public static $optionsList; | |
| 27 | + protected static $check_url; | |
| 28 | + protected static $check_url_bool; | |
| 29 | + | |
| 30 | + | |
| 31 | + const SEO_TEXT = 'seo_text'; | |
| 32 | + const DESCRIPTION = 'description'; | |
| 33 | + const META = 'meta'; | |
| 34 | + const H1 = 'h1'; | |
| 35 | + const TITLE = 'title'; | |
| 36 | + | |
| 37 | + public function init() | |
| 38 | + { | |
| 39 | + $this->url = \Yii::$app->request->url; | |
| 40 | + $this->project_name = \Yii::$app->name; | |
| 41 | + if(empty(self::$optionsList)){ | |
| 42 | + self::$optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); | |
| 43 | + } | |
| 44 | + | |
| 45 | + parent::init(); | |
| 46 | + | |
| 47 | + } | |
| 48 | + | |
| 49 | + | |
| 50 | + public function run() | |
| 51 | + { | |
| 52 | + | |
| 53 | + $seoData = $this->getViewData(); | |
| 54 | + foreach ($seoData as $key => $value) { | |
| 55 | + $this->$key = $value; | |
| 56 | + } | |
| 57 | + | |
| 58 | + | |
| 59 | + switch ($this->row) { | |
| 60 | + case self::SEO_TEXT: | |
| 61 | + | |
| 62 | + | |
| 63 | + $filter = \Yii::$app->request->get('filters', []); | |
| 64 | + $sort = \Yii::$app->request->get('sort', []); | |
| 65 | + $paginate = \Yii::$app->request->get('page', []); | |
| 66 | + | |
| 67 | + if(empty($filter) && empty($sort) && empty($paginate) ){ | |
| 68 | + | |
| 69 | + return $this->selectSeoData(self::SEO_TEXT); | |
| 70 | + | |
| 71 | + } else { | |
| 72 | + | |
| 73 | + $widgetData = static::findSeoByUrl($this->url); | |
| 74 | + | |
| 75 | + $result = ''; | |
| 76 | + | |
| 77 | + if ($widgetData instanceof \artweb\artbox\seo\models\Seo) { | |
| 78 | + | |
| 79 | + $result = $widgetData->{self::SEO_TEXT}; | |
| 80 | + | |
| 81 | + } else { | |
| 82 | + | |
| 83 | + $widgetData = $this->findSeoByDynamic(); | |
| 84 | + | |
| 85 | + if ($widgetData instanceof SeoDynamic) { | |
| 86 | + | |
| 87 | + $result = $widgetData->{self::SEO_TEXT}; | |
| 88 | + | |
| 89 | + } | |
| 90 | + | |
| 91 | + } | |
| 92 | + | |
| 93 | + return $this->replaceData($result); | |
| 94 | + } | |
| 95 | + | |
| 96 | + | |
| 97 | + break; | |
| 98 | + case self::H1: | |
| 99 | + | |
| 100 | + $filter = \Yii::$app->request->get('filters', []); | |
| 101 | + | |
| 102 | + $default = $this->selectSeoData(self::H1); | |
| 103 | + | |
| 104 | + if ($default != $this->{self::H1}) { | |
| 105 | + | |
| 106 | + return $default; | |
| 107 | + | |
| 108 | + | |
| 109 | + } else if(!empty($filter) && !$this->checkFilter($filter)){ | |
| 110 | + | |
| 111 | + $array = $this->arrayBuilder($filter); | |
| 112 | + return $this->getNameString($array); | |
| 113 | + } | |
| 114 | + else { | |
| 115 | + | |
| 116 | + return $default; | |
| 117 | + } | |
| 118 | + break; | |
| 119 | + case self::TITLE: | |
| 120 | + | |
| 121 | + $filter = \Yii::$app->request->get('filters', []); | |
| 122 | + | |
| 123 | + | |
| 124 | + $title = $this->selectSeoData(self::TITLE); | |
| 125 | + | |
| 126 | + | |
| 127 | + if(!empty($filter) && $title == $this->title || !empty($filter) && empty($title)) { | |
| 128 | + | |
| 129 | + $array = $this->arrayBuilder($filter); | |
| 130 | + | |
| 131 | + $title_string = $this->getTitleString($array); | |
| 132 | + | |
| 133 | + if($title_string){ | |
| 134 | + return $title_string; | |
| 135 | + } | |
| 136 | + | |
| 137 | + } | |
| 138 | + | |
| 139 | + if (!empty($title)) { | |
| 140 | + | |
| 141 | + return $title; | |
| 142 | + } else { | |
| 143 | + return $this->project_name; | |
| 144 | + } | |
| 145 | + | |
| 146 | + break; | |
| 147 | + case self::DESCRIPTION: | |
| 148 | + $description = $this->selectSeoData(self::DESCRIPTION); | |
| 149 | + | |
| 150 | + if (!empty($description)) { | |
| 151 | + | |
| 152 | + $this->getView()->registerMetaTag([ | |
| 153 | + 'name' => 'description', | |
| 154 | + 'content' => $description | |
| 155 | + ]); | |
| 156 | + | |
| 157 | + } else { | |
| 158 | + | |
| 159 | + $filter = \Yii::$app->request->get('filters', []); | |
| 160 | + | |
| 161 | + if(!empty($filter)){ | |
| 162 | + $array = $this->arrayBuilder($filter); | |
| 163 | + $this->getView()->registerMetaTag([ | |
| 164 | + 'name' => 'description', | |
| 165 | + 'content' => $this->getDescriptionString($array) | |
| 166 | + ]); | |
| 167 | + } | |
| 168 | + | |
| 169 | + } | |
| 170 | + | |
| 171 | + break; | |
| 172 | + case self::META: | |
| 173 | + | |
| 174 | + $meta = $this->selectSeoData(self::META); | |
| 175 | + | |
| 176 | + $filter = \Yii::$app->request->get('filters', []); | |
| 177 | + $sort = \Yii::$app->request->get('sort', []); | |
| 178 | + $paginate = \Yii::$app->request->get('page', []); | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) { | |
| 183 | + | |
| 184 | + $this->getView()->registerMetaTag([ | |
| 185 | + 'name' => 'robots', | |
| 186 | + 'content' => $meta | |
| 187 | + ]); | |
| 188 | + | |
| 189 | + } else if(!empty($filter['special'])){ | |
| 190 | + | |
| 191 | + $this->getView()->registerMetaTag([ | |
| 192 | + 'name' => 'robots', | |
| 193 | + 'content' => 'noindex,follow' | |
| 194 | + ]); | |
| 195 | + | |
| 196 | + } else if ( | |
| 197 | + isset($filter['brands']) && count($filter['brands']) > 1 | |
| 198 | + || isset($filter) && $this->checkFilter($filter) | |
| 199 | + | |
| 200 | + ) { | |
| 201 | + | |
| 202 | + $this->getView()->registerMetaTag([ | |
| 203 | + 'name' => 'robots', | |
| 204 | + 'content' => 'noindex,nofollow' | |
| 205 | + ]); | |
| 206 | + | |
| 207 | + } else if ( | |
| 208 | + isset($filter['brands']) && count($filter['brands']) > 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 4 | |
| 209 | + || isset($filter) && count($filter, COUNT_RECURSIVE) > 4 | |
| 210 | + || !empty($sort) || !empty($paginate) || isset($filter['prices']) | |
| 211 | + ) { | |
| 212 | + | |
| 213 | + $this->getView()->registerMetaTag([ | |
| 214 | + 'name' => 'robots', | |
| 215 | + 'content' => 'noindex,nofollow' | |
| 216 | + ]); | |
| 217 | + } else { | |
| 218 | + | |
| 219 | + $this->getView()->registerMetaTag([ | |
| 220 | + 'name' => 'robots', | |
| 221 | + 'content' => 'index,follow' | |
| 222 | + ]); | |
| 223 | + } | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + break; | |
| 229 | + } | |
| 230 | + | |
| 231 | + | |
| 232 | + } | |
| 233 | + | |
| 234 | + protected function replaceData($str) | |
| 235 | + { | |
| 236 | + | |
| 237 | + if (!empty($this->fields)) { | |
| 238 | + foreach ($this->fields as $field_name => $field_value) { | |
| 239 | + $str = str_replace('{' . $field_name . '}', $field_value, $str); | |
| 240 | + } | |
| 241 | + } | |
| 242 | + $str = str_replace('{project_name}', $this->project_name, $str); | |
| 243 | + return $str; | |
| 244 | + } | |
| 245 | + | |
| 246 | + protected static function findSeoByUrl($url) | |
| 247 | + { | |
| 248 | + if(empty(self::$check_url_bool)){ | |
| 249 | + self::$check_url = \artweb\artbox\seo\models\Seo::findOne(['url' => $url]); | |
| 250 | + self::$check_url_bool = true; | |
| 251 | + } | |
| 252 | + return self::$check_url; | |
| 253 | + } | |
| 254 | + | |
| 255 | + protected function findSeoByDynamic() | |
| 256 | + { | |
| 257 | + | |
| 258 | + if(!empty($this->key)){ | |
| 259 | + | |
| 260 | + $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]); | |
| 261 | + } else { | |
| 262 | + | |
| 263 | + | |
| 264 | + $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id]); | |
| 265 | + } | |
| 266 | + | |
| 267 | + return $query->one(); | |
| 268 | + } | |
| 269 | + | |
| 270 | + | |
| 271 | + protected function findSeoByDynamicForFilters(){ | |
| 272 | + return SeoDynamic::find()->joinWith('seoCategory')->where(['param' =>'filters'])->one(); | |
| 273 | + } | |
| 274 | + | |
| 275 | + | |
| 276 | + protected function getViewData() | |
| 277 | + { | |
| 278 | + $params = $this->getView()->params; | |
| 279 | + if (isset($params['seo'])) { | |
| 280 | + return $params['seo']; | |
| 281 | + } else { | |
| 282 | + return []; | |
| 283 | + } | |
| 284 | + } | |
| 285 | + | |
| 286 | + protected function selectSeoData($param) | |
| 287 | + { | |
| 288 | + | |
| 289 | + $result = ''; | |
| 290 | + | |
| 291 | + $widgetData = static::findSeoByUrl($this->url); | |
| 292 | + | |
| 293 | + if ($widgetData instanceof \artweb\artbox\seo\models\Seo) { | |
| 294 | + | |
| 295 | + $result = $widgetData->$param; | |
| 296 | + | |
| 297 | + } else if (!empty($this->$param)) { | |
| 298 | + | |
| 299 | + $result = $this->$param; | |
| 300 | + | |
| 301 | + } else { | |
| 302 | + | |
| 303 | + $widgetData = $this->findSeoByDynamic(); | |
| 304 | + | |
| 305 | + if ($widgetData instanceof SeoDynamic) { | |
| 306 | + | |
| 307 | + $result = $widgetData->$param; | |
| 308 | + | |
| 309 | + } | |
| 310 | + | |
| 311 | + } | |
| 312 | + | |
| 313 | + return $this->replaceData($result); | |
| 314 | + | |
| 315 | + } | |
| 316 | + | |
| 317 | + public function getTitleString($array){ | |
| 318 | + // "{Название раздела: Название блока фильтра | Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3} - купить в Киеве, Украине - интернет магазин Лінія Світла"; | |
| 319 | + $row = ''; | |
| 320 | + foreach($array as $name => $field){ | |
| 321 | + | |
| 322 | + if($name == 'category' ){ | |
| 323 | + $row = $field.' | '.$row; | |
| 324 | + } else { | |
| 325 | + $row .= $field['name'] .' '.$field['value'].' | ' ; | |
| 326 | + } | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + } | |
| 331 | + $row = substr($row, 0,-2 ); | |
| 332 | + $row .= " - купить в Киеве, Украине - интернет магазин Лінія Світла"; | |
| 333 | + return $row; | |
| 334 | +// $template = SeoDynamic::find()->select('title')->where(['param' =>'filters'])->one(); | |
| 335 | +// if($template instanceof SeoDynamic){ | |
| 336 | +// foreach ($array as $field_name => $field_value) { | |
| 337 | +// $template->title = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template->title); | |
| 338 | +// } | |
| 339 | +// $template = preg_replace('/\{.[^\}]*\}\s/','',$template->title); | |
| 340 | +// return $template; | |
| 341 | +// } | |
| 342 | +// | |
| 343 | +// return false; | |
| 344 | + | |
| 345 | + } | |
| 346 | + | |
| 347 | + | |
| 348 | + public function getDescriptionString($array){ | |
| 349 | + // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; | |
| 350 | + $row = 'Лучшие цены на '; | |
| 351 | + foreach($array as $name => $field){ | |
| 352 | + | |
| 353 | + if($name == 'category' ){ | |
| 354 | + $row = $field.' | '.$row; | |
| 355 | + } else { | |
| 356 | + $row .= $field['name'] .' '.$field['value'].' | ' ; | |
| 357 | + } | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + } | |
| 362 | + $row = substr($row, 0,-2 ); | |
| 363 | + $row .= ". Лінія Світла"; | |
| 364 | + return $row; | |
| 365 | + | |
| 366 | + } | |
| 367 | + | |
| 368 | + | |
| 369 | + public function getNameString($array){ | |
| 370 | + // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; | |
| 371 | + $row = ''; | |
| 372 | + foreach($array as $name => $field){ | |
| 373 | + | |
| 374 | + if($name == 'category' ){ | |
| 375 | + $row = $field.' | '.$row; | |
| 376 | + } else { | |
| 377 | + $row .= $field['name'] .' '.$field['value'].' | ' ; | |
| 378 | + } | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + } | |
| 383 | + $row = substr($row, 0,-2 ); | |
| 384 | + return $row; | |
| 385 | + | |
| 386 | + } | |
| 387 | + | |
| 388 | + public function arrayBuilder($filter) | |
| 389 | + { | |
| 390 | + | |
| 391 | + $array = [ | |
| 392 | + 'category' => $this->category_name | |
| 393 | + ]; | |
| 394 | + | |
| 395 | + | |
| 396 | + if (isset($filter['brands']) && count($filter['brands']) == 1) { | |
| 397 | + $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); | |
| 398 | + if (!$model instanceof Brand) { | |
| 399 | + | |
| 400 | + \Yii::$app->response->redirect(['/site/error'], 404); | |
| 401 | + } else { | |
| 402 | + $array['brand']['name'] = 'Бренд'; | |
| 403 | + $array['brand']['value'] = $model->name; | |
| 404 | + } | |
| 405 | + | |
| 406 | + } | |
| 407 | + | |
| 408 | + | |
| 409 | + $optionsList = ArrayHelper::map(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(), 'alias', 'name'); | |
| 410 | + | |
| 411 | + | |
| 412 | + foreach ($optionsList as $optionList => $name) { | |
| 413 | + | |
| 414 | + | |
| 415 | + if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) { | |
| 416 | + | |
| 417 | + $model = TaxOption::find()->where(['alias' => $filter[$optionList]])->one(); | |
| 418 | + if (!$model instanceof TaxOption) { | |
| 419 | + | |
| 420 | + \Yii::$app->response->redirect(['site/error'], 404); | |
| 421 | + } else { | |
| 422 | + $array[$optionList]['value'] = $model->value; | |
| 423 | + $array[$optionList]['name'] = $name; | |
| 424 | + } | |
| 425 | + | |
| 426 | + | |
| 427 | + } | |
| 428 | + | |
| 429 | + | |
| 430 | + } | |
| 431 | + | |
| 432 | + return $array; | |
| 433 | + | |
| 434 | + } | |
| 435 | + | |
| 436 | + protected function checkFilter($filter){ | |
| 437 | + foreach(self::$optionsList as $optionList){ | |
| 438 | + | |
| 439 | + if(isset($filter[$optionList]) && count($filter[$optionList]) > 1){ | |
| 440 | + return true; | |
| 441 | + } | |
| 442 | + | |
| 443 | + } | |
| 444 | + return false; | |
| 445 | + } | |
| 446 | + | |
| 447 | + | |
| 448 | +} | |
| 0 | 449 | \ No newline at end of file | ... | ... |