1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bpost\BpostApiClient\Geo6; |
4
|
|
|
|
5
|
|
|
use Bpost\BpostApiClient\Exception\BpostApiResponseException\BpostInvalidXmlResponseException; |
6
|
|
|
use SimpleXMLElement; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Geo6 class |
10
|
|
|
* |
11
|
|
|
* @author Tijs Verkoyen <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @version 3.0.0 |
14
|
|
|
* |
15
|
|
|
* @copyright Copyright (c), Tijs Verkoyen. All rights reserved. |
16
|
|
|
* @license BSD License |
17
|
|
|
*/ |
18
|
|
|
class Poi |
19
|
|
|
{ |
20
|
|
|
/** @var string */ |
21
|
|
|
private $id; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
private $type; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
private $office; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
private $street; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
private $nr; |
34
|
|
|
|
35
|
|
|
/** @var string */ |
36
|
|
|
private $zip; |
37
|
|
|
|
38
|
|
|
/** @var string */ |
39
|
|
|
private $city; |
40
|
|
|
|
41
|
|
|
/** @var int */ |
42
|
|
|
private $x; |
43
|
|
|
|
44
|
|
|
/** @var int */ |
45
|
|
|
private $y; |
46
|
|
|
|
47
|
|
|
/** @var float */ |
48
|
|
|
private $latitude; |
49
|
|
|
|
50
|
|
|
/** @var float */ |
51
|
|
|
private $longitude; |
52
|
|
|
|
53
|
|
|
/** @var array */ |
54
|
|
|
private $services; |
55
|
|
|
|
56
|
|
|
/** @var array */ |
57
|
|
|
private $hours; |
58
|
|
|
|
59
|
|
|
/** @var array */ |
60
|
|
|
private $closedFrom; |
61
|
|
|
|
62
|
|
|
/** @var array */ |
63
|
|
|
private $closedTo; |
64
|
|
|
|
65
|
|
|
/** @var string */ |
66
|
|
|
private $note; |
67
|
|
|
|
68
|
|
|
/** @var string */ |
69
|
|
|
private $page; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $city |
73
|
|
|
*/ |
74
|
|
|
public function setCity($city) |
75
|
|
|
{ |
76
|
|
|
$this->city = (string) $city; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getCity() |
83
|
|
|
{ |
84
|
|
|
return $this->city; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param array $closedFrom |
89
|
|
|
*/ |
90
|
|
|
public function setClosedFrom(array $closedFrom) |
91
|
|
|
{ |
92
|
|
|
$this->closedFrom = $closedFrom; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function getClosedFrom() |
99
|
|
|
{ |
100
|
|
|
return $this->closedFrom; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param array $closedTo |
105
|
|
|
*/ |
106
|
|
|
public function setClosedTo(array $closedTo) |
107
|
|
|
{ |
108
|
|
|
$this->closedTo = $closedTo; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return array |
113
|
|
|
*/ |
114
|
|
|
public function getClosedTo() |
115
|
|
|
{ |
116
|
|
|
return $this->closedTo; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param int $index |
121
|
|
|
* @param Day $day |
122
|
|
|
*/ |
123
|
|
|
public function addHour($index, Day $day) |
124
|
|
|
{ |
125
|
|
|
$this->hours[(int) $index] = $day; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param Day[] $hours |
130
|
|
|
*/ |
131
|
|
|
public function setHours(array $hours) |
132
|
|
|
{ |
133
|
|
|
$this->hours = $hours; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return Day[] |
138
|
|
|
*/ |
139
|
|
|
public function getHours() |
140
|
|
|
{ |
141
|
|
|
return $this->hours; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param string $id |
146
|
|
|
*/ |
147
|
|
|
public function setId($id) |
148
|
|
|
{ |
149
|
|
|
$this->id = (string) $id; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
|
|
public function getId() |
156
|
|
|
{ |
157
|
|
|
return $this->id; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param float $latitude |
162
|
|
|
*/ |
163
|
|
|
public function setLatitude($latitude) |
164
|
|
|
{ |
165
|
|
|
$this->latitude = (float) $latitude; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return float |
170
|
|
|
*/ |
171
|
|
|
public function getLatitude() |
172
|
|
|
{ |
173
|
|
|
return $this->latitude; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param float $longitude |
178
|
|
|
*/ |
179
|
|
|
public function setLongitude($longitude) |
180
|
|
|
{ |
181
|
|
|
$this->longitude = (float) $longitude; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return float |
186
|
|
|
*/ |
187
|
|
|
public function getLongitude() |
188
|
|
|
{ |
189
|
|
|
return $this->longitude; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param string $note |
194
|
|
|
*/ |
195
|
|
|
public function setNote($note) |
196
|
|
|
{ |
197
|
|
|
$this->note = (string) $note; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
public function getNote() |
204
|
|
|
{ |
205
|
|
|
return $this->note; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param string $nr |
210
|
|
|
*/ |
211
|
|
|
public function setNr($nr) |
212
|
|
|
{ |
213
|
|
|
$this->nr = (string) $nr; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @return string |
218
|
|
|
*/ |
219
|
|
|
public function getNr() |
220
|
|
|
{ |
221
|
|
|
return $this->nr; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param string $office |
226
|
|
|
*/ |
227
|
|
|
public function setOffice($office) |
228
|
|
|
{ |
229
|
|
|
$this->office = (string) $office; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @return string |
234
|
|
|
*/ |
235
|
|
|
public function getOffice() |
236
|
|
|
{ |
237
|
|
|
return $this->office; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param Service $service |
242
|
|
|
*/ |
243
|
|
|
public function addService(Service $service) |
244
|
|
|
{ |
245
|
|
|
$this->services[] = $service; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param Service[] $services |
250
|
|
|
*/ |
251
|
|
|
public function setServices(array $services) |
252
|
|
|
{ |
253
|
|
|
$this->services = $services; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @return Service[] |
258
|
|
|
*/ |
259
|
|
|
public function getServices() |
260
|
|
|
{ |
261
|
|
|
return $this->services; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @param string $street |
266
|
|
|
*/ |
267
|
|
|
public function setStreet($street) |
268
|
|
|
{ |
269
|
|
|
$this->street = (string) $street; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @return string |
274
|
|
|
*/ |
275
|
|
|
public function getStreet() |
276
|
|
|
{ |
277
|
|
|
return $this->street; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @param string $type |
282
|
|
|
*/ |
283
|
|
|
public function setType($type) |
284
|
|
|
{ |
285
|
|
|
$this->type = (string) $type; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @return string |
290
|
|
|
*/ |
291
|
|
|
public function getType() |
292
|
|
|
{ |
293
|
|
|
return $this->type; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @param int $x |
298
|
|
|
*/ |
299
|
|
|
public function setX($x) |
300
|
|
|
{ |
301
|
|
|
$this->x = (int) $x; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @return int |
306
|
|
|
*/ |
307
|
|
|
public function getX() |
308
|
|
|
{ |
309
|
|
|
return $this->x; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @param int $y |
314
|
|
|
*/ |
315
|
|
|
public function setY($y) |
316
|
|
|
{ |
317
|
|
|
$this->y = (int) $y; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @return int |
322
|
|
|
*/ |
323
|
|
|
public function getY() |
324
|
|
|
{ |
325
|
|
|
return $this->y; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @param string $zip |
330
|
|
|
*/ |
331
|
|
|
public function setZip($zip) |
332
|
|
|
{ |
333
|
|
|
$this->zip = (string) $zip; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @return string |
338
|
|
|
*/ |
339
|
|
|
public function getZip() |
340
|
|
|
{ |
341
|
|
|
return $this->zip; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @return string |
346
|
|
|
*/ |
347
|
|
|
public function getPage() |
348
|
|
|
{ |
349
|
|
|
return $this->page; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @param string $page |
354
|
|
|
*/ |
355
|
|
|
public function setPage($page) |
356
|
|
|
{ |
357
|
|
|
$this->page = (string) $page; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Create a POI based on an XML-object |
362
|
|
|
* |
363
|
|
|
* @param SimpleXMLElement $xml |
364
|
|
|
* |
365
|
|
|
* @return Poi |
366
|
|
|
* |
367
|
|
|
* @throws BpostInvalidXmlResponseException |
368
|
|
|
*/ |
369
|
|
|
public static function createFromXML(SimpleXMLElement $xml) |
370
|
|
|
{ |
371
|
|
|
if (!isset($xml->Record)) { |
372
|
|
|
throw new BpostInvalidXmlResponseException('"Record" missing'); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
$recordXml = $xml->Record; |
376
|
|
|
|
377
|
|
|
$poi = new Poi(); |
378
|
|
|
|
379
|
|
|
if (isset($recordXml->Id) && $recordXml->Id != '') { |
380
|
|
|
$poi->setId((string) $recordXml->Id); |
381
|
|
|
} |
382
|
|
|
if (isset($recordXml->ID) && $recordXml->ID != '') { |
383
|
|
|
$poi->setId((string) $recordXml->ID); |
384
|
|
|
} |
385
|
|
|
if (isset($recordXml->Type) && $recordXml->Type != '') { |
386
|
|
|
$poi->setType((string) $recordXml->Type); |
387
|
|
|
} |
388
|
|
|
if (isset($recordXml->Name) && $recordXml->Name != '') { |
389
|
|
|
$poi->setOffice((string) $recordXml->Name); |
390
|
|
|
} |
391
|
|
|
if (isset($recordXml->OFFICE) && $recordXml->OFFICE != '') { |
392
|
|
|
$poi->setOffice((string) $recordXml->OFFICE); |
393
|
|
|
} |
394
|
|
|
if (isset($recordXml->Street) && $recordXml->Street != '') { |
395
|
|
|
$poi->setStreet((string) $recordXml->Street); |
396
|
|
|
} |
397
|
|
|
if (isset($recordXml->STREET) && $recordXml->STREET != '') { |
398
|
|
|
$poi->setStreet((string) $recordXml->STREET); |
399
|
|
|
} |
400
|
|
|
if (isset($recordXml->Number) && $recordXml->Number != '') { |
401
|
|
|
$poi->setNr((string) $recordXml->Number); |
402
|
|
|
} |
403
|
|
|
if (isset($recordXml->NR) && $recordXml->NR != '') { |
404
|
|
|
$poi->setNr((string) $recordXml->NR); |
405
|
|
|
} |
406
|
|
|
if (isset($recordXml->Zip) && $recordXml->Zip != '') { |
407
|
|
|
$poi->setZip((string) $recordXml->Zip); |
408
|
|
|
} |
409
|
|
|
if (isset($recordXml->ZIP) && $recordXml->ZIP != '') { |
410
|
|
|
$poi->setZip((string) $recordXml->ZIP); |
411
|
|
|
} |
412
|
|
|
if (isset($recordXml->City) && $recordXml->City != '') { |
413
|
|
|
$poi->setCity((string) $recordXml->City); |
414
|
|
|
} |
415
|
|
|
if (isset($recordXml->CITY) && $recordXml->CITY != '') { |
416
|
|
|
$poi->setCity((string) $recordXml->CITY); |
417
|
|
|
} |
418
|
|
|
if (isset($recordXml->X) && $recordXml->X != '') { |
419
|
|
|
$poi->setX((int) $recordXml->X); |
420
|
|
|
} |
421
|
|
|
if (isset($recordXml->Y) && $recordXml->Y != '') { |
422
|
|
|
$poi->setY((int) $recordXml->Y); |
423
|
|
|
} |
424
|
|
|
if (isset($recordXml->Longitude) && $recordXml->Longitude != '') { |
425
|
|
|
$poi->setLongitude((float) $recordXml->Longitude); |
426
|
|
|
} |
427
|
|
|
if (isset($recordXml->Latitude) && $recordXml->Latitude != '') { |
428
|
|
|
$poi->setLatitude((float) $recordXml->Latitude); |
429
|
|
|
} |
430
|
|
|
if (isset($recordXml->Services) && isset($recordXml->Services->Service)) { |
431
|
|
|
foreach ($recordXml->Services->Service as $service) { |
432
|
|
|
$poi->addService(Service::createFromXML($service)); |
433
|
|
|
} |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
if (isset($recordXml->Hours)) { |
437
|
|
|
$recordHoursXml = $recordXml->Hours; |
438
|
|
|
|
439
|
|
|
if (isset($recordHoursXml->Monday)) { |
440
|
|
|
$poi->addHour(Day::DAY_INDEX_MONDAY, Day::createFromXML($recordHoursXml->Monday)); |
441
|
|
|
} |
442
|
|
|
if (isset($recordHoursXml->Tuesday)) { |
443
|
|
|
$poi->addHour(Day::DAY_INDEX_TUESDAY, Day::createFromXML($recordHoursXml->Tuesday)); |
444
|
|
|
} |
445
|
|
|
if (isset($recordHoursXml->Wednesday)) { |
446
|
|
|
$poi->addHour(Day::DAY_INDEX_WEDNESDAY, Day::createFromXML($recordHoursXml->Wednesday)); |
447
|
|
|
} |
448
|
|
|
if (isset($recordHoursXml->Thursday)) { |
449
|
|
|
$poi->addHour(Day::DAY_INDEX_THURSDAY, Day::createFromXML($recordHoursXml->Thursday)); |
450
|
|
|
} |
451
|
|
|
if (isset($recordHoursXml->Friday)) { |
452
|
|
|
$poi->addHour(Day::DAY_INDEX_FRIDAY, Day::createFromXML($recordHoursXml->Friday)); |
453
|
|
|
} |
454
|
|
|
if (isset($recordHoursXml->Saturday)) { |
455
|
|
|
$poi->addHour(Day::DAY_INDEX_SATURDAY, Day::createFromXML($recordHoursXml->Saturday)); |
456
|
|
|
} |
457
|
|
|
if (isset($recordHoursXml->Sunday)) { |
458
|
|
|
$poi->addHour(Day::DAY_INDEX_SUNDAY, Day::createFromXML($recordHoursXml->Sunday)); |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
if (isset($recordXml->ClosedFrom) && $recordXml->ClosedFrom != '') { |
463
|
|
|
$closedFrom = (string) $recordXml->ClosedFrom; |
464
|
|
|
$poi->setClosedFrom((array) $closedFrom); |
465
|
|
|
} |
466
|
|
|
if (isset($recordXml->ClosedTo) && $recordXml->ClosedTo != '') { |
467
|
|
|
$closedTo = (string) $recordXml->ClosedTo; |
468
|
|
|
$poi->setClosedTo((array) $closedTo); |
469
|
|
|
} |
470
|
|
|
if (isset($recordXml->NOTE) && $recordXml->NOTE != '') { |
471
|
|
|
$poi->setNote((string) $recordXml->NOTE); |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
if (isset($xml->Page) && isset($xml->Page['ServiceRef']) && $xml->Page['ServiceRef'] != '') { |
475
|
|
|
$poi->setPage($xml->Page['ServiceRef']); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
return $poi; |
479
|
|
|
} |
480
|
|
|
} |
481
|
|
|
|