Example #1
0
 /**
  *
  * @return array
  */
 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         // Get all params
         $params = $this->getRequest()->getParams();
         // Get countries info to port and address
         $countries = \Application\Query\CountryQuery::create()->find()->toCombo();
         try {
             // Initialice the DB transaction for all catalogs
             $this->getCatalog("PortCustomCatalog")->beginTransaction();
             $portCustom = PortCustomFactory::createFromArray($params);
             // 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);
                     }
                 }
             }
             $portCustom->setStatus(PortCustom::$Status["Active"]);
             // Create the port
             $this->getCatalog("PortCustomCatalog")->create($portCustom);
             // Foreach to create a record in database by courtyards and address
             foreach ($params["courtyards"] as $courtyardParams) {
                 // Set necessary extra data into object
                 $courtyardParams["id_port_custom"] = $portCustom->getIdPortCustom();
                 $courtyardParams["status"] = Courtyard::$Status["Active"];
                 $courtyardParams["country"] = $countries[$portCustom->getCode()];
                 if ($courtyardParams["id_forwarder"] == "null") {
                     $courtyardParams["id_forwarder"] = null;
                 }
                 if ($courtyardParams["id_contact"] == "null") {
                     $courtyardParams["id_contact"] = null;
                 }
                 $courtyard = CourtyardFactory::createFromArray($courtyardParams);
                 // save the record and create a link between Courtyard and Forwarder
                 $this->getCatalog("CourtyardCatalog")->create($courtyard);
             }
             // Commit al changes
             $this->getCatalog("PortCustomCatalog")->commit();
             $this->setFlash('ok', $this->i18n->_("Se ha guardado correctamente el "));
         } catch (Exception $e) {
             $this->getCatalog("PortCustomCatalog")->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('port-custom/list');
 }
Example #2
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\PortCustom
  */
 protected function makeBean($resultset)
 {
     return PortCustomFactory::createFromArray($resultset);
 }