<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
* %C - the currency ISO code (e.g., 'USD') if provided
* %c - the currency symbol (e.g., '$') if available
*
- * @param float $amount the monetary amount to display (1234.56)
- * @param string $currency the three-letter ISO currency code ('USD')
- * @param string $format the desired currency format
+ * @param float $amount the monetary amount to display (1234.56)
+ * @param string $currency the three-letter ISO currency code ('USD')
+ * @param string $format the desired currency format
+ * @param string $valueFormat the desired monetary value display format (e.g. '%!i')
*
* @return string formatted monetary string
*
* @static
*/
- static function format($amount, $currency = NULL, $format = NULL, $onlyNumber = FALSE) {
+ static function format($amount, $currency = NULL, $format = NULL, $onlyNumber = FALSE, $valueFormat = NULL) {
if (CRM_Utils_System::isNull($amount)) {
return '';
if (!$format) {
$format = $config->moneyformat;
}
-
+
+ if (!$valueFormat) {
+ $valueFormat = $config->moneyvalueformat;
+ }
+
if ($onlyNumber) {
// money_format() exists only in certain PHP install (CRM-650)
if (is_numeric($amount) and function_exists('money_format')) {
- $amount = money_format($config->moneyvalueformat, $amount);
+ $amount = money_format($valueFormat, $amount);
}
return $amount;
}
if (!self::$_currencySymbols) {
- $currencySymbolName = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array('labelColumn' => 'name'));
- $currencySymbol = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency');
-
- self::$_currencySymbols = array_combine($currencySymbolName, $currencySymbol);
+ self::$_currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array('keyColumn' => 'name', 'labelColumn' => 'symbol'));
}
if (!$currency) {
$currency = $config->defaultCurrency;
}
- if (!$format) {
- $format = $config->moneyformat;
- }
-
// money_format() exists only in certain PHP install (CRM-650)
// setlocale() affects native gettext (CRM-11054, CRM-9976)
if (is_numeric($amount) && function_exists('money_format')) {
$lc = setlocale(LC_MONETARY, 0);
setlocale(LC_MONETARY, 'en_US.utf8', 'en_US', 'en_US.utf8', 'en_US', 'C');
- $amount = money_format($config->moneyvalueformat, $amount);
+ $amount = money_format($valueFormat, $amount);
setlocale(LC_MONETARY, $lc);
}