Ejemplo n.º 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';
 }
Ejemplo n.º 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;
 }
 public function dashboardAction()
 {
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::VALIDATE_FORM . '.js');
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::STATE_UPDATE . '.js');
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $currentUser = $auth->getIdentity();
     }
     $productMapper = new Application_Model_ProductMapper();
     $this->view->products = $productMapper->fetchAll();
     $userMapper = new Application_Model_UserMapper();
     $this->view->users = $userMapper->fetchAll();
     $mailMapper = new Application_Model_MailsettingMapper();
     $this->view->mailSettings = $mailMapper->fetchAll();
     $orderMapper = new Application_Model_OrderMapper();
     $this->view->orders = $orderMapper->fetchAll();
     $currencyMapper = new Application_Model_CurrencyMapper();
     $this->view->currencies = $currencyMapper->fetchAll();
     $forms = array();
     foreach ($this->view->mailSettings as $setting) {
         $form = new Application_Form_SubmitButton();
         $form->setAction($this->view->url(array('controller' => 'mailsettings', 'action' => 'delete'), null, true));
         $form->addAttribs(array('id' => 'delSettingForm' . $setting->id, 'onsubmit' => self::VALIDATE_FORM . "('delSettingForm" . $setting->id . "')"));
         $form->getElement('id')->setValue($setting->id);
         $form->getElement('submit')->setAttribs(array('class' => 'btn btn-danger'));
         $form->getElement('submit')->setLabel('Delete');
         $forms['delSettingForm'][] = $form;
         $form = new Application_Form_SubmitButton();
         if ($setting->getDefaultConfig()) {
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary disabled'));
             $form->getElement('submit')->setLabel('Default');
         } else {
             $form->addAttribs(array('id' => 'defSettingForm' . $setting->id, 'onsubmit' => self::VALIDATE_FORM . "('defSettingForm" . $setting->id . "')"));
             $form->setAction($this->view->url(array('controller' => 'mailsettings', 'action' => 'mkdefault'), null, true));
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary'));
             $form->getElement('submit')->setLabel('Make Default');
             $form->getElement('id')->setValue($setting->id);
         }
         $forms['defSettingForm'][] = $form;
     }
     //initialize forms
     foreach ($this->view->users as $user) {
         $form = new Application_Form_SubmitButton();
         if ($user->id == $currentUser->id || $user->getAdminId() == 1) {
             // is current user or is superuser
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-danger disabled'));
             $form->getElement('submit')->setLabel('Delete');
         } else {
             $form->setAction($this->view->url(array('controller' => 'users', 'action' => 'delete'), null, true));
             $form->addAttribs(array('id' => 'delUserForm' . $user->id, 'onsubmit' => self::VALIDATE_FORM . "('delUserForm" . $user->id . "')"));
             $form->getElement('id')->setValue($user->id);
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-danger'));
             $form->getElement('submit')->setLabel('Delete');
         }
         $forms['delUserForm'][] = $form;
         $form = new Application_Form_SubmitButton();
         if ($user->id == $currentUser->id || $user->getAdminId() == 1 || !$user->verified) {
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary disabled'));
             $form->getElement('submit')->setLabel('Make Admin');
         } else {
             if ($user->getAdminId()) {
                 $form->addAttribs(array('id' => 'umkUserForm' . $user->id, 'onsubmit' => self::VALIDATE_FORM . "('umkUserForm" . $user->id . "')"));
                 $form->setAction($this->view->url(array('controller' => 'users', 'action' => 'umkadmin'), null, true));
                 $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary'));
                 $form->getElement('submit')->setLabel('Unmake Admin');
             } else {
                 $form->addAttribs(array('id' => 'mkUserForm' . $user->id, 'onsubmit' => self::VALIDATE_FORM . "('mkUserForm" . $user->id . "')"));
                 $form->setAction($this->view->url(array('controller' => 'users', 'action' => 'mkadmin'), null, true));
                 $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary'));
                 $form->getElement('submit')->setLabel('Make Admin');
             }
             $form->getElement('id')->setValue($user->id);
         }
         $forms['mkUserForm'][] = $form;
     }
     // initialize forms
     foreach ($this->view->products as $i => $product) {
         $delForm = new Application_Form_DeleteProduct();
         $delForm->setAction($this->view->url(array('controller' => 'products', 'action' => 'delete'), null, true));
         $delForm->addAttribs(array('id' => 'delForm' . $product->id, 'onsubmit' => self::VALIDATE_FORM . "('delForm" . $product->id . "')"));
         $delForm->getElement('product_id')->setValue($product->id);
         $forms['delProductForm'][] = $delForm;
     }
     $this->view->forms = $forms;
 }