コード例 #1
0
ファイル: jbmoney.php プロジェクト: alexmixaylov/real
 /**
  * Get all currency values and cache in memory
  */
 public function init()
 {
     // optimize
     if (!empty(self::$curList)) {
         return self::$curList;
     }
     $this->app->jbdebug->mark('jbmoney::init::start');
     $curParams = $this->_config->getGroup('cart.currency')->get('list');
     $ttl = (int) $this->_config->get('currency_ttl', 1440, 'cart.config');
     $cacheKey = $this->_jbcache->hash(array('params' => (array) $curParams, 'date' => date('d-m-Y'), 'ttl' => $ttl));
     self::$curList = $this->_jbcache->get($cacheKey, 'currency', true, array('ttl' => $ttl));
     if (empty(self::$curList)) {
         $elements = $this->app->jbcartposition->loadElements('currency');
         self::$curList = array(JBCartValue::DEFAULT_CODE => array('code' => JBCartValue::DEFAULT_CODE, 'value' => 1, 'name' => JText::_('JBZOO_CURRENCY_DEFAULT_CODE'), 'format' => $this->_defaultFormat), self::PERCENT => array('code' => self::PERCENT, 'value' => 1, 'name' => JText::_('JBZOO_CART_CURRENCY_PERCENT'), 'format' => array_merge($this->_defaultFormat, array('symbol' => self::PERCENT))));
         $noCache = null;
         // fallback flag
         /** @type JBCartElementCurrency $element */
         foreach ($elements as $element) {
             $code = $element->getCode();
             if (empty($code)) {
                 continue;
             }
             try {
                 if ($noCache) {
                     // speedup if fatal errors have appeared
                     $value = $element->getFallbackValue();
                 } else {
                     $value = $element->getValue($code);
                 }
             } catch (JBCartElementCurrencyException $e) {
                 $noCache = time();
                 $value = $element->getFallbackValue();
                 if (JDEBUG || !$this->app->jbenv->isSite()) {
                     $this->app->jbnotify->warning($e->getMessage());
                 }
             }
             if ($code && $value > 0) {
                 self::$curList[$code] = array('code' => $code, 'value' => $value, 'name' => $element->getName(), 'format' => $element->getFormat());
             }
         }
         if (count(self::$curList) == 2 || !isset(self::$curList['eur'])) {
             self::$curList['eur'] = self::$curList[JBCartValue::DEFAULT_CODE];
         }
         if (!$noCache) {
             $this->_jbcache->set($cacheKey, self::$curList, 'currency', true, array('ttl' => $ttl));
         }
     }
     $this->app->jbdebug->mark('jbmoney::init::finish');
     return self::$curList;
 }