Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorsgiehl <stefan@piwik.org>2015-10-09 20:18:51 +0300
committersgiehl <stefan@piwik.org>2015-10-11 15:46:00 +0300
commit760ff363143d960528bd9f2ebe2d97d98582c8c4 (patch)
tree3e2c722dca198643e9b1dca1e46de8d0118d5ce0 /core
parentdb258371a505f969cb2a997c4d7871d8a3b6ffe5 (diff)
use new currency number formats
Diffstat (limited to 'core')
-rw-r--r--core/Metrics/Formatter.php6
-rw-r--r--core/NumberFormatter.php38
-rwxr-xr-xcore/Twig.php4
3 files changed, 41 insertions, 7 deletions
diff --git a/core/Metrics/Formatter.php b/core/Metrics/Formatter.php
index c2b8a1062d..69d32bc628 100644
--- a/core/Metrics/Formatter.php
+++ b/core/Metrics/Formatter.php
@@ -149,21 +149,16 @@ class Formatter
public function getPrettyMoney($value, $idSite)
{
$space = ' ';
-
$currencySymbol = self::getCurrencySymbol($idSite);
-
$currencyBefore = $currencySymbol . $space;
$currencyAfter = '';
-
// (maybe more currencies prefer this notation?)
$currencySymbolToAppend = array('€', 'kr', 'zł');
-
// manually put the currency symbol after the amount
if (in_array($currencySymbol, $currencySymbolToAppend)) {
$currencyAfter = $space . $currencySymbol;
$currencyBefore = '';
}
-
// if the input is a number (it could be a string or INPUT form),
// and if this number is not an int, we round to precision 2
if (is_numeric($value)) {
@@ -175,7 +170,6 @@ class Formatter
$value = sprintf("%01." . $precision . "f", $value);
}
}
-
$prettyMoney = $currencyBefore . $value . $currencyAfter;
return $prettyMoney;
}
diff --git a/core/NumberFormatter.php b/core/NumberFormatter.php
index 5324b552a0..f4b446daee 100644
--- a/core/NumberFormatter.php
+++ b/core/NumberFormatter.php
@@ -23,6 +23,9 @@ class NumberFormatter extends Singleton
/** @var string language specific pattern for percent numbers */
protected $patternPercent;
+ /** @var string language specific pattern for currency numbers */
+ protected $patternCurrency;
+
/** @var string language specific plus sign */
protected $symbolPlus;
@@ -53,6 +56,7 @@ class NumberFormatter extends Singleton
public function __construct()
{
$this->patternNumber = Piwik::translate('Intl_NumberFormatNumber');
+ $this->patternCurrency = Piwik::translate('Intl_NumberFormatCurrency');
$this->patternPercent = Piwik::translate('Intl_NumberFormatPercent');
$this->symbolPlus = Piwik::translate('Intl_NumberSymbolPlus');
$this->symbolMinus = Piwik::translate('Intl_NumberSymbolMinus');
@@ -140,6 +144,40 @@ class NumberFormatter extends Singleton
}
/**
+ * Formats given number as percent value
+ * @param string|int|float $value
+ * @param string $currency
+ * @param int $precision
+ * @return mixed|string
+ */
+ public function formatCurrency($value, $currency, $precision=2)
+ {
+ static $positivePattern, $negativePattern;
+
+ if (empty($positivePatter) || empty($negativePattern)) {
+ list($positivePattern, $negativePattern) = $this->parsePattern($this->patternCurrency);
+ }
+
+ $newValue = trim($value, " \0\x0B$currency");
+ if (!is_numeric($newValue)) {
+ return $value;
+ }
+
+ $negative = (bccomp('0', $value, 12) == 1);
+ $pattern = $negative ? $negativePattern : $positivePattern;
+
+ if ($newValue == round($newValue)) {
+ // if no fraction digits available, don't show any
+ $value = $this->formatNumberWithPattern($pattern, $newValue, 0, 0);
+ } else {
+ // show given count of fraction digits otherwise
+ $value = $this->formatNumberWithPattern($pattern, $newValue, $precision, $precision);
+ }
+
+ return str_replace('¤', $currency, $value);
+ }
+
+ /**
* Formats the given number with the given pattern
*
* @param string $pattern
diff --git a/core/Twig.php b/core/Twig.php
index 7267e98fed..90b9643622 100755
--- a/core/Twig.php
+++ b/core/Twig.php
@@ -12,6 +12,7 @@ use Exception;
use Piwik\Container\StaticContainer;
use Piwik\DataTable\Filter\SafeDecodeLabel;
use Piwik\Metrics\Formatter;
+use Piwik\Tracker\GoalManager;
use Piwik\View\RenderTokenParser;
use Piwik\Visualization\Sparkline;
use Twig_Environment;
@@ -312,7 +313,8 @@ class Twig
}
$idSite = func_get_args();
$idSite = $idSite[1];
- return $formatter->getPrettyMoney($amount, $idSite);
+ $currencySymbol = Formatter::getCurrencySymbol($idSite);
+ return NumberFormatter::getInstance()->formatCurrency($amount, $currencySymbol, GoalManager::REVENUE_PRECISION);
});
$this->twig->addFilter($moneyFilter);
}