<?php
 namespace App\Config; class OrderServicesTypes extends XmlDynamicRecordsAbstract { protected $fileName=CONFIG_FILE_RESERVATIONS_SERVICETYPES; protected function getAll_rawData_extractDataFromFile_list(\SimpleXMLElement $xml) { $return=[]; foreach ($xml->serviceType as $rst) { $return [ (String)$rst['code'] ] = (String)$rst; } return $return; } protected function getAll_rawData_extractDataFromFile_default(\SimpleXMLElement $xml) { return (String)$xml['default'].''; } protected function getAll_rawData_extractDataFromFile_mandatory(\SimpleXMLElement $xml) { return (Int)$xml['mandatory']; } protected function itemCheck($code, $itemDetails) { if (!is_string($itemDetails)) throw new \Exception('The order service type name must be set as a string.'); if (!$code) $this->addErrorMessage('The order service type `code` was not defined.'); if (!$itemDetails) $this->addErrorMessage('The order service type `name` was not defined.'); if (mb_strlen($code) > 20) $this->addErrorMessage('The order service type `code` length must be smaller than 20 chars.'); if (mb_strlen($itemDetails) > 50) $this->addErrorMessage('The order service type `name` length must be smaller than 50 chars.'); if (htmlClean($itemDetails) != $itemDetails) $this->addErrorMessage('The order service type `name` cannot contain html special characters.'); foreach ($this->itemsList as $c => $n) { if ($c != $code and $itemDetails == $n) { $this->addErrorMessage('This order service type `name` already exists.'); } } } protected function save_check() { } protected function save_write_do_getXml() { $xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><reservationServiceTypes/>'); foreach($this->itemsList as $rstCode => $rstName) { $servObj = $xml->addChild('serviceType'); $servObj[0] = $rstName; $servObj['code'] = $rstCode; } $xml['mandatory'] = $this->mandatory; $xml['default'] = $this->defaultItem; return $xml; } } 