Example #1
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\CustomsBroker
  */
 protected function makeBean($resultset)
 {
     return CustomsBrokerFactory::createFromArray($resultset);
 }
 /**
  *
  * @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");
 }