<?php
 namespace App\ExportData\ExportFile; class CurrencyRates extends GeneralAbstract { protected $entityType = 'currencyExchange'; protected $fileName = 'currencyExchange'; protected $rootTag = 'currencyExchangeRates'; protected $allowedOperationTypes = ['add', 'update', 'delete']; protected $date; protected $market; protected function checkIfInactiveEntity() { return !\App\Config\ExportData_ActiveEntities::getInstance()->get('currencyExchange'); } public function __construct($date, $market) { if (!$this->rootTag) { throw new \Exception('The root tag was not set for the class `'.get_called_class().'`.'); } $this->date = $date; $this->market = $market; } protected function populateXml(\SimpleXMLElement $xml, \App\MessagesCollector $msgs) { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); if (!validDate($this->date) ) { $msgs->addError("The date of the currency exchange rates is not valid: `{$this->date}`."); } if (!$this->market or !in_array($this->market, $CFG['currencies']['markets'])) { $msgs->addError("The market `{$this->market}` is not set/valid for currency exchange rate export."); } $ratesObj = \App\CurrencyExchange\Date::getInstance($this->date, $this->market); $rates = $ratesObj->getRates(); $currenciesTypesList=\App\Config\CurrencyTypes::getInstance()->getSimpleActive(); $xml['date']=$this->date; $xml['market']=$this->market; $xml['exportTime']=date("Y-m-d\TH:i:s"); foreach($currenciesTypesList as $currTypeCode=>$currTypeName) { $currTypeObj = $xml->addChild('currencyType'); $currTypeObj['code'] = htmlUnclean($currTypeCode); $currTypeObj['name'] = htmlUnclean($currTypeName); $currenciesValues = $rates[$currTypeCode]; if (is_array($currenciesValues)) { foreach ($currenciesValues as $currCode=>$value) { $currCodeObj = $currTypeObj->addChild('currency', $value); $currCodeObj['code'] = htmlUnclean($currCode); } } } } } 