コード例 #1
0
ファイル: ContactController.php プロジェクト: Eximagen/sochi
 /**
  *
  * @return array
  */
 public function updateAction()
 {
     $form = $this->getForm();
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         if (!$form->isValid($params)) {
             $this->view->setTpl("New");
             $this->view->form = $form;
             return;
         }
         $id = $this->getRequest()->getParam('id');
         $contact = ContactQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the Contact with id {$id}"));
         try {
             $this->getContactCatalog()->beginTransaction();
             ContactFactory::populate($contact, $form->getValues());
             $this->getContactCatalog()->update($contact);
             $this->getContactCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("Se actualizo correctamente el Contact"));
         } catch (Exception $e) {
             $this->getContactCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('contact/list');
 }
コード例 #2
0
ファイル: ContactCatalog.php プロジェクト: Eximagen/sochi
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\Contact
  */
 protected function makeBean($resultset)
 {
     return ContactFactory::createFromArray($resultset);
 }
コード例 #3
0
 /**
  * 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));
     }
 }