Merge pull request #4372 from davecivicrm/CRM-15467
[civicrm-core.git] / CRM / Utils / Money.php
index 6ffa9b5c597504bcef1f595780a3b07d80c03e09..69e60df32226981d58fed7dbb8f0f657fe1c73a0 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -49,15 +49,17 @@ class CRM_Utils_Money {
    * %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 bool $onlyNumber
+   * @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 '';
@@ -69,10 +71,14 @@ class CRM_Utils_Money {
       $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;
     }
@@ -85,16 +91,12 @@ class CRM_Utils_Money {
       $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);
     }