<?php
 namespace App\Config; class InvoiceDueDates extends XmlBasicAbstract { protected $fileName=CONFIG_FILE_INVOICES_DUE_DATES; protected function getAll_rawData_extractDataFromFile(\SimpleXMLElement $xml) { $clientCategoriesList=[]; foreach ($xml as $clientCategories) { $clientCategoriesList[(string)$clientCategories->getName()] = (int)$clientCategories; } return $clientCategoriesList; } protected function getAll_rawData_fileNotExists() { $return= [ 'corporate' => 0, 'subagent' => 0, 'customer' => 0 ]; return $return; } protected function save_check() { $allowedClientCategoriesList= ['corporate', 'subagent', 'customer']; foreach ($this->itemsList as $category => $daysNumber) { if ( !in_array($category, $allowedClientCategoriesList) ) { $this->addErrorMessage('An invalid category was requested: '.$category); } if ($daysNumber) { if ( !is_numeric($daysNumber) or $daysNumber<0 or $daysNumber>366 ) { $this->addErrorMessage('Number of days until due dates for `'.$category.' category` must be a numeric value between 0 and 366 '); } } } } protected function save_write_do_getXml() { $xml=simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><invoiceDueDates />'); foreach ( $this->itemsList as $clientCategory => $days ) { if($days=='') { $days=0; } $xml->addChild($clientCategory, $days); } return $xml; } } 