diff options
-rw-r--r-- | core/Metrics/Formatter.php | 3 | ||||
-rw-r--r-- | core/MetricsFormatter.php | 72 | ||||
-rw-r--r-- | plugins/API/ProcessedReport.php | 4 |
3 files changed, 74 insertions, 5 deletions
diff --git a/core/Metrics/Formatter.php b/core/Metrics/Formatter.php index a2f2d928ae..315e21b8ca 100644 --- a/core/Metrics/Formatter.php +++ b/core/Metrics/Formatter.php @@ -21,9 +21,6 @@ use Piwik\Tracker\GoalManager; * method when formatting Metrics. * * @api - * - * TODO: backwards compatibility, re-introduce MetricsFormatter as deprecated and make it use Formatter internally. - * do after tests passing. */ class Formatter { diff --git a/core/MetricsFormatter.php b/core/MetricsFormatter.php new file mode 100644 index 0000000000..daa8710fc6 --- /dev/null +++ b/core/MetricsFormatter.php @@ -0,0 +1,72 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik; + +use Piwik\Metrics\Formatter; +use Piwik\Plugins\API\ProcessedReport; + +/** + * Contains helper function that format numerical values in different ways. + * + * @deprecated + */ +class MetricsFormatter +{ + private static $formatter = null; + private static $htmlFormatter = null; + + public static function getFormatter($isHtml = false) + { + if ($isHtml) { + if (self::$formatter === null) { + self::$formatter = new Formatter(); + } + return self::$formatter; + } else { + if (self::$htmlFormatter === null) { + self::$htmlFormatter = new Formatter\Html(); + } + return self::$htmlFormatter; + } + } + + public static function getPrettyNumber($value) + { + return self::getFormatter()->getPrettyNumber($value); + } + + public static function getPrettyTimeFromSeconds($numberOfSeconds, $displayTimeAsSentence = true, $isHtml = true, $round = false) + { + return self::getFormatter($isHtml)->getPrettyTimeFromSeconds($numberOfSeconds, $displayTimeAsSentence, $round); + } + + public static function getPrettySizeFromBytes($size, $unit = null, $precision = 1) + { + return self::getFormatter()->getPrettySizeFromBytes($size, $unit, $precision); + } + + public static function getPrettyMoney($value, $idSite, $isHtml = true) + { + return self::getFormatter($isHtml)->getPrettyMoney($value, $idSite); + } + + public static function getPrettyValue($idSite, $columnName, $value, $isHtml) + { + return ProcessedReport::getPrettyValue(self::getFormatter($isHtml), $idSite, $columnName, $value); + } + + public static function getCurrencySymbol($idSite) + { + return Formatter::getCurrencySymbol($idSite); + } + + public static function getCurrencyList() + { + return Formatter::getCurrencyList(); + } +} diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index 50cf8618e5..cd70eff8b9 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -676,7 +676,7 @@ class ProcessedReport } // TODO: should not call this for formatted processed metrics - $prettyValue = $this->getPrettyValue($formatter, $idSiteForRow, $columnName, $columnValue, $htmlAllowed = false); + $prettyValue = self::getPrettyValue($formatter, $idSiteForRow, $columnName, $columnValue, $htmlAllowed = false); $enhancedRow->addColumn($columnName, $prettyValue); } // For example the Maps Widget requires the raw metrics to do advanced datavis elseif ($returnRawMetrics) { @@ -810,7 +810,7 @@ class ProcessedReport * @param bool $isHtml If true, replaces all spaces with `' '`. * @return string */ - private function getPrettyValue(Formatter $formatter, $idSite, $columnName, $value) + public static function getPrettyValue(Formatter $formatter, $idSite, $columnName, $value) { if (!is_numeric($value)) { return $value; |