Exemple #1
0
 /**
  * Обновить данные котирововк
  * 
  * @return string
  */
 public function updateQuotations()
 {
     $quotationMapper = new Application_Model_QuotationMapper();
     $quotationModel = new Application_Model_Quotation();
     $currencyMapper = new Application_Model_CurrencyMapper();
     $quotationMapper->clearCache();
     $currencyMapper->clearCache();
     $now = Zend_Date::now();
     $nowUnixFormated = $now->toString('Y-M-d H:m:s');
     $currenciesFetched = $currencyMapper->fetchAll();
     $currencyArray = [];
     foreach ($currenciesFetched as $currency) {
         $providerCurrencyId = $currency->getProviderCurrencyId();
         $currencyArray[$providerCurrencyId] = $currency;
     }
     $quotationMapper->delete();
     $quotations = $this->_prepareData();
     foreach ($currencyArray as $baseProviderCurrencyId => $baseCurrency) {
         foreach ($currencyArray as $quotatedProviderCurrencyId => $quotatedCurrency) {
             if ($baseProviderCurrencyId == $quotatedProviderCurrencyId) {
                 continue;
             }
             $quotation = round($quotations[$baseProviderCurrencyId]['quotation'] / $quotations[$quotatedProviderCurrencyId]['quotation'], 2);
             $data = ['baseCurrencyId' => $baseCurrency->getId(), 'quotatedCurrencyId' => $quotatedCurrency->getId(), 'quotation' => $quotation, 'updatedAt' => $nowUnixFormated];
             $quotationModel->setOptions($data);
             $quotationMapper->save($quotationModel);
         }
     }
     return 'success';
 }
Exemple #2
0
 /**
  * Получить все данные
  * 
  * @return \Application_Model_Quotation  Результат выборки данных
  */
 public function fetchAll()
 {
     $cacheId = $this->_cachePrefix . 'all';
     $cache = Zend_Registry::get('cache');
     if (!($resultSet = $cache->load($cacheId))) {
         $resultSet = $this->getDbTable()->fetchAll();
         $cache->save($resultSet, $cacheId);
     }
     $entries = array();
     foreach ($resultSet as $row) {
         $entry = new Application_Model_Quotation();
         $entry->setId($row->id)->setBaseCurrencyId($row->baseCurrencyId)->setQuotatedCurrencyId($row->quotatedCurrencyId)->setQuotation($row->quotation)->setUpdatedAt($row->updatedAt);
         $entries[] = $entry;
     }
     return $entries;
 }