Index: branches/5.2.x/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r15340 -r15368 --- branches/5.2.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 15340) +++ branches/5.2.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 15368) @@ -1,6 +1,6 @@ Application->RecallVar('curr_iso'); + if ( $currency == 'selected' ) { + return $this->Application->RecallVar('curr_iso'); } - elseif ($currency == 'primary' || $currency == '') { - $iso = $this->Application->GetPrimaryCurrency(); + + if ( $currency == 'primary' || $currency == '' ) { + return $this->Application->GetPrimaryCurrency(); } - else { //explicit currency - $iso = $currency; - } - return $iso; + + // explicit currency + return $currency == 'field' && $field_currency ? $field_currency : $currency; } /** * Convert primary currency to selected (if they are the same, converter will just return) * * @param float $value - * @param string $iso + * @param string $target_iso + * @param string $source_iso * @return float */ - function ConvertCurrency($value, $iso) + function ConvertCurrency($value, $target_iso, $source_iso = 'PRIMARY') { $converter = $this->Application->recallObject('CurrencyRates'); /* @var $converter CurrencyRates */ - return $converter->Convert($value, 'PRIMARY', $iso); + return $converter->Convert($value, $source_iso, $target_iso); } function AddCurrencySymbol($value, $iso, $decimal_tag = '') { - static $decimal_separator = false; + $converter = $this->Application->recallObject('CurrencyRates'); + /* @var $converter CurrencyRates */ - $cache_key = 'iso_masks[%CurrSerial%]'; - $iso_masks = $this->Application->getCache($cache_key); - - if ($iso_masks === false) { - $this->Conn->nextQueryCachable = true; - $symbol_sql = 'IF(COALESCE(Symbol, "") = "", CONCAT(ISO, " "), Symbol)'; - - $sql = 'SELECT IF(SymbolPosition = 0, CONCAT(' . $symbol_sql . ', "%s"), CONCAT("%s", ' . $symbol_sql . ')), LOWER(ISO) AS ISO - FROM ' . $this->Application->getUnitOption('curr', 'TableName') . ' - WHERE Status = ' . STATUS_ACTIVE; - $iso_masks = $this->Conn->GetCol($sql, 'ISO'); - $this->Application->setCache($cache_key, $iso_masks); - } - - if ( $decimal_tag ) { - if ( $decimal_separator === false ) { - $language = $this->Application->recallObject('lang.current'); - /* @var $language LanguagesItem */ - - $decimal_separator = $language->GetDBField('DecimalPoint'); - } - - list ($integer_part, $decimal_part) = explode($decimal_separator, $value); - $value = $integer_part . $decimal_separator . '<' . $decimal_tag . '>' . $decimal_part . ''; - } - - $iso = strtolower($iso); - - return array_key_exists($iso, $iso_masks) ? sprintf($iso_masks[$iso], $value) : $value; + return $converter->AddCurrencySymbol($value, $iso, $decimal_tag); } /** @@ -888,16 +862,19 @@ } else { if (array_key_exists('currency', $params) && $params['currency']) { - $iso = $this->GetISO($params['currency']); + $source_iso = isset($params['currency_field']) ? $object->GetDBField($params['currency_field']) : 'PRIMARY'; + $target_iso = $this->GetISO($params['currency'], $source_iso); $original = $object->GetDBField($field); - $value = $this->ConvertCurrency($original, $iso); + + $value = $this->ConvertCurrency($original, $target_iso, $source_iso); + $object->SetDBField($field, $value); $object->SetFieldOption($field, 'converted', true); } $format = array_key_exists('format', $params) ? $params['format'] : false; if (!$format || $format == '$format') { - $format = null; + $format = NULL; } $value = $object->GetField($field, $format); @@ -913,7 +890,7 @@ if (array_key_exists('currency', $params) && $params['currency']) { $decimal_tag = isset($params['decimal_tag']) ? $params['decimal_tag'] : ''; - $value = $this->AddCurrencySymbol($value, $iso, $decimal_tag); + $value = $this->AddCurrencySymbol($value, $target_iso, $decimal_tag); $params['no_special'] = 1; } }