/** * * @return array */ public function createAction() { $form = $this->getForm(); if ($this->getRequest()->isPost()) { $params = $this->getRequest()->getParams(); if (!$form->isValid($params)) { $this->view->setTpl("New"); $this->view->form = $form; return; } try { $this->getContactCatalog()->beginTransaction(); $contact = ContactFactory::createFromArray($form->getValues()); $this->getContactCatalog()->create($contact); $this->getContactCatalog()->commit(); $this->setFlash('ok', $this->i18n->_("Se ha guardado correctamente el ")); } catch (Exception $e) { $this->getContactCatalog()->rollBack(); $this->setFlash('error', $this->i18n->_($e->getMessage())); } } $this->_redirect('contact/list'); }
/** * * makeBean * @param array $resultset * @return \Application\Model\Bean\Contact */ protected function makeBean($resultset) { return ContactFactory::createFromArray($resultset); }
/** * This action create a new forwarder's contact * * @author Erick Guevara Martínez * @return json */ public function createnewforwardercontactAction() { if ($this->getRequest()->isPost()) { $params = $this->getRequest()->getParams(); try { $contact = ContactFactory::createFromArray($params["contact"]); if ($params["contact"]["id_forwarder"] != "") { $forwarder = ForwarderQuery::create()->findByPK($params["contact"]["id_forwarder"]); $contact->setIdCompany($forwarder->getIdCompany()); } else { $forwarder = new Forwarder(); } $this->getCatalog("ContactCatalog")->create($contact); foreach ($params["contact"]["phones"] as $phone) { if (strlen($phone["number"]) > 0) { $phoneNumbers = Application\Model\Factory\PhoneNumberFactory::createFromArray($phone); $this->getCatalog("PhoneNumberCatalog")->create($phoneNumbers); } } if (strlen($params["contact"]["email"]) > 0) { $email = Application\Model\Factory\EmailFactory::createFromArray($params["contact"]); $this->getCatalog("EmailCatalog")->create($email); $this->getCatalog("ContactCatalog")->linkToEmail($contact->getIdPerson(), $email->getIdEmail(), $type); } $address = AddressFactory::createFromArray($params["contact"]); $this->getCatalog("AddressCatalog")->create($address); $this->getCatalog("ContactCatalog")->linkToAddress($contact->getIdPerson(), $address->getIdAddress(), $type); //$this->getCatalog("ContactCatalog")->commit(); $response = array("result" => "ok", "contactId" => $contact->getIdContact(), "contactName" => $contact->getName(), "forwarderId" => $forwarder->getIdForwarder()); } catch (Exception $e) { $response = array("result" => "error", "message" => $e->getMessage()); } die(Zend_Json::encode($response)); } }