<?php
 namespace App\Config; class SupplierInvoice_Fields extends XmlBasicAbstract { protected $fileName=CONFIG_FILE_SUPPLIERINVOICES_FIELDS; private $allowedFields= ['rowType', 'location', 'contractNumber', 'passenger', 'reservationCode', 'reservationNumber', 'reservationId', 'idService', 'checkIn', 'checkOut', 'supplierService', 'ticketNo', 'extResId', 'extResDate', 'confirmationNumber']; protected function getAll_rawData_extractDataFromFile(\SimpleXMLElement $xml) { $return=[]; foreach ($xml->service as $serv) { $atrsList=[]; $serviceCode=null; foreach ($serv->attributes() as $atr=>$val) { if ($atr=='code') { $serviceCode=(String)$val; } else { $atrsList[(String)$atr]=(String)$val; } } if ($serviceCode!==null) { $return[$serviceCode]=$atrsList; } } return $return; } public function setField($serviceCode, $field, $value) { if ($this->constructType!='admin') { throw new \Exception("You can use the method `".get_called_class().'::'.__FUNCTION__."` only if the constructor type is `admin`."); } if (!is_string($serviceCode) and !is_numeric($serviceCode)) { throw new \Exception("You did not set() a correct code for the service code."); } if (!is_string($field) and !is_numeric($field)) { throw new \Exception("You did not set() a correct name for the field."); } $this->itemsList[$serviceCode][$field] = $value; $this->changedFlag = true; } public function getAllowedFields() { return $this->allowedFields; } protected function save_check() { foreach ($this->itemsList as $serviceCode=>$serviceFields) { if (!is_array($serviceFields)) $this->addErrorMessage(sprintf('The configuration for the service code `%s` is not valid.', $serviceCode)); foreach ($serviceFields as $fld=>$type) { if (!in_array($fld, $this->allowedFields)) $this->addErrorMessage(sprintf('The field `%s` for the service code `%s` is not valid.', $fld, $serviceCode)); if ($type and $type!='mandatory' and $type!='optional') $this->addErrorMessage(sprintf('Bad value for the field `%s` of the service code `%s`.', $fld, $serviceCode)); } } } protected function save_write_do_getXml() { $xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><supplierInvoicesFields/>'); foreach ($this->itemsList as $serviceCode=>$fields) { if(Services_Basic::getInstance()->checkService($serviceCode) || $serviceCode == '') { $servObj = $xml->addChild('service'); $servObj['code'] = $serviceCode; foreach ($fields as $fld=>$visibility) { if ($visibility) $servObj[$fld]=$visibility; } } } return $xml; } }