示例#1
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\Forwarder
  */
 protected function makeBean($resultset)
 {
     return ForwarderFactory::createFromArray($resultset);
 }
示例#2
0
 /**
  *
  * @return array
  */
 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         $params["courtyards"] = $this->getRequest()->getParam("courtyards", array());
         $params["contacts"] = $this->getRequest()->getParam("contacts", array());
         $params["name"] = $this->getRequest()->getParam("name");
         try {
             $this->getForwarderCatalog()->beginTransaction();
             $forwarder = ForwarderFactory::createFromArray($params);
             // Default status = active
             $forwarder->setStatus(Forwarder::$Status['Active']);
             // Create Forwarder
             $this->getForwarderCatalog()->create($forwarder);
             //Create courtyards
             foreach ($params["courtyards"] as $courtyardParams) {
                 $courtyard = CourtyardFactory::createFromArray($courtyardParams);
                 $courtyard->setIdForwarder($forwarder->getIdForwarder());
                 $this->getCourtyardCatalog()->create($courtyard);
                 $this->getForwarderCatalog()->linkToPortCustom($forwarder->getIdForwarder(), $courtyard->getIdPortCustom());
             }
             foreach ($params['contacts'] as $id) {
                 $contact = ContactQuery::create()->findByPK($id);
                 $contact->setIdCompany($forwarder->getIdCompany());
                 $this->getContactCatalog()->update($contact);
             }
             // Commit last change in database
             $this->getForwarderCatalog()->commit();
             $id = $forwarder->getIdForwarder();
         } catch (Exception $e) {
             // Roll back any change in database
             $this->getForwarderCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
             $this->_redirect('forwarder/list');
         }
     }
     $this->setFlash('ok', $this->i18n->_("The Forwarder with id {$id} was created"));
     $this->_redirect('forwarder/list');
 }