/** * * @static * @param Courtyard courtyard * @param array $fields */ public static function populate($courtyard, $fields) { parent::populate($courtyard, $fields); if (!$courtyard instanceof Courtyard) { static::throwException("El objecto no es un Courtyard"); } if (isset($fields['id_courtyard'])) { $courtyard->setIdCourtyard($fields['id_courtyard']); } if (isset($fields['id_address'])) { $courtyard->setIdAddress($fields['id_address']); } if (isset($fields['id_port_custom'])) { $courtyard->setIdPortCustom($fields['id_port_custom']); } if (isset($fields['id_forwarder'])) { $courtyard->setIdForwarder($fields['id_forwarder']); } if (isset($fields['id_contact'])) { $courtyard->setIdContact($fields['id_contact']); } if (isset($fields['name'])) { $courtyard->setName($fields['name']); } if (isset($fields['status'])) { $courtyard->setStatus($fields['status']); } }
/** * * makeBean * @param array $resultset * @return \Application\Model\Bean\Address */ protected function makeBean($resultset) { return AddressFactory::createFromArray($resultset); }
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'); }
/** * * @return array */ public function updateAction() { $params = $this->getRequest()->getParams(); $id = $params['id_customs_broker']; $customsBroker = CustomsBrokerQuery::create()->findByPKOrThrow($id, $this->i18n->_('It does not exist Customs Broker with id')); $this->getCustomsBrokerCatalog()->beginTransaction(); try { $address = AddressFactory::createFromArray($params); $this->getCatalog('AddressCatalog')->update($address); } catch (Exception $e) { //Address couldn't be created $this->getCustomsBrokerCatalog()->rollBack(); $this->setFlash('error', $this->i18n->_($e->getMessage())); } //updates the file and its register in the db and eliminates previous one $type = $_FILES['id_last_fee_file']['type']; if ($type) { try { $uploadPath = 'files/company/customs-broker/' . $params['id_company']; $fileUploader = new FileUploader("id_last_fee_file"); if ($fileUploader->isUpload()) { if ($customsBroker->getIdLastFeeFile()) { $idFile = $customsBroker->getIdLastFeeFile(); $feeFile = \Application\Query\FileQuery::create()->findByPK($idFile); //$this->getCatalog('FileCatalog')->deleteById($feeFile->getIdFile()); is_dir(unlink('public/' . $feeFile->getContent())); } if (strstr($type, "image") != false) { $uploadPath .= '/images'; $fileUploader->saveFile('public/' . $uploadPath, true); } else { $uploadPath .= '/files'; $fileUploader->saveFile('public/' . $uploadPath, false); } $myFile = new File(); $myFile->setContent($uploadPath . $fileUploader->getFileName()); $myFile->setType(file::$typeFile['typeFile']); $this->getCatalog('FileCatalog')->create($myFile); $customsBroker->setIdLastFeeFile($myFile->getIdFile()); } } catch (Exception $e) { //the images wasn't uploaded $this->setFlash('error', $this->i18n->_($e->getMessage())); } } try { $this->getCustomsBrokerCatalog()->unlinkAllPortCustom($id); $idsCustomsPort = $params['idsCustomsPort']; foreach ($idsCustomsPort as $idCustomsPort) { $this->getCustomsBrokerCatalog()->linkToPortCustom($customsBroker->getIdCustomsBroker(), $idCustomsPort); } } catch (Exception $e) { $this->setFlash('error', $this->i18n->_($e->getMessage())); } //Inserts a customs broker register try { CustomsBrokerFactory::populate($customsBroker, $params); $this->getCustomsBrokerCatalog()->update($customsBroker); } catch (Exception $e) { $this->setFlash('error', $this->i18n->_($e->getMessage())); } $this->getCustomsBrokerCatalog()->commit(); $this->setFlash('ok', $this->i18n->_("The Customs Brokers with id {$id} has been updated")); $this->_redirect("customs-broker/list"); }
/** * 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)); } }