1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Columnis\Model; |
4
|
|
|
|
5
|
|
|
class PageLegacyData { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* |
9
|
|
|
* @var array |
10
|
|
|
*/ |
11
|
|
|
protected $data; |
12
|
|
|
|
13
|
|
|
public function setData($data) { |
14
|
|
|
$this->data = $data; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function __construct($data) { |
18
|
|
|
$this->data = $data; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Get legacy data |
23
|
|
|
* |
24
|
|
|
* @return array |
25
|
|
|
*/ |
26
|
|
|
public function getData() { |
27
|
|
|
$legacyData = [ |
28
|
|
|
"sitio" => [ |
29
|
|
|
"traducciones" => [], |
30
|
|
|
"traducciones_json" => [], |
31
|
|
|
"menus" => [], |
32
|
|
|
"datos_fecha" => [], |
33
|
|
|
"images_path" => '', |
34
|
|
|
"idiomas" => [], |
35
|
|
|
"sitelink" => '', |
36
|
|
|
"head" => [], |
37
|
|
|
], |
38
|
|
|
"modulos" => [], |
39
|
|
|
"pagina" => [], |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
if(is_array($this->data)) { |
43
|
|
|
foreach($this->data as $key => $value) { |
44
|
|
|
|
45
|
|
|
switch($key) { |
46
|
|
|
case 'columnis.rest.pages': |
47
|
|
|
$this->processPageData(array_values($value)[0], $legacyData['pagina']); |
48
|
|
|
break; |
49
|
|
|
case 'columnis.rest.menu_items': |
50
|
|
|
$this->processMenuData(array_values($value)[0], $legacyData['sitio']['menus'][0]); |
51
|
|
|
break; |
52
|
|
|
case 'columnis.rest.configuration': |
53
|
|
|
$this->processConfigurationData(array_values($value)[0], $legacyData); |
54
|
|
|
break; |
55
|
|
|
case 'columnis.rest.translations': |
56
|
|
|
$this->processTranslationsData(array_values($value)[0], $legacyData); |
57
|
|
|
break; |
58
|
|
|
case 'columnis.rest.sections': |
59
|
|
|
$this->processSectionsData($value, $legacyData['modulos']); |
60
|
|
|
break; |
61
|
|
|
case 'columnis.rest.banners': |
62
|
|
|
$this->processBannersData($value, $legacyData['modulos']); |
63
|
|
|
break; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $legacyData; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function processPageData($value, &$pageData) { |
72
|
|
|
|
73
|
|
|
if(!empty($value)) { |
74
|
|
|
$pageData['idPagina'] = $value['id']; |
75
|
|
|
$pageData['template'] = $value['template']; |
76
|
|
|
$pageData['tituloPagina'] = $value['text']; |
77
|
|
|
$pageData['description'] = $value['description']; |
78
|
|
|
$pageData['keywords'] = $value['keywords']; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
protected function processMenuData($values, &$menusData) { |
83
|
|
|
$menusData = [ |
84
|
|
|
'vinculos' => [] |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
if(is_array($values["_embedded"]["menu_items"])) { |
88
|
|
|
foreach($values["_embedded"]["menu_items"] as $menu) { |
89
|
|
|
$menusData['vinculos'][] = [ |
90
|
|
|
"id" => $menu['id'], |
91
|
|
|
"texto" => $menu['text'], |
92
|
|
|
"target" => $menu['target'], |
93
|
|
|
"anclaje" => $menu['anchorage'], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
protected function processConfigurationData($values, &$data) { |
100
|
|
|
|
101
|
|
|
$data["sitio"]["images_path"] = $values["imagesDomain"]; |
102
|
|
|
|
103
|
|
|
$data["sitio"]["head"] = [ |
104
|
|
|
"fixed" => [ |
105
|
|
|
"title" => $values["title"], |
106
|
|
|
"keywords" => $values["keywords"], |
107
|
|
|
"description" => $values["description"] |
108
|
|
|
], |
109
|
|
|
"analytics" => $values["analyticsAccountIds"] |
110
|
|
|
]; |
111
|
|
|
|
112
|
|
|
$data["sitio"]["sitelink"] = $_SERVER['SERVER_NAME']; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
protected function processTranslationsData($values, &$data) { |
116
|
|
|
$translations = []; |
117
|
|
|
|
118
|
|
|
if(is_array($values["_embedded"]["translations"])) { |
119
|
|
|
foreach($values["_embedded"]["translations"] as $translation) { |
120
|
|
|
|
121
|
|
|
if($translation["languageId"] === "es") { |
122
|
|
|
$translations = $translation["translations"]; |
123
|
|
|
break; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$data["sitio"]["traducciones"] = $translations; |
129
|
|
|
$data["sitio"]["traducciones_json"] = json_encode($translations); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
protected function processSectionsData($values, &$modulesData) { |
133
|
|
|
if(!array_key_exists("secciones", $modulesData)) { |
134
|
|
|
$modulesData["secciones"] = []; |
135
|
|
|
}; |
136
|
|
|
|
137
|
|
|
foreach($values as $route => $data) { |
138
|
|
|
$modulesData["secciones"][] = [ |
139
|
|
|
"id" => $data["id"], |
140
|
|
|
"titulo" => $data["title"], |
141
|
|
|
"keywords" => $data["keywords"], |
142
|
|
|
"descripcion" => $data["description"], |
143
|
|
|
"foto" => $this->processPictureData($data["_embedded"]['picture']), |
144
|
|
|
"subSecciones" => $data["subSections"], |
145
|
|
|
]; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
protected function processBannersData($values, &$modulesData) { |
150
|
|
|
if(!array_key_exists("banners", $modulesData)) { |
151
|
|
|
$modulesData["banners"] = [ |
152
|
|
|
"grupos_banners" => [] |
153
|
|
|
]; |
154
|
|
|
}; |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
foreach($values as $bannerGroup) { |
158
|
|
|
$modulesData["banners"]["grupos_banners"][] = [ |
159
|
|
|
"nombre" => "", |
160
|
|
|
"banners" => [] |
161
|
|
|
]; |
162
|
|
|
|
163
|
|
|
$bannerIndex = count($modulesData["banners"]["grupos_banners"]) - 1; |
164
|
|
|
|
165
|
|
|
if(is_array($bannerGroup["_embedded"]["banners"])) { |
166
|
|
|
foreach($bannerGroup["_embedded"]["banners"] as $route => $data) { |
167
|
|
|
|
168
|
|
|
$picture = $this->processPictureData($data["_embedded"]['picture']); |
169
|
|
|
|
170
|
|
|
$modulesData["banners"]["grupos_banners"][$bannerIndex]['banners'][] = [ |
171
|
|
|
"id" => $data["id"], |
172
|
|
|
"titulo" => $data["title"], |
173
|
|
|
"texto" => $data["text"], |
174
|
|
|
"vinculo" => $data["link"], |
175
|
|
|
"descripcion" => $data["description"], |
176
|
|
|
"enImagen" => $data["inImagen"], |
177
|
|
|
"archivo" => is_array($picture) ? $picture["src"] : "", |
178
|
|
|
"foto" => $picture, |
179
|
|
|
]; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
protected function processPictureData($picture) { |
187
|
|
|
if(!is_array($picture)) { |
188
|
|
|
return; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
return [ |
192
|
|
|
"id" => $picture["id"], |
193
|
|
|
"idOriginal" => $picture["id"], |
194
|
|
|
"titulo" => $picture["title"], |
195
|
|
|
"src" => $picture["filename"], |
196
|
|
|
"src_alternativa" => $picture["filename"], |
197
|
|
|
"comentarios" => $picture["description"], |
198
|
|
|
"orden" => $picture["order"], |
199
|
|
|
]; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
?> |
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.