<?php
 namespace App\Config; class Services_OfferDetails extends XmlBasicAbstract { protected $fileName=CONFIG_FILE_SERVICE_OFFER_DETAILS; protected function getAll_rawData_extractDataFromFile(\SimpleXMLElement $xml) { $result=[]; foreach($xml->service as $serviceOfferDetails) { $serviceOfferDetailsList = []; $serviceOfferDetailsList['quantityType'] = (string)$serviceOfferDetails->quantityType; $serviceOfferDetailsList['expiration'] = [ 'type' => (string)$serviceOfferDetails->valability['relativeTo'], 'period'=>(int)$serviceOfferDetails->valability['days'] ]; $serviceOfferDetailsList['ignoreSupplierOnDocuments'] = (string)$serviceOfferDetails->ignoreSupplierOnDocuments; $result[(string)$serviceOfferDetails['code']]=$serviceOfferDetailsList; } return $result; } protected function save_check(){ foreach (Services_Basic::getAdmin()->getListLinear() as $serviceCode => $serviceDetails) { if ( !in_array($this->itemsList[$serviceCode]['quantityType'], ['simple', 'duration', 'distance'])) { $this->addErrorMessage('When setting the service offer details, the offer `quantity type` is not valid for service `'.$serviceDetails['name'].'`.'); } if ( !in_array($this->itemsList[$serviceCode]['ignoreSupplierOnDocuments'], ['hidden', 'visible', 'defaultSelected']) ) { $this->addErrorMessage('When setting the service offer details, the element `ignoreSupplierOnDocuments` is not valid for service `'.$serviceDetails['name'].'`.'); } if ( !in_array($this->itemsList[$serviceCode]['expiration']['type'], ['noValability', 'offerAddDate', 'serviceStartDate'])) { $this->addErrorMessage('When setting the service offer details, the offer expiration is not valid for service `'.$serviceDetails['name'].'`.'); } if ( $this->itemsList[$serviceCode]['expiration']['type']=='offerAddDate' or $this->itemsList[$serviceCode]['expiration']['type']=='serviceStartDate' ) { if (!is_numeric($this->itemsList[$serviceCode]['expiration']['period']) or $this->itemsList[$serviceCode]['expiration']['period']<0 or $this->itemsList[$serviceCode]['expiration']['period']>366 ) { $this->addErrorMessage('When setting the service offer details, the expiration period of offer must be a positive value less than 366 for service `'.$serviceDetails['name'].'`.'); } } } } protected function save_write_do_getXml() { $xml=simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><offerDetails />'); foreach (Services_Basic::getAdmin()->getListLinear() as $serviceCode => $serviceDetails) { $serviceObj=$xml->addChild('service'); $serviceObj['code']=$serviceCode; $serviceObj->quantityType = $this->itemsList[$serviceCode]['quantityType']; $valabilityObj=$serviceObj->addChild('valability'); $valabilityObj['relativeTo']=$this->itemsList[$serviceCode]['expiration']['type']; if ( $this->itemsList[$serviceCode]['expiration']['type'] == 'offerAddDate' or $this->itemsList[$serviceCode]['expiration']['type'] == 'serviceStartDate' ) { $valabilityObj['days']=$this->itemsList[$serviceCode]['expiration']['period']; } $serviceObj->ignoreSupplierOnDocuments = $this->itemsList[$serviceCode]['ignoreSupplierOnDocuments']; } return $xml; } public function getIgnoreSupplierOnDocuments($serviceCode) { $servCfg = $this->get($serviceCode); return $servCfg['ignoreSupplierOnDocuments']; } } 