Commit 21f69fb1228a845838853a3229f94a27ecd5981c
1 parent
37586ef6
-Pagination noindex follow
Showing
1 changed file
with
443 additions
and
406 deletions
Show diff stats
frontend/widgets/Seo.php
1 | <?php | 1 | <?php |
2 | -namespace frontend\widgets; | ||
3 | - | ||
4 | -use common\models\SeoDynamic; | ||
5 | -use Yii; | ||
6 | -use common\modules\product\models\Brand; | ||
7 | -use common\modules\rubrication\models\TaxGroup; | ||
8 | -use common\modules\rubrication\models\TaxOption; | ||
9 | -use yii\base\Widget; | ||
10 | -use yii\helpers\ArrayHelper; | ||
11 | -use yii\helpers\Html; | ||
12 | -use yii\helpers\Url; | ||
13 | -use yii\web\HttpException; | ||
14 | - | ||
15 | -class Seo extends Widget | ||
16 | -{ | ||
17 | - private $url; | ||
18 | - public $row; | ||
19 | - public $own_attr; | ||
20 | - public $fields; | ||
21 | - public $category_name; | ||
22 | - public $description; | ||
23 | - public $title; | ||
24 | - public $meta; | ||
25 | - public $seo_text; | ||
26 | - public $h1; | ||
27 | - public $key; | ||
28 | - public $name; | ||
29 | - public $project_name; | ||
30 | - public static $optionsList; | ||
31 | - protected static $check_url; | ||
32 | - protected static $check_url_bool; | ||
33 | - | ||
34 | - | ||
35 | - const SEO_TEXT = 'seo_text'; | ||
36 | - const DESCRIPTION = 'description'; | ||
37 | - const META = 'meta'; | ||
38 | - const H1 = 'h1'; | ||
39 | - const TITLE = 'title'; | ||
40 | - | ||
41 | - public function init() | ||
42 | - { | ||
43 | - $this->url = \Yii::$app->request->url; | ||
44 | - $this->project_name = \Yii::$app->name; | ||
45 | - if(empty(self::$optionsList)){ | ||
46 | - self::$optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); | ||
47 | - } | ||
48 | - | ||
49 | - parent::init(); | ||
50 | - | ||
51 | - } | ||
52 | - | ||
53 | - | ||
54 | - public function run() | 2 | + namespace frontend\widgets; |
3 | + | ||
4 | + use common\models\SeoDynamic; | ||
5 | + use Yii; | ||
6 | + use common\modules\product\models\Brand; | ||
7 | + use common\modules\rubrication\models\TaxGroup; | ||
8 | + use common\modules\rubrication\models\TaxOption; | ||
9 | + use yii\base\Widget; | ||
10 | + use yii\helpers\ArrayHelper; | ||
11 | + use yii\helpers\Html; | ||
12 | + use yii\helpers\Url; | ||
13 | + use yii\web\HttpException; | ||
14 | + | ||
15 | + class Seo extends Widget | ||
55 | { | 16 | { |
56 | - | ||
57 | - $seoData = $this->getViewData(); | ||
58 | - foreach ($seoData as $key => $value) { | ||
59 | - $this->$key = $value; | 17 | + private $url; |
18 | + public $row; | ||
19 | + public $own_attr; | ||
20 | + public $fields; | ||
21 | + public $category_name; | ||
22 | + public $description; | ||
23 | + public $title; | ||
24 | + public $meta; | ||
25 | + public $seo_text; | ||
26 | + public $h1; | ||
27 | + public $key; | ||
28 | + public $name; | ||
29 | + public $project_name; | ||
30 | + public static $optionsList; | ||
31 | + protected static $check_url; | ||
32 | + protected static $check_url_bool; | ||
33 | + | ||
34 | + const SEO_TEXT = 'seo_text'; | ||
35 | + const DESCRIPTION = 'description'; | ||
36 | + const META = 'meta'; | ||
37 | + const H1 = 'h1'; | ||
38 | + const TITLE = 'title'; | ||
39 | + | ||
40 | + public function init() | ||
41 | + { | ||
42 | + $this->url = \Yii::$app->request->url; | ||
43 | + $this->project_name = \Yii::$app->name; | ||
44 | + if (empty(self::$optionsList)) { | ||
45 | + self::$optionsList = ArrayHelper::getColumn( | ||
46 | + TaxGroup::find() | ||
47 | + ->where([ 'is_filter' => 'TRUE' ]) | ||
48 | + ->all(), | ||
49 | + 'alias' | ||
50 | + ); | ||
51 | + } | ||
52 | + | ||
53 | + parent::init(); | ||
54 | + | ||
60 | } | 55 | } |
61 | - | ||
62 | - | ||
63 | - switch ($this->row) { | ||
64 | - case self::SEO_TEXT: | ||
65 | - | ||
66 | - | ||
67 | - $filter = \Yii::$app->request->get('filters', []); | ||
68 | - $sort = \Yii::$app->request->get('sort', []); | ||
69 | - $paginate = \Yii::$app->request->get('page', []); | ||
70 | - | ||
71 | - if(empty($filter) && empty($sort) && empty($paginate) ){ | ||
72 | - | ||
73 | - return $this->selectSeoData(self::SEO_TEXT); | ||
74 | - | ||
75 | - } else { | ||
76 | - | ||
77 | - $widgetData = static::findSeoByUrl($this->url); | ||
78 | - | ||
79 | - $result = ''; | ||
80 | - | ||
81 | - if ($widgetData instanceof \common\models\Seo) { | ||
82 | - | ||
83 | - $result = $widgetData->{self::SEO_TEXT}; | ||
84 | - | 56 | + |
57 | + public function run() | ||
58 | + { | ||
59 | + | ||
60 | + $seoData = $this->getViewData(); | ||
61 | + foreach ($seoData as $key => $value) { | ||
62 | + $this->$key = $value; | ||
63 | + } | ||
64 | + | ||
65 | + switch ($this->row) { | ||
66 | + case self::SEO_TEXT: | ||
67 | + | ||
68 | + $filter = \Yii::$app->request->get('filters', []); | ||
69 | + $sort = \Yii::$app->request->get('sort', []); | ||
70 | + $paginate = \Yii::$app->request->get('page', []); | ||
71 | + | ||
72 | + if (empty($filter) && empty($sort) && empty($paginate)) { | ||
73 | + | ||
74 | + return $this->selectSeoData(self::SEO_TEXT); | ||
75 | + | ||
85 | } else { | 76 | } else { |
86 | - | ||
87 | - $widgetData = $this->findSeoByDynamic(); | ||
88 | - | ||
89 | - if ($widgetData instanceof SeoDynamic) { | ||
90 | - | 77 | + |
78 | + $widgetData = static::findSeoByUrl($this->url); | ||
79 | + | ||
80 | + $result = ''; | ||
81 | + | ||
82 | + if ($widgetData instanceof \common\models\Seo) { | ||
83 | + | ||
91 | $result = $widgetData->{self::SEO_TEXT}; | 84 | $result = $widgetData->{self::SEO_TEXT}; |
92 | - | 85 | + |
86 | + } else { | ||
87 | + | ||
88 | + $widgetData = $this->findSeoByDynamic(); | ||
89 | + | ||
90 | + if ($widgetData instanceof SeoDynamic) { | ||
91 | + | ||
92 | + $result = $widgetData->{self::SEO_TEXT}; | ||
93 | + | ||
94 | + } | ||
95 | + | ||
93 | } | 96 | } |
94 | - | 97 | + |
98 | + return $this->replaceData($result); | ||
95 | } | 99 | } |
96 | - | ||
97 | - return $this->replaceData($result); | ||
98 | - } | ||
99 | - | ||
100 | - | ||
101 | - break; | ||
102 | - case self::H1: | ||
103 | - | ||
104 | - $filter = \Yii::$app->request->get('filters', []); | ||
105 | - | ||
106 | - $default = $this->selectSeoData(self::H1); | ||
107 | - | ||
108 | - if ($default != $this->{self::H1}) { | ||
109 | - | ||
110 | - return $default; | ||
111 | - | ||
112 | - | ||
113 | - } else if(!empty($filter) && !$this->checkFilter($filter)){ | ||
114 | - | ||
115 | - $array = $this->arrayBuilder($filter); | ||
116 | - return $this->getNameString($array); | ||
117 | - } | ||
118 | - else { | ||
119 | - | ||
120 | - return $default; | ||
121 | - } | 100 | + |
122 | break; | 101 | break; |
123 | - case self::TITLE: | ||
124 | - | ||
125 | - $filter = \Yii::$app->request->get('filters', []); | ||
126 | - | ||
127 | - | ||
128 | - $title = $this->selectSeoData(self::TITLE); | ||
129 | - | ||
130 | - | ||
131 | - if(!empty($filter) && $title == $this->title || !empty($filter) && empty($title)) { | ||
132 | - | ||
133 | - $array = $this->arrayBuilder($filter); | ||
134 | - | ||
135 | - $title_string = $this->getTitleString($array); | ||
136 | - | ||
137 | - if($title_string){ | ||
138 | - return $title_string; | 102 | + case self::H1: |
103 | + | ||
104 | + $filter = \Yii::$app->request->get('filters', []); | ||
105 | + | ||
106 | + $default = $this->selectSeoData(self::H1); | ||
107 | + | ||
108 | + if ($default != $this->{self::H1}) { | ||
109 | + | ||
110 | + return $default; | ||
111 | + | ||
112 | + } else if (!empty($filter) && !$this->checkFilter($filter)) { | ||
113 | + | ||
114 | + $array = $this->arrayBuilder($filter); | ||
115 | + return $this->getNameString($array); | ||
116 | + } else { | ||
117 | + | ||
118 | + return $default; | ||
139 | } | 119 | } |
140 | - | ||
141 | - } | ||
142 | - | ||
143 | - if (!empty($title)) { | ||
144 | - | ||
145 | - return $title; | ||
146 | - } else { | ||
147 | - return $this->project_name; | ||
148 | - } | ||
149 | - | ||
150 | - break; | ||
151 | - case self::DESCRIPTION: | ||
152 | - $description = $this->selectSeoData(self::DESCRIPTION); | ||
153 | - | ||
154 | - if (!empty($description)) { | ||
155 | - | ||
156 | - $this->getView()->registerMetaTag([ | ||
157 | - 'name' => 'description', | ||
158 | - 'content' => $description | ||
159 | - ]); | ||
160 | - | ||
161 | - } else { | ||
162 | - | 120 | + break; |
121 | + case self::TITLE: | ||
122 | + | ||
163 | $filter = \Yii::$app->request->get('filters', []); | 123 | $filter = \Yii::$app->request->get('filters', []); |
164 | - | ||
165 | - if(!empty($filter)){ | 124 | + |
125 | + $title = $this->selectSeoData(self::TITLE); | ||
126 | + | ||
127 | + if (!empty($filter) && $title == $this->title || !empty($filter) && empty($title)) { | ||
128 | + | ||
166 | $array = $this->arrayBuilder($filter); | 129 | $array = $this->arrayBuilder($filter); |
167 | - $this->getView()->registerMetaTag([ | ||
168 | - 'name' => 'description', | ||
169 | - 'content' => $this->getDescriptionString($array) | ||
170 | - ]); | 130 | + |
131 | + $title_string = $this->getTitleString($array); | ||
132 | + | ||
133 | + if ($title_string) { | ||
134 | + return $title_string; | ||
135 | + } | ||
136 | + | ||
171 | } | 137 | } |
172 | - | ||
173 | - } | ||
174 | - | ||
175 | - break; | ||
176 | - case self::META: | ||
177 | - | ||
178 | - $meta = $this->selectSeoData(self::META); | ||
179 | - | ||
180 | - $filter = \Yii::$app->request->get('filters', []); | ||
181 | - $sort = \Yii::$app->request->get('sort', []); | ||
182 | - $paginate = \Yii::$app->request->get('page', []); | ||
183 | - | ||
184 | - | ||
185 | - if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) { | ||
186 | - | ||
187 | - $this->getView()->registerMetaTag([ | ||
188 | - 'name' => 'robots', | ||
189 | - 'content' => $meta | ||
190 | - ]); | ||
191 | - | ||
192 | - } else if(!empty($filter['special'])){ | ||
193 | - | ||
194 | - $this->getView()->registerMetaTag([ | ||
195 | - 'name' => 'robots', | ||
196 | - 'content' => 'noindex,follow' | ||
197 | - ]); | ||
198 | - | ||
199 | - } else if ( | ||
200 | - isset($filter['brands']) && count($filter['brands']) > 1 | ||
201 | - || isset($filter) && $this->checkFilter($filter) | ||
202 | - | ||
203 | - ) { | ||
204 | - | ||
205 | - $this->getView()->registerMetaTag([ | ||
206 | - 'name' => 'robots', | ||
207 | - 'content' => 'noindex,nofollow' | ||
208 | - ]); | ||
209 | - | ||
210 | - } else if ( | ||
211 | - isset($filter['brands']) && count($filter['brands']) > 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 4 | ||
212 | - || isset($filter) && count($filter, COUNT_RECURSIVE) > 4 | ||
213 | - || !empty($sort) || !empty($paginate) || isset($filter['prices']) | ||
214 | - ) { | ||
215 | - | ||
216 | - $this->getView()->registerMetaTag([ | ||
217 | - 'name' => 'robots', | ||
218 | - 'content' => 'noindex,nofollow' | ||
219 | - ]); | ||
220 | - } else { | ||
221 | - | ||
222 | - $this->getView()->registerMetaTag([ | ||
223 | - 'name' => 'robots', | ||
224 | - 'content' => 'index,follow' | ||
225 | - ]); | 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() | ||
153 | + ->registerMetaTag( | ||
154 | + [ | ||
155 | + 'name' => 'description', | ||
156 | + 'content' => $description, | ||
157 | + ] | ||
158 | + ); | ||
159 | + | ||
160 | + } else { | ||
161 | + | ||
162 | + $filter = \Yii::$app->request->get('filters', []); | ||
163 | + | ||
164 | + if (!empty($filter)) { | ||
165 | + $array = $this->arrayBuilder($filter); | ||
166 | + $this->getView() | ||
167 | + ->registerMetaTag( | ||
168 | + [ | ||
169 | + 'name' => 'description', | ||
170 | + 'content' => $this->getDescriptionString($array), | ||
171 | + ] | ||
172 | + ); | ||
173 | + } | ||
174 | + | ||
175 | + } | ||
176 | + | ||
177 | + break; | ||
178 | + case self::META: | ||
179 | + | ||
180 | + $meta = $this->selectSeoData(self::META); | ||
181 | + | ||
182 | + $filter = \Yii::$app->request->get('filters', []); | ||
183 | + $sort = \Yii::$app->request->get('sort', []); | ||
184 | + $paginate = \Yii::$app->request->get('page', []); | ||
185 | + | ||
186 | + if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter[ 'prices' ])) { | ||
187 | + $this->getView() | ||
188 | + ->registerMetaTag( | ||
189 | + [ | ||
190 | + 'name' => 'robots', | ||
191 | + 'content' => $meta, | ||
192 | + ] | ||
193 | + ); | ||
194 | + | ||
195 | + } else if (!empty($filter[ 'special' ])) { | ||
196 | + | ||
197 | + $this->getView() | ||
198 | + ->registerMetaTag( | ||
199 | + [ | ||
200 | + 'name' => 'robots', | ||
201 | + 'content' => 'noindex,follow', | ||
202 | + ] | ||
203 | + ); | ||
204 | + | ||
205 | + } else if (isset($filter[ 'brands' ]) && count( | ||
206 | + $filter[ 'brands' ] | ||
207 | + ) > 1 || isset($filter) && $this->checkFilter($filter) | ||
208 | + | ||
209 | + ) { | ||
210 | + | ||
211 | + $this->getView() | ||
212 | + ->registerMetaTag( | ||
213 | + [ | ||
214 | + 'name' => 'robots', | ||
215 | + 'content' => 'noindex,nofollow', | ||
216 | + ] | ||
217 | + ); | ||
218 | + | ||
219 | + } else if (isset($filter[ 'brands' ]) && count($filter[ 'brands' ]) > 1 && isset($filter) && count( | ||
220 | + $filter, | ||
221 | + COUNT_RECURSIVE | ||
222 | + ) >= 4 || isset($filter) && count( | ||
223 | + $filter, | ||
224 | + COUNT_RECURSIVE | ||
225 | + ) > 4 || !empty($sort) || isset($filter[ 'prices' ]) | ||
226 | + ) { | ||
227 | + | ||
228 | + $this->getView() | ||
229 | + ->registerMetaTag( | ||
230 | + [ | ||
231 | + 'name' => 'robots', | ||
232 | + 'content' => 'noindex,nofollow', | ||
233 | + ] | ||
234 | + ); | ||
235 | + } else if (!empty($paginate)) { | ||
236 | + | ||
237 | + $this->getView() | ||
238 | + ->registerMetaTag( | ||
239 | + [ | ||
240 | + 'name' => 'robots', | ||
241 | + 'content' => 'noindex,follow', | ||
242 | + ] | ||
243 | + ); | ||
244 | + } else { | ||
245 | + $this->getView() | ||
246 | + ->registerMetaTag( | ||
247 | + [ | ||
248 | + 'name' => 'robots', | ||
249 | + 'content' => 'index,follow', | ||
250 | + ] | ||
251 | + ); | ||
252 | + } | ||
253 | + | ||
254 | + break; | ||
255 | + } | ||
256 | + | ||
257 | + } | ||
258 | + | ||
259 | + protected function replaceData($str) | ||
260 | + { | ||
261 | + | ||
262 | + if (!empty($this->fields)) { | ||
263 | + foreach ($this->fields as $field_name => $field_value) { | ||
264 | + $str = str_replace('{' . $field_name . '}', $field_value, $str); | ||
226 | } | 265 | } |
227 | - | ||
228 | - | ||
229 | - | ||
230 | - | ||
231 | - break; | 266 | + } |
267 | + $str = str_replace('{project_name}', $this->project_name, $str); | ||
268 | + return $str; | ||
232 | } | 269 | } |
233 | - | ||
234 | - | ||
235 | - } | ||
236 | - | ||
237 | - protected function replaceData($str) | ||
238 | - { | ||
239 | - | ||
240 | - if (!empty($this->fields)) { | ||
241 | - foreach ($this->fields as $field_name => $field_value) { | ||
242 | - $str = str_replace('{' . $field_name . '}', $field_value, $str); | 270 | + |
271 | + protected static function findSeoByUrl($url) | ||
272 | + { | ||
273 | + if (empty(self::$check_url_bool)) { | ||
274 | + self::$check_url = \common\models\Seo::findOne([ 'url' => $url ]); | ||
275 | + self::$check_url_bool = true; | ||
243 | } | 276 | } |
277 | + return self::$check_url; | ||
244 | } | 278 | } |
245 | - $str = str_replace('{project_name}', $this->project_name, $str); | ||
246 | - return $str; | ||
247 | - } | ||
248 | - | ||
249 | - protected static function findSeoByUrl($url) | ||
250 | - { | ||
251 | - if(empty(self::$check_url_bool)){ | ||
252 | - self::$check_url = \common\models\Seo::findOne(['url' => $url]); | ||
253 | - self::$check_url_bool = true; | 279 | + |
280 | + protected function findSeoByDynamic() | ||
281 | + { | ||
282 | + | ||
283 | + if (!empty($this->key)) { | ||
284 | + | ||
285 | + $query = SeoDynamic::find() | ||
286 | + ->joinWith('seoCategory') | ||
287 | + ->where( | ||
288 | + [ | ||
289 | + 'controller' => \Yii::$app->controller->id, | ||
290 | + 'action' => \Yii::$app->controller->action->id, | ||
291 | + 'key' => $this->key, | ||
292 | + ] | ||
293 | + ); | ||
294 | + } else { | ||
295 | + | ||
296 | + $query = SeoDynamic::find() | ||
297 | + ->joinWith('seoCategory') | ||
298 | + ->where( | ||
299 | + [ | ||
300 | + 'controller' => \Yii::$app->controller->id, | ||
301 | + 'action' => \Yii::$app->controller->action->id, | ||
302 | + ] | ||
303 | + ); | ||
304 | + } | ||
305 | + | ||
306 | + return $query->one(); | ||
254 | } | 307 | } |
255 | - return self::$check_url; | ||
256 | - } | ||
257 | - | ||
258 | - protected function findSeoByDynamic() | ||
259 | - { | ||
260 | - | ||
261 | - if(!empty($this->key)){ | ||
262 | - | ||
263 | - $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]); | ||
264 | - } else { | ||
265 | - | ||
266 | - | ||
267 | - $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id]); | 308 | + |
309 | + protected function findSeoByDynamicForFilters() | ||
310 | + { | ||
311 | + return SeoDynamic::find() | ||
312 | + ->joinWith('seoCategory') | ||
313 | + ->where([ 'param' => 'filters' ]) | ||
314 | + ->one(); | ||
268 | } | 315 | } |
269 | - | ||
270 | - return $query->one(); | ||
271 | - } | ||
272 | - | ||
273 | - | ||
274 | - protected function findSeoByDynamicForFilters(){ | ||
275 | - return SeoDynamic::find()->joinWith('seoCategory')->where(['param' =>'filters'])->one(); | ||
276 | - } | ||
277 | - | ||
278 | - | ||
279 | - protected function getViewData() | ||
280 | - { | ||
281 | - $params = $this->getView()->params; | ||
282 | - if (isset($params['seo'])) { | ||
283 | - return $params['seo']; | ||
284 | - } else { | ||
285 | - return []; | 316 | + |
317 | + protected function getViewData() | ||
318 | + { | ||
319 | + $params = $this->getView()->params; | ||
320 | + if (isset($params[ 'seo' ])) { | ||
321 | + return $params[ 'seo' ]; | ||
322 | + } else { | ||
323 | + return []; | ||
324 | + } | ||
286 | } | 325 | } |
287 | - } | ||
288 | - | ||
289 | - protected function selectSeoData($param) | ||
290 | - { | ||
291 | - | ||
292 | - $result = ''; | ||
293 | - | ||
294 | - $widgetData = static::findSeoByUrl($this->url); | ||
295 | - | ||
296 | - $seoDynamicData = $this->findSeoByDynamic(); | ||
297 | 326 | ||
298 | - if ($widgetData instanceof \common\models\Seo) { | ||
299 | - | ||
300 | - $result = $widgetData->$param; | ||
301 | - | ||
302 | - } else if ($seoDynamicData instanceof SeoDynamic) { | 327 | + protected function selectSeoData($param) |
328 | + { | ||
303 | 329 | ||
304 | - $result = $seoDynamicData->$param; | ||
305 | - | ||
306 | - } else if (!empty($this->$param)) { | ||
307 | - | ||
308 | - $result = $this->$param; | ||
309 | - | ||
310 | - } else { | ||
311 | $result = ''; | 330 | $result = ''; |
312 | - } | ||
313 | - | ||
314 | - return $this->replaceData($result); | ||
315 | - | ||
316 | - } | ||
317 | - | ||
318 | - public function getTitleString($array){ | ||
319 | - // "{Название раздела: Название блока фильтра | Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3} - купить в Киеве, Украине - интернет магазин Лінія Світла"; | ||
320 | - $row = ''; | ||
321 | - foreach($array as $name => $field){ | ||
322 | - | ||
323 | - if($name == 'category' ){ | ||
324 | - $row = $field.' | '.$row; | 331 | + |
332 | + $widgetData = static::findSeoByUrl($this->url); | ||
333 | + | ||
334 | + $seoDynamicData = $this->findSeoByDynamic(); | ||
335 | + | ||
336 | + if ($widgetData instanceof \common\models\Seo) { | ||
337 | + | ||
338 | + $result = $widgetData->$param; | ||
339 | + | ||
340 | + } else if ($seoDynamicData instanceof SeoDynamic) { | ||
341 | + | ||
342 | + $result = $seoDynamicData->$param; | ||
343 | + | ||
344 | + } else if (!empty($this->$param)) { | ||
345 | + | ||
346 | + $result = $this->$param; | ||
347 | + | ||
325 | } else { | 348 | } else { |
326 | - $row .= $field['name'] .' '.$field['value'].' | ' ; | 349 | + $result = ''; |
327 | } | 350 | } |
328 | - | ||
329 | - | ||
330 | - | 351 | + |
352 | + return $this->replaceData($result); | ||
353 | + | ||
331 | } | 354 | } |
332 | - $row = substr($row, 0,-2 ); | ||
333 | - $row .= " - купить в Киеве, Украине - интернет магазин Лінія Світла"; | ||
334 | - return $row; | ||
335 | -// $template = SeoDynamic::find()->select('title')->where(['param' =>'filters'])->one(); | ||
336 | -// if($template instanceof SeoDynamic){ | ||
337 | -// foreach ($array as $field_name => $field_value) { | ||
338 | -// $template->title = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template->title); | ||
339 | -// } | ||
340 | -// $template = preg_replace('/\{.[^\}]*\}\s/','',$template->title); | ||
341 | -// return $template; | ||
342 | -// } | ||
343 | -// | ||
344 | -// return false; | ||
345 | - | ||
346 | - } | ||
347 | - | ||
348 | - | ||
349 | - public function getDescriptionString($array){ | ||
350 | - // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; | ||
351 | - $row = 'Лучшие цены на '; | ||
352 | - foreach($array as $name => $field){ | ||
353 | - | ||
354 | - if($name == 'category' ){ | ||
355 | - $row = $field.' | '.$row; | ||
356 | - } else { | ||
357 | - $row .= $field['name'] .' '.$field['value'].' | ' ; | 355 | + |
356 | + public function getTitleString($array) | ||
357 | + { | ||
358 | + // "{Название раздела: Название блока фильтра | Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3} - купить в Киеве, Украине - интернет магазин Лінія Світла"; | ||
359 | + $row = ''; | ||
360 | + foreach ($array as $name => $field) { | ||
361 | + | ||
362 | + if ($name == 'category') { | ||
363 | + $row = $field . ' | ' . $row; | ||
364 | + } else { | ||
365 | + $row .= $field[ 'name' ] . ' ' . $field[ 'value' ] . ' | '; | ||
366 | + } | ||
367 | + | ||
358 | } | 368 | } |
359 | - | ||
360 | - | ||
361 | - | 369 | + $row = substr($row, 0, -2); |
370 | + $row .= " - купить в Киеве, Украине - интернет магазин Лінія Світла"; | ||
371 | + return $row; | ||
372 | + // $template = SeoDynamic::find()->select('title')->where(['param' =>'filters'])->one(); | ||
373 | + // if($template instanceof SeoDynamic){ | ||
374 | + // foreach ($array as $field_name => $field_value) { | ||
375 | + // $template->title = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template->title); | ||
376 | + // } | ||
377 | + // $template = preg_replace('/\{.[^\}]*\}\s/','',$template->title); | ||
378 | + // return $template; | ||
379 | + // } | ||
380 | + // | ||
381 | + // return false; | ||
382 | + | ||
362 | } | 383 | } |
363 | - $row = substr($row, 0,-2 ); | ||
364 | - $row .= ". Лінія Світла"; | ||
365 | - return $row; | ||
366 | - | ||
367 | - } | ||
368 | - | ||
369 | - | ||
370 | - public function getNameString($array){ | ||
371 | - // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; | ||
372 | - $row = ''; | ||
373 | - foreach($array as $name => $field){ | ||
374 | - | ||
375 | - if($name == 'category' ){ | ||
376 | - $row = $field.' | '.$row; | ||
377 | - } else { | ||
378 | - $row .= $field['name'] .' '.$field['value'].' | ' ; | 384 | + |
385 | + public function getDescriptionString($array) | ||
386 | + { | ||
387 | + // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; | ||
388 | + $row = 'Лучшие цены на '; | ||
389 | + foreach ($array as $name => $field) { | ||
390 | + | ||
391 | + if ($name == 'category') { | ||
392 | + $row = $field . ' | ' . $row; | ||
393 | + } else { | ||
394 | + $row .= $field[ 'name' ] . ' ' . $field[ 'value' ] . ' | '; | ||
395 | + } | ||
396 | + | ||
379 | } | 397 | } |
380 | - | ||
381 | - | ||
382 | - | 398 | + $row = substr($row, 0, -2); |
399 | + $row .= ". Лінія Світла"; | ||
400 | + return $row; | ||
401 | + | ||
383 | } | 402 | } |
384 | - $row = substr($row, 0,-2 ); | ||
385 | - return $row; | ||
386 | - | ||
387 | - } | ||
388 | - | ||
389 | - public function arrayBuilder($filter) | ||
390 | - { | ||
391 | - | 403 | + |
404 | + public function getNameString($array) | ||
405 | + { | ||
406 | + // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; | ||
407 | + $row = ''; | ||
408 | + foreach ($array as $name => $field) { | ||
409 | + | ||
410 | + if ($name == 'category') { | ||
411 | + $row = $field . ' | ' . $row; | ||
412 | + } else { | ||
413 | + $row .= $field[ 'name' ] . ' ' . $field[ 'value' ] . ' | '; | ||
414 | + } | ||
415 | + | ||
416 | + } | ||
417 | + $row = substr($row, 0, -2); | ||
418 | + return $row; | ||
419 | + | ||
420 | + } | ||
421 | + | ||
422 | + public function arrayBuilder($filter) | ||
423 | + { | ||
424 | + | ||
392 | $array = [ | 425 | $array = [ |
393 | - 'category' => $this->category_name | 426 | + 'category' => $this->category_name, |
394 | ]; | 427 | ]; |
395 | - | ||
396 | - | ||
397 | - if (isset($filter['brands']) && count($filter['brands']) == 1) { | ||
398 | - $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); | 428 | + |
429 | + if (isset($filter[ 'brands' ]) && count($filter[ 'brands' ]) == 1) { | ||
430 | + $model = Brand::find() | ||
431 | + ->where([ 'alias' => $filter[ 'brands' ][ 0 ] ]) | ||
432 | + ->one(); | ||
399 | if (!$model instanceof Brand) { | 433 | if (!$model instanceof Brand) { |
400 | - | ||
401 | - \Yii::$app->response->redirect(['/site/error'], 404); | 434 | + |
435 | + \Yii::$app->response->redirect([ '/site/error' ], 404); | ||
402 | } else { | 436 | } else { |
403 | - $array['brand']['name'] = 'Бренд'; | ||
404 | - $array['brand']['value'] = $model->name; | 437 | + $array[ 'brand' ][ 'name' ] = 'Бренд'; |
438 | + $array[ 'brand' ][ 'value' ] = $model->name; | ||
405 | } | 439 | } |
406 | - | 440 | + |
407 | } | 441 | } |
408 | - | ||
409 | - | ||
410 | - $optionsList = ArrayHelper::map(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(), 'alias', 'name'); | ||
411 | - | ||
412 | - | 442 | + |
443 | + $optionsList = ArrayHelper::map( | ||
444 | + TaxGroup::find() | ||
445 | + ->where([ 'is_filter' => 'TRUE' ]) | ||
446 | + ->all(), | ||
447 | + 'alias', | ||
448 | + 'name' | ||
449 | + ); | ||
450 | + | ||
413 | foreach ($optionsList as $optionList => $name) { | 451 | foreach ($optionsList as $optionList => $name) { |
414 | - | ||
415 | - | ||
416 | - if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) { | ||
417 | - | ||
418 | - $model = TaxOption::find()->where(['alias' => $filter[$optionList]])->one(); | 452 | + |
453 | + if (isset($filter[ $optionList ]) && count($filter[ $optionList ]) == 1) { | ||
454 | + | ||
455 | + $model = TaxOption::find() | ||
456 | + ->where([ 'alias' => $filter[ $optionList ] ]) | ||
457 | + ->one(); | ||
419 | if (!$model instanceof TaxOption) { | 458 | if (!$model instanceof TaxOption) { |
420 | - | ||
421 | - \Yii::$app->response->redirect(['site/error'], 404); | 459 | + |
460 | + \Yii::$app->response->redirect([ 'site/error' ], 404); | ||
422 | } else { | 461 | } else { |
423 | - $array[$optionList]['value'] = $model->value; | ||
424 | - $array[$optionList]['name'] = $name; | 462 | + $array[ $optionList ][ 'value' ] = $model->value; |
463 | + $array[ $optionList ][ 'name' ] = $name; | ||
425 | } | 464 | } |
426 | - | ||
427 | - | 465 | + |
428 | } | 466 | } |
429 | - | ||
430 | - | 467 | + |
431 | } | 468 | } |
432 | - | ||
433 | - return $array; | ||
434 | - | ||
435 | - } | ||
436 | - | ||
437 | - protected function checkFilter($filter){ | ||
438 | - foreach(self::$optionsList as $optionList){ | ||
439 | - | ||
440 | - if(isset($filter[$optionList]) && count($filter[$optionList]) > 1){ | ||
441 | - return true; | 469 | + |
470 | + return $array; | ||
471 | + | ||
472 | + } | ||
473 | + | ||
474 | + protected function checkFilter($filter) | ||
475 | + { | ||
476 | + foreach (self::$optionsList as $optionList) { | ||
477 | + | ||
478 | + if (isset($filter[ $optionList ]) && count($filter[ $optionList ]) > 1) { | ||
479 | + return true; | ||
480 | + } | ||
481 | + | ||
442 | } | 482 | } |
443 | - | 483 | + return false; |
444 | } | 484 | } |
445 | - return false; | ||
446 | - } | ||
447 | - | ||
448 | - | ||
449 | -} | ||
450 | \ No newline at end of file | 485 | \ No newline at end of file |
486 | + | ||
487 | + } | ||
451 | \ No newline at end of file | 488 | \ No newline at end of file |