示例#1
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\Forwarder
  */
 protected function makeBean($resultset)
 {
     return ForwarderFactory::createFromArray($resultset);
 }
示例#2
0
 public function updateAction()
 {
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         $params["contacts"] = $this->getRequest()->getParam("contacts", array());
         $id = $this->getRequest()->getParam('id');
         //$idCourtyard = $this->getRequest()->getParam('id_courtyard');
         $courtyardParams = $this->getRequest()->getParam('courtyards');
         //die(print_r($courtyardParams));
         $forwarder = ForwarderQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the Forwarder with id {$id}"));
         //$courtyard = CourtyardQuery::create()->findOneOrThrow($idCourtyard, $this->i18n->_("It does not exist the Courtyard with id {$idCourtyard}"));
         try {
             $this->getForwarderCatalog()->beginTransaction();
             ForwarderFactory::populate($forwarder, $params);
             $this->getForwarderCatalog()->update($forwarder);
             //$this->getForwarderCatalog()->unlinkAllPortCustom($forwarder->getIdForwarder());
             foreach ($params['contacts'] as $idContact) {
                 $contact = ContactQuery::create()->findByPK($idContact);
                 $contact->setIdCompany($forwarder->getIdCompany());
                 $this->getContactCatalog()->update($contact);
             }
             foreach ($courtyardParams as $i => $courtyardParam) {
                 $idCourtyard = $courtyardParam['id_courtyard'];
                 $idAddress = $courtyardParam['id_address'];
                 if ($idCourtyard > 0) {
                     $courtyard = CourtyardQuery::create()->findByPKOrThrow($idCourtyard, $this->i18n->_("It does not exist the Courtyard with id {$idCourtyard}"));
                     CourtyardFactory::populate($courtyard, $courtyardParam);
                     $this->getCourtyardCatalog()->update($courtyard);
                     $this->getForwarderCatalog()->linkToPortCustom($forwarder->getIdForwarder(), $courtyard->getIdPortCustom());
                     $address = AddressQuery::create()->findByPKOrThrow($idAddress, $this->i18n->_("It does not exist the address with id {$idAddress}"));
                     AddressFactory::populate($address, $courtyardParam);
                     $this->getAddressCatalog()->update($address);
                 } else {
                     $newCourtyard = $courtyardParam;
                     $courtyard = CourtyardFactory::createFromArray($courtyardParam);
                     $courtyard->setIdForwarder($forwarder->getIdForwarder());
                     $this->getCourtyardCatalog()->create($courtyard);
                     $this->getForwarderCatalog()->linkToPortCustom($forwarder->getIdForwarder(), $courtyard->getIdPortCustom());
                     $arrayPhones = $newContacts['id_phone_number'];
                     $address = AddressFactory::createFromArray($newCourtyard);
                     $this->getAddressCatalog()->create($address);
                     //$this->getContactCatalog()->linkToAddress($contact->getIdPerson(), $address->getIdAddress(), $type);
                 }
             }
         } catch (Exception $e) {
             $this->getForwarderCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->setFlash('ok', $this->i18n->_("The Forwarder with id {$id} was updated"));
     $this->getForwarderCatalog()->commit();
     $this->_redirect('forwarder/list');
 }