Piwik\Site::getCurrencySymbolFor PHP Method

getCurrencySymbolFor() public static method

Returns the currency of the site with the specified ID.
public static getCurrencySymbolFor ( integer $idsite ) : string
$idsite integer The site ID.
return string
    public static function getCurrencySymbolFor($idsite)
    {
        $currency = self::getCurrencyFor($idsite);
        $symbols = self::getCurrencyList();
        if (isset($symbols[$currency])) {
            return $symbols[$currency][0];
        }
        return '';
    }

Usage Example

Example #1
0
 /**
  * Returns a pretty formated monetary value using the currency associated with a site.
  *
  * @param int|string $value The monetary value to format.
  * @param int $idSite The ID of the site whose currency will be used.
  * @return string
  * @api
  */
 public function getPrettyMoney($value, $idSite)
 {
     $space = ' ';
     $currencySymbol = Site::getCurrencySymbolFor($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)) {
         if ($value == round($value)) {
             // 0.0 => 0
             $value = round($value);
         } else {
             $precision = GoalManager::REVENUE_PRECISION;
             $value = sprintf("%01." . $precision . "f", $value);
         }
     }
     $prettyMoney = $currencyBefore . $value . $currencyAfter;
     return $prettyMoney;
 }
All Usage Examples Of Piwik\Site::getCurrencySymbolFor