Exemple #1
0
 /**
  * Verify that initial currencies have been loaded
  */
 public function test_default_currencies()
 {
     APP_Currencies::init();
     $this->assertNotEmpty(APP_Currencies::get_currencies());
     $this->assertNotEmpty(APP_Currencies::get_currency('USD'));
     $this->assertEquals('US Dollars ($)', APP_Currencies::get_currency_string('USD'));
 }
<?php

APP_Currencies::init();
/**
 * Helps define currencies, their display preferences, and 
 * presenting price and currency information
 */
class APP_Currencies
{
    /**
     * Holds a list of all currently registered currencies
     * @var array
     */
    private static $currencies;
    /**
     * Initializes the registered currency list. 
     * Allows for localization of currency names.
     */
    public static function init()
    {
        self::$currencies = array('USD' => array('symbol' => '&#36;', 'name' => __('US Dollars', APP_TD)), 'EUR' => array('symbol' => '&euro;', 'name' => __('Euros', APP_TD)), 'GBP' => array('symbol' => '&pound;', 'name' => __('Pounds Sterling', APP_TD)), 'AUD' => array('symbol' => '&#36;', 'name' => __('Australian Dollars', APP_TD)), 'BRL' => array('symbol' => 'R&#36;', 'name' => __('Brazilian Real', APP_TD)), 'CAD' => array('symbol' => '&#36;', 'name' => __('Canadian Dollars', APP_TD)), 'CZK' => array('symbol' => 'K&#269;', 'name' => __('Czech Koruna', APP_TD)), 'DKK' => array('symbol' => 'kr', 'name' => __('Danish Krone', APP_TD)), 'HKD' => array('symbol' => '&#36;', 'name' => __('Hong Kong Dollar', APP_TD)), 'HUF' => array('symbol' => 'Ft', 'name' => __('Hungarian Forint', APP_TD)), 'ILS' => array('symbol' => '&#8362;', 'name' => __('Israeli Shekel', APP_TD)), 'JPY' => array('symbol' => '&yen;', 'name' => __('Japanese Yen', APP_TD)), 'MYR' => array('symbol' => 'RM', 'name' => __('Malaysian Ringgits', APP_TD)), 'MXN' => array('symbol' => '&#36;', 'name' => __('Mexican Peso', APP_TD)), 'NZD' => array('symbol' => '&#36;', 'name' => __('New Zealand Dollar', APP_TD)), 'NOK' => array('symbol' => 'kr', 'name' => __('Norwegian Krone', APP_TD)), 'PHP' => array('symbol' => 'P', 'name' => __('Philippine Pesos', APP_TD)), 'PLN' => array('symbol' => 'z&#322;', 'name' => __('Polish Zloty', APP_TD)), 'SGD' => array('symbol' => '&#36;', 'name' => __('Singapore Dollar', APP_TD)), 'SEK' => array('symbol' => 'kr', 'name' => __('Swedish Krona', APP_TD)), 'CHF' => array('symbol' => 'Fr', 'name' => __('Swiss Franc', APP_TD)), 'TWD' => array('symbol' => '&#36;', 'name' => __('Taiwan New Dollar', APP_TD)), 'THB' => array('symbol' => '&#3647;', 'name' => __('Thai Baht', APP_TD)), 'TRY' => array('symbol' => '&#8356;', 'name' => __('Turkish Lira', APP_TD)));
    }
    /**
     * Adds a currency to the list of registered currencies if the currency does not 
     * already exist.
     * Allows plugins and themes to define their own custom currencies.
     * 
     * @param string $currency_code Currency code used to identify currency.
     * @param array $args Array of options related to this currency
     * 	'symbol' => The symbol denoting the type of currency. IE: $ for USD
     * 	'name' => The formal name of the currency