<?php
 namespace App\Config; class Services_Calculations_ClientTypes extends XmlBasicAbstract { protected $fileName=CONFIG_FILE_SERVICE_CALCULATION_CLIENT_TYPES; protected function getAll_rawData_extractDataFromFile(\SimpleXMLElement $xml) { $return=[]; foreach($xml->service as $serviceDetails) { foreach ($serviceDetails as $calcClientType) { $return[(String)$serviceDetails['code'].'_'.(String)$calcClientType['location'].'_'.(String)$calcClientType['code']]=(String)$calcClientType; } } return $return; } protected function save_check() { global $_LANG; foreach (Services_Calculations::getAdmin()->getAll() as $calculationCode => $calculationDetails) { if ( !$calculationDetails['deleted'] ) { if ( !in_array($this->itemsList[$calculationCode], ['customers', 'corporates', 'both'])) { $this->addErrorMessage(sprintf('When setting the service offer details, the client type `%s` is not valid for calculation type `%s` for service `%s` at location `%s`', $this->itemsList[$calculationCode], $calculationDetails['name'], Services_Basic::getInstance()->getServiceName($calculationDetails['serviceCode']), $_LANG['locations']['countriesCriteria']['long'][$calculationDetails['location']])); } } } } protected function save_write_do_getXml() { $xml=simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><calculationsClientType />'); foreach (Services_Calculations::getAdmin()->getExtendedList() as $serviceCode => $locationDetails) { $serviceObj=$xml->addChild('service'); $serviceObj['code']=$serviceCode; foreach ($locationDetails as $locationCode => $calculationDetails) { foreach ($calculationDetails as $calculationCode => $nothing) { $clientTypeObj = $serviceObj->addChild('calculationType', $this->itemsList[$serviceCode.'_'.$locationCode.'_'.$calculationCode]); $clientTypeObj['location'] = $locationCode; $clientTypeObj['code'] = $calculationCode; } } } return $xml; } public function getClientType($serviceCode, $location, $calculation) { if (!$serviceCode) throw new \Exception('The service code was not set.'); if (!$location) throw new \Exception('The location code was not set.'); if (!strlen($calculation)) throw new \Exception('The calculation code was not set.'); $key=$serviceCode.'_'.$location.'_'.$calculation; $allData = $this->getAll(); return $allData[$key]; } } 