Esempio n. 1
0
 /**
  *
  * @return array
  */
 public function updateAction()
 {
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         $countries = \Application\Query\CountryQuery::create()->find()->toCombo();
         $portCustom = PortCustomQuery::create()->findByPKOrThrow($params["id_port_custom"], $this->i18n->_("It does not exist the PortCustom with id {$params["id_port_custom"]}"));
         try {
             $this->getCatalog("PortCustomCatalog")->beginTransaction();
             PortCustomFactory::populate($portCustom, $params);
             if ($params["air"] != PortCustom::$Air["Active"]) {
                 $portCustom->setAir(PortCustom::$Air["Inactive"]);
             }
             if ($params["sea"] != PortCustom::$Sea["Active"]) {
                 $portCustom->setSea(PortCustom::$Sea["Inactive"]);
             }
             if ($params["ground"] != PortCustom::$Ground["Active"]) {
                 $portCustom->setGround(PortCustom::$Ground["Inactive"]);
             }
             // Set if is a departure port or a destination port corresponding to port type
             if ($params["is"] == 1) {
                 $portCustom->setIsDeparture(1)->setIsDestination(2);
             } else {
                 if ($params["is"] == 2) {
                     $portCustom->setIsDeparture(2)->setIsDestination(1);
                 } else {
                     if ($params["is"] == 3) {
                         $portCustom->setIsDeparture(1)->setIsDestination(1);
                     }
                 }
             }
             //die("<pre>".print_r($portCustom, true)."</pre>");
             $this->getCatalog("PortCustomCatalog")->update($portCustom);
             //Foreach to process courtyards
             foreach ($params["courtyards"] as $courtyardParams) {
                 // Assign the country name for any case (insert or update)
                 $courtyardParams["country"] = $countries[$portCustom->getCode()];
                 if ($courtyardParams["id_forwarder"] == "null") {
                     $courtyardParams["id_forwarder"] = null;
                 }
                 if ($courtyardParams["id_contact"] == "null") {
                     $courtyardParams["id_contact"] = null;
                 }
                 // If courtyard have id then update courtyard, if it have id then create courtyard
                 if ($courtyardParams["id_courtyard"] > 0) {
                     // Find database courtyard
                     $courtyard = CourtyardQuery::create()->findByPKOrThrow($courtyardParams["id_courtyard"], $this->i18n->_("It does not exist the Courtyard with id {$courtyardParams["id_courtyard"]}"));
                     CourtyardFactory::populate($courtyard, $courtyardParams);
                     $this->getCatalog("CourtyardCatalog")->update($courtyard);
                 } else {
                     // Add extra data required to courtyard params
                     $courtyardParams["id_port_custom"] = $portCustom->getIdPortCustom();
                     $courtyardParams["status"] = Courtyard::$Status["Active"];
                     $courtyard = CourtyardFactory::createFromArray($courtyardParams);
                     // save the record and create a link between Courtyard and Forwarder
                     $this->getCatalog("CourtyardCatalog")->create($courtyard);
                 }
             }
             $this->getCatalog("PortCustomCatalog")->commit();
             $this->setFlash('ok', $this->i18n->_("Se actualizo correctamente el PortCustom"));
         } catch (Exception $e) {
             $this->getCatalog("PortCustomCatalog")->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('port-custom/list');
 }
Esempio n. 2
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\PortCustom
  */
 protected function makeBean($resultset)
 {
     return PortCustomFactory::createFromArray($resultset);
 }