/** * Return the object as an array for usage in the XML * * @param \DomDocument $document * @param string $prefix * @param string $type * @return \DomElement */ public function toXML(\DOMDocument $document, $prefix = null, $type = null) { $nationalElement = $document->createElement($this->getPrefixedTagName('nationalBox', $prefix)); $boxElement = parent::toXML($document, null, 'bpostOnAppointment'); $nationalElement->appendChild($boxElement); $this->addToXmlReceiver($document, $boxElement); $this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); return $nationalElement; }
/** * @param \SimpleXMLElement $nationalXml * @param National $self * @return AtHome * @throws BpostException * @throws BpostXmlInvalidItemException */ public static function createFromXML(\SimpleXMLElement $nationalXml, self $self = null) { if ($self === null) { throw new BpostException('Set an instance of National'); } if (isset($nationalXml->product) && $nationalXml->product != '') { $self->setProduct((string) $nationalXml->product); } if (isset($nationalXml->options) && !empty($nationalXml->options)) { /** @var \SimpleXMLElement $optionData */ foreach ($nationalXml->options as $optionData) { $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); if (in_array($optionData->getName(), array(Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED, Messaging::MESSAGING_TYPE_INFO_NEXT_DAY, Messaging::MESSAGING_TYPE_INFO_REMINDER, Messaging::MESSAGING_TYPE_KEEP_ME_INFORMED))) { $option = Messaging::createFromXML($optionData); } else { switch ($optionData->getName()) { case 'insured': $class = 'Insurance'; break; default: $class = ucfirst($optionData->getName()); } $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . $class; if (!method_exists($className, 'createFromXML')) { throw new BpostXmlInvalidItemException(); } $option = call_user_func(array($className, 'createFromXML'), $optionData); } $self->addOption($option); } } if (isset($nationalXml->weight) && $nationalXml->weight != '') { $self->setWeight((int) $nationalXml->weight); } if (isset($nationalXml->openingHours) && $nationalXml->openingHours != '') { foreach ($nationalXml->openingHours->children() as $day => $value) { $self->addOpeningHour(new Day($day, (string) $value)); } } if (isset($nationalXml->desiredDeliveryPlace) && $nationalXml->desiredDeliveryPlace != '') { $self->setDesiredDeliveryPlace((string) $nationalXml->desiredDeliveryPlace); } return $self; }
/** * Return the object as an array for usage in the XML * * @param \DomDocument $document * @param string $prefix * @param string $type * @return \DomElement */ public function toXML(\DOMDocument $document, $prefix = null, $type = null) { $nationalElement = $document->createElement($this->getPrefixedTagName('nationalBox', $prefix)); $boxElement = parent::toXML($document, null, 'atBpost'); $nationalElement->appendChild($boxElement); if ($this->getPugoId() !== null) { $boxElement->appendChild($document->createElement('pugoId', $this->getPugoId())); } if ($this->getPugoName() !== null) { $boxElement->appendChild($document->createElement('pugoName', $this->getPugoName())); } if ($this->getPugoAddress() !== null) { $boxElement->appendChild($this->getPugoAddress()->toXML($document, 'common')); } if ($this->getReceiverName() !== null) { $boxElement->appendChild($document->createElement('receiverName', $this->getReceiverName())); } if ($this->getReceiverCompany() !== null) { $boxElement->appendChild($document->createElement('receiverCompany', $this->getReceiverCompany())); } $this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); $this->addToXmlShopHandlingInstruction($document, $boxElement, $prefix); return $nationalElement; }
/** * @param \SimpleXMLElement $xml * @return AtHome * @throws BpostNotImplementedException * @throws BpostXmlInvalidItemException * @throws \Bpost\BpostApiClient\BpostException */ public static function createFromXML(\SimpleXMLElement $xml) { $self = new self(); if (!isset($xml->atHome)) { throw new BpostXmlInvalidItemException(); } $atHomeXml = $xml->atHome[0]; $self = parent::createFromXML($atHomeXml, $self); if (isset($atHomeXml->receiver)) { $self->setReceiver(Receiver::createFromXML($atHomeXml->receiver->children('http://schema.post.be/shm/deepintegration/v3/common'))); } if (isset($atHomeXml->requestedDeliveryDate) && $atHomeXml->requestedDeliveryDate != '') { $self->setRequestedDeliveryDate($atHomeXml->requestedDeliveryDate); } return $self; }