<?php
namespace App\Config; class AutobalancingScoringCriteria extends XmlBasicAbstract { protected $fileName = 'autobalancingScoringCriteria.xml'; protected function getAll_rawData_extractDataFromFile(\SimpleXMLElement $xml) { $autobalancingScoringCriteria = []; foreach ($xml->criterion as $criterion) { foreach ($criterion->children() as $criterionKey=>$criterionValue) { $autobalancingScoringCriteria[(string)$criterion->attributes()['name']][$criterionKey] = (float)$criterionValue; } } return $autobalancingScoringCriteria; } public function getDefaultValuesForAutobalancingScoringCriteria() { return $this->getAll_rawData_fileNotExists(); } protected function getAll_rawData_fileNotExists() { return [ 'ticketNumber' => [ 'equal' => 350, 'notEqual' => -150], 'externalReservationId' => [ 'equal' => 150, 'notEqual' => -80], 'externalReservationDate' => [ 'equal' => 120, 'notEqual' => -20], 'confirmationNumber' => [ 'equal' => 150, 'notEqual' => -80], 'idService' => [ 'equal' => 400, 'notEqual' => -250], 'reservationId' => [ 'equal' => 160, 'notEqual' => -120], 'reservationNumber' => [ 'equal' => 180, 'notEqual' => -80], 'reservationCode' => [ 'equal' => 180, 'notEqual' => -50], 'idPassenger' => [ 'equal' => 120, 'notEqual' => -40], 'checkIn' => [ 'equal' => 110, 'notEqual' => -20], 'serviceCode' => [ 'equal' => 90, 'notEqual' => -70], 'idSupplier' => [ 'equal' => 50, 'notEqual' => -50], 'idSupplierService' => [ 'equal' => 100, 'notEqual' => -50], 'countryCode' => [ 'equal' => 40, 'notEqual' => -80], 'cityId' => [ 'equal' => 90, 'notEqual' => -20], 'price' => [ 'equal' => 240, 'notEqual' => -100, 'tolerance'=>0.07], ]; } protected function save_check() { $_LANG = \App\Loader_Lang::getInstance()->getAll(); foreach ($this->getDefaultValuesForAutobalancingScoringCriteria() as $criterionName=>$criterionValues) { $criteriaName[] = $criterionName; } foreach ($this->itemsList as $autobalancingScoringCriteriaKey => $autobalancingScoringCriteriaValuesList) { if (!in_array($autobalancingScoringCriteriaKey, $criteriaName)) { $this->addErrorMessage(sprintf($_LANG['Admin']['Config']['InvoiceBalances']['AutobalancingScoringCriteria']['process']['messages']['criterionName'], $autobalancingScoringCriteriaKey )); } foreach ($autobalancingScoringCriteriaValuesList as $scoringKey => $scoringValue) { if (!is_numeric($scoringValue)) { $this->addErrorMessage(sprintf($_LANG['Admin']['Config']['InvoiceBalances']['AutobalancingScoringCriteria']['process']['messages']['value'], $autobalancingScoringCriteriaKey, $scoringKey)); } if (($autobalancingScoringCriteriaKey == 'tolerance') && !($scoringValue > 0)) { $this->addErrorMessage($_LANG['Admin']['Config']['InvoiceBalances']['AutobalancingScoringCriteria']['process']['messages']['greaterThanZero']); } } } } protected function save_write_do_getXml() { $xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><autobalancingScoringCriteria />'); $autobalancingScoringCriteriaList = self::getAdmin()->getAll(); foreach ($autobalancingScoringCriteriaList as $autobalancingScoringCriteriaKey => $autobalancingScoringCriteriaValuesList) { $autobalancingScoringCriteriaTag = $xml->addChild('criterion'); $autobalancingScoringCriteriaTag->addAttribute('name', $autobalancingScoringCriteriaKey); foreach ($autobalancingScoringCriteriaValuesList as $scoringKey => $scoringValue) { $autobalancingScoringCriteriaTag->addChild($scoringKey , $scoringValue); } } return $xml; } } 