Index: branches/5.1.x/units/currencies/currency_rates.php =================================================================== diff -u -r13100 -r13164 --- branches/5.1.x/units/currencies/currency_rates.php (.../currency_rates.php) (revision 13100) +++ branches/5.1.x/units/currencies/currency_rates.php (.../currency_rates.php) (revision 13164) @@ -1,6 +1,6 @@ Application =& kApplication::Instance(); + parent::kBase(); + $this->GetRatesData(); } function GetRatesData() { - // written :) just check that it's correct - $conn =& $this->Application->GetADODBConnection(); - $table = $this->Application->getUnitOption('curr', 'TableName'); - $primary = $this->GetPrimaryCurrency(); - $sql = 'SELECT "'.$primary.'" AS TARGET, ISO AS ID, RateToPrimary As RATE, 1 AS UNITS FROM '.$table.' WHERE 1'; - $rates = $conn->Query($sql); - foreach ($rates as $a_rate) { - $this->SetRate($primary, $a_rate['ID'], $a_rate['RATE']); + $cache_key = 'currency_rates[%CurrSerial%]'; + $rates = $this->Application->getCache($cache_key); + $primary = $this->Application->GetPrimaryCurrency(); + + if ($rates === false) { + $conn =& $this->Application->GetADODBConnection(); + + $conn->nextQueryCachable = true; + $sql = 'SELECT ISO, RateToPrimary + FROM ' . $this->Application->getUnitOption('curr', 'TableName') . ' + WHERE Status = ' . STATUS_ACTIVE; + $rates = $conn->Query($sql); + + $this->Application->setCache($cache_key, $rates); } + + foreach ($rates as $rate) { + $this->SetRate($primary, $rate['ISO'], $rate['RateToPrimary']); + } } function GetRate($source_cur, $target_cur, $units = 1) { - $source_cur = ($source_cur == 'PRIMARY') ? $this->GetPrimaryCurrency() : $source_cur; - $target_cur = ($target_cur == 'PRIMARY') ? $this->GetPrimaryCurrency() : $target_cur; + $source_cur = ($source_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $source_cur; + $target_cur = ($target_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $target_cur; if($source_cur == $target_cur) { return 1; @@ -76,18 +86,6 @@ $this->ExchangeRates[$target_cur]['UNITS'] = $units; } - function GetPrimaryCurrency() - { - if(!$this->PrimaryCurrency) - { - $conn =& $this->Application->GetADODBConnection(); - $table = $this->Application->getUnitOption('curr', 'TableName'); - $sql = 'SELECT ISO FROM '.$table.' WHERE IsPrimary = 1'; - $this->PrimaryCurrency = $conn->GetOne($sql); - } - return $this->PrimaryCurrency; - } - function StoreRates($currencies=null) { $curr_object =& $this->Application->recallObject('curr', null, Array ('skip_autoload' => true)); @@ -127,7 +125,6 @@ function GetRatesData() { - $this->GetPrimaryCurrency(); $xml_parser = xml_parser_create(); $curl_helper =& $this->Application->recallObject('CurlHelper'); @@ -179,7 +176,6 @@ function GetRatesData() { - $this->GetPrimaryCurrency(); $xml_parser = xml_parser_create(); $curl_helper =& $this->Application->recallObject('CurlHelper'); @@ -225,7 +221,6 @@ $curl_helper =& $this->Application->recallObject('CurlHelper'); /* @var $curl_helper kCurlHelper */ - $this->GetPrimaryCurrency(); for($i = 0; $i < 10; $i++) { $time = adodb_mktime() - $i * 3600 * 24;