Example #1
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\CustomsBroker
  */
 protected function makeBean($resultset)
 {
     return CustomsBrokerFactory::createFromArray($resultset);
 }
 /**
  * @author Jose Luis Suarez Nieto
  * @return array
  */
 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         try {
             $this->getCustomsBrokerCatalog()->beginTransaction();
             $customBroker = CustomsBrokerFactory::createFromArray($params);
             // Default status = active
             $customBroker->setStatus(CustomsBroker::$Status['Active']);
             //creates the file and its register in the db
             $type = $_FILES['id_last_fee_file']['type'];
             if ($type) {
                 try {
                     $uploadPath = 'public/files/company/customs-broker/' . $customBroker->getIdCompany();
                     $fileUploader = new FileUploader("id_last_fee_file");
                     if (strstr($type, "image") != false) {
                         $uploadPath .= '/images';
                         $fileUploader->saveFile($uploadPath, true);
                     } else {
                         $uploadPath .= 'files';
                         // 							echo getcwd().'<br>';
                         // 							echo $uploadPath;
                         // 							exit();
                         $fileUploader->saveFile($uploadPath, false);
                     }
                     $myFile = new File();
                     //$uploadPath.= 'files/company/customs-broker/'.$customBroker->getIdCompany();
                     $myFile->setContent($uploadPath . $fileUploader->getFileName());
                     $myFile->setType($type);
                     $this->getCatalog('FileCatalog')->create($myFile);
                     $customBroker->setIdLastFeeFile($myFile->getIdFile());
                 } catch (Exception $e) {
                     //the images wasn't uploaded
                     $this->getCustomsBrokerCatalog()->rollBack();
                     $this->setFlash('error', $this->i18n->_($e->getMessage()));
                 }
             }
             //Inserts a customs broker register
             $this->getCustomsBrokerCatalog()->create($customBroker);
             try {
                 $idsCustomsPort = $params['idsCustomsPort'];
                 foreach ($idsCustomsPort as $idCustomsPort) {
                     $this->getCustomsBrokerCatalog()->linkToPortCustom($customBroker->getIdCustomsBroker(), $idCustomsPort);
                 }
             } catch (Exception $e) {
                 $this->getCustomsBrokerCatalog()->rollBack();
                 $this->setFlash('error', $this->i18n->_($e->getMessage()));
             }
             $address = AddressFactory::createFromArray($params);
             $this->getAddressCatalog()->create($address);
             $this->getCustomsBrokerCatalog()->linkToAddress($customBroker->getIdCompany(), $address->getIdAddress(), $type);
         } catch (Exception $e) {
             $this->getCustomsBrokerCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
         $this->getCustomsBrokerCatalog()->commit();
         $id = $customBroker->getIdCustomsBroker();
         $this->setFlash('ok', $this->i18n->_("The Customs Broker with id {$id} has been created"));
         $this->_redirect("customs-broker/list");
     }
 }