You are here

static function CurrencyExchangerBartFeenstraCurrency::load in Currency 7.2

Implements CurrencyExchangerInterface::load().

Overrides CurrencyExchangerInterface::load

2 calls to CurrencyExchangerBartFeenstraCurrency::load()
CurrencyExchangerBartFeenstraCurrency::loadMultiple in currency/includes/CurrencyExchangerBartFeenstraCurrency.inc
Implements CurrencyExchangerInterface::loadMultiple().
CurrencyExchangerBartFeenstraCurrencyWebTestCase::testCurrencyExchangerBartFeenstraCurrency in currency/tests/CurrencyConverterBartFeenstraCurrencyWebTestCase.test
Test currency exchange.

File

currency/includes/CurrencyExchangerBartFeenstraCurrency.inc, line 16
Contains class CurrencyExchangerBartFeenstraCurrency.

Class

CurrencyExchangerBartFeenstraCurrency
Provides fixed exchange rates as provided by bartfeenstra/currency.

Code

static function load($currency_code_from, $currency_code_to) {
  if (in_array($currency_code_from, BartFeenstra\Currency\Currency::resourceListAll()) && in_array($currency_code_to, BartFeenstra\Currency\Currency::resourceListAll())) {

    // Check if the requested rate is available.
    $currency_from = new Currency();
    $currency_from
      ->resourceLoad($currency_code_from);
    if ($currency_from && isset($currency_from->exchangeRates[$currency_code_to])) {
      return $currency_from->exchangeRates[$currency_code_to];
    }

    // Conversion rates are two-way. If a reverse rate is unavailable, set it.
    $currency_to = new Currency();
    $currency_to
      ->resourceLoad($currency_code_to);
    if ($currency_to && isset($currency_to->exchangeRates[$currency_code_from])) {
      return currency_divide(1, $currency_to->exchangeRates[$currency_code_from]);
    }
  }

  // There is no available exchange rate.
  return FALSE;
}