1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bpost\BpostApiClient\Bpost\Order\Box; |
4
|
|
|
|
5
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Box\National\Unregistered; |
6
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Box\Option\Messaging; |
7
|
|
|
use Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress; |
8
|
|
|
use Bpost\BpostApiClient\Bpost\ProductConfiguration\Product; |
9
|
|
|
use Bpost\BpostApiClient\Common\XmlHelper; |
10
|
|
|
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException; |
11
|
|
|
use Bpost\BpostApiClient\Exception\BpostNotImplementedException; |
12
|
|
|
use DOMDocument; |
13
|
|
|
use DOMElement; |
14
|
|
|
use SimpleXMLElement; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* bPost At247 class |
18
|
|
|
* |
19
|
|
|
* @author Tijs Verkoyen <[email protected]> |
20
|
|
|
* |
21
|
|
|
* @version 3.0.0 |
22
|
|
|
* |
23
|
|
|
* @copyright Copyright (c), Tijs Verkoyen. All rights reserved. |
24
|
|
|
* @license BSD License |
25
|
|
|
*/ |
26
|
|
|
class At247 extends National |
27
|
|
|
{ |
28
|
|
|
/** @var string */ |
29
|
|
|
private $parcelsDepotId; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
private $parcelsDepotName; |
33
|
|
|
|
34
|
|
|
/** @var \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress */ |
35
|
|
|
private $parcelsDepotAddress; |
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
protected $product = Product::PRODUCT_NAME_BPACK_24H_PRO; |
39
|
|
|
|
40
|
|
|
/** @var string */ |
41
|
|
|
private $memberId; |
42
|
|
|
|
43
|
|
|
/** @var Unregistered */ |
44
|
|
|
private $unregistered; |
45
|
|
|
|
46
|
|
|
/** @var string */ |
47
|
|
|
private $receiverName; |
48
|
|
|
|
49
|
|
|
/** @var string */ |
50
|
|
|
private $receiverCompany; |
51
|
|
|
|
52
|
|
|
/** @var string */ |
53
|
|
|
protected $requestedDeliveryDate; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $memberId |
57
|
|
|
*/ |
58
|
|
|
public function setMemberId($memberId) |
59
|
|
|
{ |
60
|
|
|
$this->memberId = $memberId; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function getMemberId() |
67
|
|
|
{ |
68
|
|
|
return $this->memberId; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress $parcelsDepotAddress |
73
|
|
|
*/ |
74
|
|
|
public function setParcelsDepotAddress($parcelsDepotAddress) |
75
|
|
|
{ |
76
|
|
|
$this->parcelsDepotAddress = $parcelsDepotAddress; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress |
81
|
|
|
*/ |
82
|
|
|
public function getParcelsDepotAddress() |
83
|
|
|
{ |
84
|
|
|
return $this->parcelsDepotAddress; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $parcelsDepotId |
89
|
|
|
*/ |
90
|
|
|
public function setParcelsDepotId($parcelsDepotId) |
91
|
|
|
{ |
92
|
|
|
$this->parcelsDepotId = $parcelsDepotId; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getParcelsDepotId() |
99
|
|
|
{ |
100
|
|
|
return $this->parcelsDepotId; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $parcelsDepotName |
105
|
|
|
*/ |
106
|
|
|
public function setParcelsDepotName($parcelsDepotName) |
107
|
|
|
{ |
108
|
|
|
$this->parcelsDepotName = $parcelsDepotName; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getParcelsDepotName() |
115
|
|
|
{ |
116
|
|
|
return $this->parcelsDepotName; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return Unregistered |
121
|
|
|
*/ |
122
|
|
|
public function getUnregistered() |
123
|
|
|
{ |
124
|
|
|
return $this->unregistered; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param Unregistered $unregistered |
129
|
|
|
*/ |
130
|
|
|
public function setUnregistered(Unregistered $unregistered) |
131
|
|
|
{ |
132
|
|
|
$this->unregistered = $unregistered; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param string $product Possible values are: bpack 24h Pro |
137
|
|
|
* |
138
|
|
|
* @throws BpostInvalidValueException |
139
|
|
|
*/ |
140
|
|
|
public function setProduct($product) |
141
|
|
|
{ |
142
|
|
|
if (!in_array($product, self::getPossibleProductValues())) { |
143
|
|
|
throw new BpostInvalidValueException('product', $product, self::getPossibleProductValues()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
parent::setProduct($product); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return array |
151
|
|
|
*/ |
152
|
|
|
public static function getPossibleProductValues() |
153
|
|
|
{ |
154
|
|
|
return array( |
155
|
|
|
Product::PRODUCT_NAME_BPACK_24H_PRO, |
156
|
|
|
Product::PRODUCT_NAME_BPACK_24_7, |
157
|
|
|
); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string $receiverCompany |
162
|
|
|
*/ |
163
|
|
|
public function setReceiverCompany($receiverCompany) |
164
|
|
|
{ |
165
|
|
|
$this->receiverCompany = $receiverCompany; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return string |
170
|
|
|
*/ |
171
|
|
|
public function getReceiverCompany() |
172
|
|
|
{ |
173
|
|
|
return $this->receiverCompany; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param string $receiverName |
178
|
|
|
*/ |
179
|
|
|
public function setReceiverName($receiverName) |
180
|
|
|
{ |
181
|
|
|
$this->receiverName = $receiverName; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
|
|
public function getReceiverName() |
188
|
|
|
{ |
189
|
|
|
return $this->receiverName; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
public function getRequestedDeliveryDate() |
196
|
|
|
{ |
197
|
|
|
return $this->requestedDeliveryDate; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param string $requestedDeliveryDate |
202
|
|
|
*/ |
203
|
|
|
public function setRequestedDeliveryDate($requestedDeliveryDate) |
204
|
|
|
{ |
205
|
|
|
$this->requestedDeliveryDate = (string) $requestedDeliveryDate; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Return the object as an array for usage in the XML |
210
|
|
|
* |
211
|
|
|
* @param DomDocument $document |
212
|
|
|
* @param string $prefix |
213
|
|
|
* @param string $type |
214
|
|
|
* |
215
|
|
|
* @return DomElement |
216
|
|
|
*/ |
217
|
|
|
public function toXML(DOMDocument $document, $prefix = null, $type = null) |
218
|
|
|
{ |
219
|
|
|
$nationalElement = $document->createElement(XmlHelper::getPrefixedTagName('nationalBox', $prefix)); |
220
|
|
|
$boxElement = parent::toXML($document, null, 'at24-7'); |
221
|
|
|
$nationalElement->appendChild($boxElement); |
222
|
|
|
|
223
|
|
|
if ($this->getParcelsDepotId() !== null) { |
|
|
|
|
224
|
|
|
$boxElement->appendChild( |
225
|
|
|
$document->createElement('parcelsDepotId', $this->getParcelsDepotId()) |
226
|
|
|
); |
227
|
|
|
} |
228
|
|
|
if ($this->getParcelsDepotName() !== null) { |
|
|
|
|
229
|
|
|
$boxElement->appendChild( |
230
|
|
|
$document->createElement( |
231
|
|
|
'parcelsDepotName', |
232
|
|
|
$this->getParcelsDepotName() |
233
|
|
|
) |
234
|
|
|
); |
235
|
|
|
} |
236
|
|
|
if ($this->getParcelsDepotAddress() !== null) { |
237
|
|
|
$boxElement->appendChild( |
238
|
|
|
$this->getParcelsDepotAddress()->toXML($document) |
239
|
|
|
); |
240
|
|
|
} |
241
|
|
|
if ($this->getMemberId() !== null) { |
|
|
|
|
242
|
|
|
$boxElement->appendChild( |
243
|
|
|
$document->createElement( |
244
|
|
|
'memberId', |
245
|
|
|
$this->getMemberId() |
246
|
|
|
) |
247
|
|
|
); |
248
|
|
|
} |
249
|
|
|
$this->addToXmlUnregistered($document, $boxElement, $prefix); |
250
|
|
|
if ($this->getReceiverName() !== null) { |
|
|
|
|
251
|
|
|
$boxElement->appendChild( |
252
|
|
|
$document->createElement( |
253
|
|
|
'receiverName', |
254
|
|
|
$this->getReceiverName() |
255
|
|
|
) |
256
|
|
|
); |
257
|
|
|
} |
258
|
|
|
if ($this->getReceiverCompany() !== null) { |
|
|
|
|
259
|
|
|
$boxElement->appendChild( |
260
|
|
|
$document->createElement( |
261
|
|
|
'receiverCompany', |
262
|
|
|
$this->getReceiverCompany() |
263
|
|
|
) |
264
|
|
|
); |
265
|
|
|
} |
266
|
|
|
$this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); |
267
|
|
|
|
268
|
|
|
return $nationalElement; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @param DOMDocument $document |
273
|
|
|
* @param DOMElement $typeElement |
274
|
|
|
* @param string $prefix |
275
|
|
|
*/ |
276
|
|
|
protected function addToXmlRequestedDeliveryDate(DOMDocument $document, DOMElement $typeElement, $prefix) |
277
|
|
|
{ |
278
|
|
|
if ($this->getRequestedDeliveryDate() !== null && $this->getRequestedDeliveryDate() !== "" ) { |
279
|
|
|
$typeElement->appendChild( |
280
|
|
|
$document->createElement( |
281
|
|
|
XmlHelper::getPrefixedTagName('requestedDeliveryDate', $prefix), |
282
|
|
|
$this->getRequestedDeliveryDate() |
283
|
|
|
) |
284
|
|
|
); |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @param DOMDocument $document |
290
|
|
|
* @param DOMElement $typeElement |
291
|
|
|
* @param string $prefix |
292
|
|
|
*/ |
293
|
|
|
protected function addToXmlUnregistered(DOMDocument $document, DOMElement $typeElement, $prefix) |
|
|
|
|
294
|
|
|
{ |
295
|
|
|
if ($this->getUnregistered() !== null) { |
296
|
|
|
$typeElement->appendChild( |
297
|
|
|
$this->getUnregistered()->toXml($document) |
298
|
|
|
); |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @param SimpleXMLElement $xml |
304
|
|
|
* @param National|null $self |
305
|
|
|
* |
306
|
|
|
* @return At247 |
307
|
|
|
* |
308
|
|
|
* @throws BpostInvalidValueException |
309
|
|
|
* @throws BpostNotImplementedException |
310
|
|
|
* @throws \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
311
|
|
|
* @throws \Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException |
312
|
|
|
*/ |
313
|
|
|
public static function createFromXML(SimpleXMLElement $xml, National $self = null) |
314
|
|
|
{ |
315
|
|
|
$at247 = new At247(); |
316
|
|
|
|
317
|
|
|
if (isset($xml->{'at24-7'}->product) && $xml->{'at24-7'}->product != '') { |
318
|
|
|
$at247->setProduct( |
319
|
|
|
(string) $xml->{'at24-7'}->product |
320
|
|
|
); |
321
|
|
|
} |
322
|
|
|
if (isset($xml->{'at24-7'}->options)) { |
323
|
|
|
/** @var SimpleXMLElement $optionData */ |
324
|
|
|
foreach ($xml->{'at24-7'}->options as $optionData) { |
325
|
|
|
$optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); |
326
|
|
|
|
327
|
|
|
if (in_array($optionData->getName(), array(Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED))) { |
328
|
|
|
$option = Messaging::createFromXML($optionData); |
329
|
|
|
} else { |
330
|
|
|
$option = self::getOptionFromOptionData($optionData); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
$at247->addOption($option); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
if (isset($xml->{'at24-7'}->weight) && $xml->{'at24-7'}->weight != '') { |
337
|
|
|
$at247->setWeight( |
338
|
|
|
(int) $xml->{'at24-7'}->weight |
339
|
|
|
); |
340
|
|
|
} |
341
|
|
|
if (isset($xml->{'at24-7'}->memberId) && $xml->{'at24-7'}->memberId != '') { |
342
|
|
|
$at247->setMemberId( |
343
|
|
|
(string) $xml->{'at24-7'}->memberId |
344
|
|
|
); |
345
|
|
|
} |
346
|
|
|
if (isset($xml->{'at24-7'}->receiverName) && $xml->{'at24-7'}->receiverName != '') { |
347
|
|
|
$at247->setReceiverName( |
348
|
|
|
(string) $xml->{'at24-7'}->receiverName |
349
|
|
|
); |
350
|
|
|
} |
351
|
|
|
if (isset($xml->{'at24-7'}->receiverCompany) && $xml->{'at24-7'}->receiverCompany != '') { |
352
|
|
|
$at247->setReceiverCompany( |
353
|
|
|
(string) $xml->{'at24-7'}->receiverCompany |
354
|
|
|
); |
355
|
|
|
} |
356
|
|
|
if (isset($xml->{'at24-7'}->parcelsDepotId) && $xml->{'at24-7'}->parcelsDepotId != '') { |
357
|
|
|
$at247->setParcelsDepotId( |
358
|
|
|
(string) $xml->{'at24-7'}->parcelsDepotId |
359
|
|
|
); |
360
|
|
|
} |
361
|
|
|
if (isset($xml->{'at24-7'}->parcelsDepotName) && $xml->{'at24-7'}->parcelsDepotName != '') { |
362
|
|
|
$at247->setParcelsDepotName( |
363
|
|
|
(string) $xml->{'at24-7'}->parcelsDepotName |
364
|
|
|
); |
365
|
|
|
} |
366
|
|
|
if (isset($xml->{'at24-7'}->parcelsDepotAddress)) { |
367
|
|
|
/** @var SimpleXMLElement $parcelsDepotAddressData */ |
368
|
|
|
$parcelsDepotAddressData = $xml->{'at24-7'}->parcelsDepotAddress->children( |
369
|
|
|
'http://schema.post.be/shm/deepintegration/v3/common' |
370
|
|
|
); |
371
|
|
|
$at247->setParcelsDepotAddress( |
372
|
|
|
ParcelsDepotAddress::createFromXML($parcelsDepotAddressData) |
373
|
|
|
); |
374
|
|
|
} |
375
|
|
|
if (isset($xml->{'at24-7'}->requestedDeliveryDate) && $xml->{'at24-7'}->requestedDeliveryDate != '') { |
376
|
|
|
$at247->setRequestedDeliveryDate( |
377
|
|
|
(string) $xml->{'at24-7'}->requestedDeliveryDate |
378
|
|
|
); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
return $at247; |
382
|
|
|
} |
383
|
|
|
} |
384
|
|
|
|