/**
  * This function search a currency exchange by id currency from and id currency to
  * 
  * @author Erick Guevara Martínez
  * @param int $from
  * @param int $to
  * @return CurrencyExchange
  */
 public function getByFromAndTo($from, $to)
 {
     $currencyExchange = new CurrencyExchange();
     if ($from == $to) {
         CurrencyExchangeFactory::populate($currencyExchange, array(CurrencyExchange::CURRENCY => $to, CurrencyExchange::RATE => 1));
     } else {
         if ($to == CurrencyExchange::$baseCurrency) {
             $currencyExchange = $this->getByPK($from);
         } else {
             if ($from == CurrencyExchange::$baseCurrency) {
                 $toExchange = $this->getByPK($to);
                 CurrencyExchangeFactory::populate($currencyExchange, array(CurrencyExchange::CURRENCY => $to, CurrencyExchange::RATE => $toExchange->invertExchangeRate()));
             } else {
                 if ($from != CurrencyExchange::$baseCurrency && $to != CurrencyExchange::$baseCurrency) {
                     $fromExchange = $this->getByPK($from);
                     $toExchange = $this->getByPK($to);
                     CurrencyExchangeFactory::populate($currencyExchange, array(CurrencyExchange::CURRENCY => $to, CurrencyExchange::RATE => $fromExchange->getRate() / $toExchange->getRate()));
                 }
             }
         }
     }
     return $currencyExchange;
 }
 /**
  *
  * @return array
  */
 public function updateAction()
 {
     $form = $this->getForm();
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         if (!$form->isValid($params)) {
             $this->view->setTpl("New");
             $this->view->form = $form;
             return;
         }
         $id = $this->getRequest()->getParam('id');
         $currencyExchange = CurrencyExchangeQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the CurrencyExchange with id {$id}"));
         try {
             $this->getCurrencyExchangeCatalog()->beginTransaction();
             CurrencyExchangeFactory::populate($currencyExchange, $form->getValues());
             $this->getCurrencyExchangeCatalog()->update($currencyExchange);
             $this->getCurrencyExchangeCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("Se actualizo correctamente el CurrencyExchange"));
         } catch (Exception $e) {
             $this->getCurrencyExchangeCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('currency-exchange/list');
 }