You are here

class Currency in Currency 7.2

Same name in this branch
  1. 7.2 currency/includes/Currency.inc \Currency
  2. 7.2 currency/vendor/bartfeenstra/currency/src/BartFeenstra/Currency/Currency.php \BartFeenstra\Currency\Currency

Describes a currency.

Hierarchy

Expanded class hierarchy of Currency

26 string references to 'Currency'
currency.inc in currency/ctools/plugins/export_ui/currency.inc
CurrencyAmountFormElementWebTestCase::getInfo in currency/tests/CurrencyAmountFormElementWebTestCase.test
Implements DrupalTestCase::getInfo().
CurrencyAmountViewsHandlerFieldWebTestCase::getInfo in currency/tests/CurrencyAmountViewsHandlerFieldWebTestCase.test
Implements DrupalTestCase::getInfo().
CurrencyCRUDWebTestCase::getInfo in currency/tests/CurrencyCRUDWebTestCase.test
Implements DrupalTestCase::getInfo().
CurrencyExchangerBartFeenstraCurrencyWebTestCase::getInfo in currency/tests/CurrencyConverterBartFeenstraCurrencyWebTestCase.test
Implements DrupalTestCase::getInfo().

... See full list

File

currency/includes/Currency.inc, line 11
Contains class Currency.

View source
class Currency extends BartFeenstra\Currency\Currency {

  /**
   * Implements Ctools' exportables "export_module" property.
   *
   * @var string
   */
  public $export_module = 'currency';

  /**
   * Implements Ctools' exportables "export_type" property.
   *
   * @var string
   */
  public $export_type = 0;

  /**
   * The number of subunits to round amounts in this currency to.
   *
   * @see Currency::getRoundingStep()
   *
   * @var integer
   */
  public $rounding_step = NULL;

  /**
   * Implements Ctools' exportables "table" property.
   *
   * @var string
   */
  public $table = 'currency';

  /**
   * Implements Ctools' exportables "type" property.
   *
   * @var string
   */
  public $type = 'Local';

  /**
   * Implements __construct().
   */
  function __construct(array $properties = array()) {
    foreach ($properties as $property => $value) {
      $this->{$property} = $value;
    }
  }

  /**
   * Format an amount using this currency and the environment's default locale
   * pattern.
   *
   * This is a wrapper for CurrencyLocalePattern::format() in situations where
   * the environment's default locale pattern should be used.
   *
   * @param string $amount
   *   A numeric string.
   *
   * @return string
   */
  function format($amount) {
    return CurrencyLocalePattern::loadFromEnv()
      ->format($this, $amount);
  }

  /**
   * Returns the rounding step.
   *
   * @return string|false
   *   The rounding step as a numeric string, or FALSE if unavailable.
   */
  function getRoundingStep() {
    if (is_numeric($this->rounding_step)) {
      return $this->rounding_step;
    }
    elseif (is_numeric($this->subunits)) {
      return $this->subunits > 0 ? currency_divide(1, $this->subunits) : 1;
    }
    else {
      return FALSE;
    }
  }

  /**
   * Rounds an amount.
   *
   * @param string $amount
   *   A numeric string.
   *
   * @return string
   *   A numeric string.
   */
  function roundAmount($amount) {
    return currency_round($amount, $this
      ->getRoundingStep());
  }

  /**
   * Translates the human-readable currency title.
   *
   * @param string|null $language_code
   *   The ISO 639-1 code of the language to translate the title to, or NULL to
   *   use the default language.
   *
   * @return string
   */
  function translateTitle($language_code = NULL) {
    if (module_exists('i18n_string')) {
      return i18n_string('currency:currency:' . $this->ISO4217Code . ':title', $this->title, array(
        'langcode' => $language_code,
      ));
    }
    return $this->title;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Currency::$alternativeSigns public property Alternative (non-official) currency signs.
Currency::$exchangeRates public property Exchange rates to other currencies.
Currency::$export_module public property Implements Ctools' exportables "export_module" property.
Currency::$export_type public property Implements Ctools' exportables "export_type" property.
Currency::$ISO4217Code public property ISO 4217 currency code.
Currency::$ISO4217Number public property ISO 4217 currency number.
Currency::$resourceISO4217Codes public static property A list of the ISO 4217 codes of all known currency resources.
Currency::$resourcePath public static property The path to the resources directory.
Currency::$rounding_step public property The number of subunits to round amounts in this currency to.
Currency::$sign public property The currency's official sign, such as '€' or '$'.
Currency::$subunits public property The number of subunits this currency has.
Currency::$table public property Implements Ctools' exportables "table" property.
Currency::$title public property Human-readable title in US English.
Currency::$type public property Implements Ctools' exportables "type" property.
Currency::$usage public property This currency's usage.
Currency::format function Format an amount using this currency and the environment's default locale pattern.
Currency::getDecimals function Returns the number of decimals.
Currency::getRoundingStep function Returns the rounding step.
Currency::resourceDir public static function Returns the directory that contains the currency resources.
Currency::resourceDump public function Dumps this object to YAML code.
Currency::resourceListAll public static function Lists all currency resources in the library.
Currency::resourceLoad public function Loads a currency resource into this object.
Currency::resourceParse public function Parses a YAML file into this object.
Currency::roundAmount function Rounds an amount.
Currency::translateTitle function Translates the human-readable currency title.
Currency::__construct function Implements __construct().