Пример #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';
 }
Пример #2
0
 /**
  * Отображение данных
  */
 public function indexAction()
 {
     $quotation = new Application_Model_QuotationMapper();
     $quotationsFetched = $quotation->fetchAll();
     $currency = new Application_Model_CurrencyMapper();
     $currenciesFetched = $currency->fetchAll();
     $currencyArray = [];
     foreach ($currenciesFetched as $currency) {
         $currencyId = $currency->getId();
         $currencyArray[$currencyId] = $currency;
     }
     $quotationArray = [];
     foreach ($quotationsFetched as $quotation) {
         $baseCurrencyId = $quotation->getBaseCurrencyId();
         $quotatedCurrencyId = $quotation->getQuotatedCurrencyId();
         $quotationArray[$baseCurrencyId][$quotatedCurrencyId] = $quotation;
     }
     $this->view->title = 'Курсы валют';
     $this->view->currencies = $currencyArray;
     $this->view->quotations = $quotationArray;
 }