Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/units/helpers/ecb_currency_rates.php
Show All 11 Lines | |||||
*/ | */ | ||||
defined('FULL_PATH') or die('restricted access!'); | defined('FULL_PATH') or die('restricted access!'); | ||||
class ECBCurrencyRates extends CurrencyRates { | class ECBCurrencyRates extends CurrencyRates { | ||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->RateSource = 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'; | $this->RateSource = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'; | ||||
parent::__construct(); | parent::__construct(); | ||||
} | } | ||||
function GetRatesData() | function GetRatesData() | ||||
{ | { | ||||
$xml_parser = xml_parser_create(); | $xml_parser = xml_parser_create(); | ||||
/** @var kCurlHelper $curl_helper */ | /** @var kCurlHelper $curl_helper */ | ||||
$curl_helper = $this->Application->recallObject('CurlHelper'); | $curl_helper = $this->Application->recallObject('CurlHelper'); | ||||
$curl_helper->followLocation = true; | |||||
$xml = $curl_helper->Send($this->RateSource); | $xml = $curl_helper->Send($this->RateSource); | ||||
if ( !$curl_helper->isGoodResponseCode() || strlen($xml) == 0 ) { | |||||
return; | |||||
} | |||||
xml_parse_into_struct($xml_parser, $xml, $struct, $index); | xml_parse_into_struct($xml_parser, $xml, $struct, $index); | ||||
$data_res = Array(); | $data_res = Array(); | ||||
foreach($struct as $element) | foreach($struct as $element) | ||||
{ | { | ||||
if(isset($element['attributes']) && isset($element['attributes']['CURRENCY'])) | if(isset($element['attributes']) && isset($element['attributes']['CURRENCY'])) | ||||
{ | { | ||||
$currency = $element['attributes']['CURRENCY']; | $currency = $element['attributes']['CURRENCY']; | ||||
$data_res[$currency]['ID'] = $currency; | $data_res[$currency]['ID'] = $currency; | ||||
$data_res[$currency]['TARGET'] = 'EUR'; | $data_res[$currency]['TARGET'] = 'EUR'; | ||||
$data_res[$currency]['UNITS'] = 1; | $data_res[$currency]['UNITS'] = 1; | ||||
$data_res[$currency]['RATE'] = ($element['attributes']['RATE'] == 0) ? 0 : 1 / $element['attributes']['RATE']; | $data_res[$currency]['RATE'] = ($element['attributes']['RATE'] == 0) ? 0 : 1 / $element['attributes']['RATE']; | ||||
} | } | ||||
} | } | ||||
if(!$data_res['EUR']) | |||||
{ | if ( !isset($data_res['EUR']) ) { | ||||
$data_res['EUR']['ID'] = 'EUR'; | $data_res['EUR']['ID'] = 'EUR'; | ||||
$data_res['EUR']['UNITS'] = 1; | $data_res['EUR']['UNITS'] = 1; | ||||
$data_res['EUR']['TARGET'] = 'EUR'; | $data_res['EUR']['TARGET'] = 'EUR'; | ||||
$data_res['EUR']['RATE'] = 1; | $data_res['EUR']['RATE'] = 1; | ||||
} | } | ||||
$this->ExchangeRates = $data_res; | $this->ExchangeRates = $data_res; | ||||
} | } | ||||
} | } |