1 | <?php |
||
17 | class ComponentPlugin |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Сохранение связей полей и данных плагинов |
||
22 | * @param $event |
||
23 | * @throws \Exception |
||
24 | */ |
||
25 | public function attach($event) |
||
31 | |||
32 | /** |
||
33 | * Сохранение данных сео-плагина |
||
34 | * @param $event |
||
35 | * @throws \Exception |
||
36 | * @return \Larrock\Core\Models\Seo|Seo|null |
||
37 | */ |
||
38 | protected function attachSeo($event) |
||
39 | { |
||
40 | /** @var Seo $seo */ |
||
41 | $seo = LarrockAdminSeo::getModel()->whereSeoIdConnect($event->model->id)->whereSeoTypeConnect($event->component->name)->first(); |
||
42 | |||
43 | if($seo){ |
||
44 | if( !empty($event->request->get('seo_title')) || |
||
45 | !empty($event->request->get('seo_description')) || |
||
46 | !empty($event->request->get('seo_seo_keywords'))){ |
||
47 | $seo->seo_id_connect = $event->model->id; |
||
48 | $seo->seo_url_connect = $event->request->get('url_connect'); |
||
49 | $seo->seo_title = $event->request->get('seo_title'); |
||
50 | $seo->seo_description = $event->request->get('seo_description'); |
||
51 | $seo->seo_keywords = $event->request->get('seo_keywords'); |
||
52 | $seo->seo_type_connect = $event->component->name; |
||
53 | if($seo->save()){ |
||
54 | MessageLarrock::success('SEO обновлено'); |
||
55 | return $seo; |
||
56 | } |
||
57 | }else{ |
||
58 | $seo->delete(); |
||
59 | MessageLarrock::success('SEO удалено'); |
||
60 | return $seo; |
||
61 | } |
||
62 | }else{ |
||
63 | if( !empty($event->request->get('seo_title')) || |
||
64 | !empty($event->request->get('seo_description')) || |
||
65 | !empty($event->request->get('seo_seo_keywords'))){ |
||
66 | $seo = LarrockAdminSeo::getModel(); |
||
67 | $seo->seo_id_connect = $event->request->get('id_connect'); |
||
68 | $seo->seo_url_connect = $event->request->get('url_connect'); |
||
69 | $seo->seo_title = $event->request->get('seo_title'); |
||
70 | $seo->seo_description = $event->request->get('seo_description'); |
||
71 | $seo->seo_keywords = $event->request->get('seo_keywords'); |
||
72 | $seo->seo_type_connect = $event->request->get('type_connect'); |
||
73 | if($seo->save()){ |
||
74 | MessageLarrock::success('SEO добавлено'); |
||
75 | return $seo; |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | return null; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Создание анонса материала через модуль anonsCategory |
||
84 | * @param $event |
||
85 | * @return bool|Feed|null |
||
86 | * @throws \Exception |
||
87 | */ |
||
88 | protected function attachAnonsModule($event) |
||
119 | |||
120 | /** |
||
121 | * Сохранение связей полей |
||
122 | * @param $event |
||
123 | */ |
||
124 | protected function attachRows($event) |
||
148 | |||
149 | /** |
||
150 | * Удаление всех связей материала компонента |
||
151 | * @param $event |
||
152 | */ |
||
153 | public function detach($event) |
||
158 | |||
159 | /** |
||
160 | * Удаление связей полей |
||
161 | * @param $event |
||
162 | */ |
||
163 | protected function detachRows($event) |
||
189 | |||
190 | /** |
||
191 | * Удаление данных плагинов |
||
192 | * @param $event |
||
193 | */ |
||
194 | protected function detachPlugins($event) |
||
206 | |||
207 | } |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.