<?php
 namespace App\Config; class ClientServices extends XmlBasicAbstract { protected $fileName=CONFIG_FILE_SERVICE_DISABLEDCLIENTSERVICES; protected function getAll_rawData_extractDataFromFile(\SimpleXMLElement $xml) { global $CFG; $disabledServiceList=[]; foreach ($xml->location as $countryCriteriaList) { foreach ($countryCriteriaList as $disabledService) { $disabledServiceList[(string)$disabledService['code']][(string)$countryCriteriaList['code']] =true; } } $result=[]; foreach (Services_Basic::getInstance()->getListLinear() as $serviceCode => $serviceDetails) { foreach ($CFG['countriesCriteria'] as $countryCriteria) { if ( $disabledServiceList[$serviceCode][$countryCriteria] ) { $result[$serviceCode][$countryCriteria]=false; } else { $result[$serviceCode][$countryCriteria]=true; } } } return $result; } protected function getAll_rawData_fileNotExists() { global $CFG; $result=[]; foreach (Services_Basic::getInstance()->getListLinear() as $serviceCode => $serviceDetails) { foreach ($CFG['countriesCriteria'] as $countryCriteria) { $result[$serviceCode][$countryCriteria]=true; } } return $result; } protected function save_check() { global $CFG; $allowedServices=Services_Basic::getInstance()->getListLinear(); foreach ($this->itemsList as $serviceCode => $serviceList) { if ( !$allowedServices[$serviceCode] ) $this->addErrorMessage('An invalid service code was requested: '.$serviceCode); foreach ($serviceList as $countryCriterion => $disabledServicesList) { if ( !in_array($countryCriterion, $CFG['countriesCriteria']) ) { $this->addErrorMessage('An invalid country criterion was requested: '.$countryCriterion); } } } } protected function save_write_do_getXml() { global $CFG; $xml=simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><disabledClientServices/>'); $disabledServicesList=[]; foreach ($CFG['countriesCriteria'] as $countryCriterion) { foreach (Services_Basic::getInstance()->getListLinear() as $serviceCode => $serviceDetails) { if ( !$this->itemsList[$serviceCode][$countryCriterion] ) { $disabledServicesList[$countryCriterion][$serviceCode]=true; } } } foreach ($disabledServicesList as $countryCriterion => $servicesList) { $locationTag=$xml->addChild('location'); $locationTag['code'] = $countryCriterion; foreach ($servicesList as $serviceCode => $disabledService) { $serviceTag = $locationTag->addChild('service'); $serviceTag['code'] = $serviceCode; } } return $xml; } public function isActiveOnCriterion($serviceCode, $criterion) { $serviceConfig = $this->get($serviceCode); return (Boolean)$serviceConfig[$criterion]; } public function isActive($serviceCode) { if (!$this->get($serviceCode)) { throw new \Exception("The service code `{$serviceCode}` is not valid."); } $serviceConfig = $this->get($serviceCode); return (Boolean)array_filter($serviceConfig); } } 