getFileCache( 'currencies', $locale, array(&$this, '_cacheMiss') ); $cacheTime = $cache->getCacheTime(); if ($cacheTime !== null && $cacheTime < filemtime($this->getCurrencyFilename($locale))) { $cache->flush(); } } return $cache; } function _cacheMiss(&$cache, $id) { static $allCurrencies; if (!isset($allCurrencies)) { // Add a locale load to the debug notes. $notes =& Registry::get('system.debug.notes'); $filename = $this->getCurrencyFilename(Locale::getLocale()); $notes[] = array('debug.notes.currencyListLoad', array('filename' => $filename)); // Reload locale registry file $xmlDao = &new XMLDAO(); $data = $xmlDao->parseStruct($filename, array('currency')); // Build array with ($charKey => array(stuff)) if (isset($data['currency'])) { foreach ($data['currency'] as $currencyData) { $allCurrencies[$currencyData['attributes']['code_alpha']] = array( $currencyData['attributes']['name'], $currencyData['attributes']['code_numeric'] ); } } asort($allCurrencies); $cache->setEntireCache($allCurrencies); } return null; } function getCurrencyFilename($locale) { return "locale/$locale/currencies.xml"; } /** * Retrieve a currency by alpha currency ID. * @param $currencyId int * @return Currency */ function &getCurrencyByAlphaCode($codeAlpha) { $cache =& $this->_getCache(); return $this->_returnCurrencyFromRow($codeAlpha, $cache->get($codeAlpha)); } /** * Retrieve an array of all currencies. * @return array of Currencies */ function &getCurrencies() { $cache =& $this->_getCache(); $returner = array(); foreach ($cache->getContents() as $codeAlpha => $entry) { $returner[] =& $this->_returnCurrencyFromRow($codeAlpha, $entry); } return $returner; } /** * Internal function to return a Currency object from a row. * @param $row array * @return Currency */ function &_returnCurrencyFromRow($codeAlpha, &$entry) { $currency = &new Currency(); $currency->setCodeAlpha($codeAlpha); $currency->setName($entry[0]); $currency->setCodeNumeric($entry[1]); HookRegistry::call('CurrencyDAO::_returnCurrencyFromRow', array(&$currency, &$codeAlpha, &$entry)); return $currency; } } ?>