/** * * @param int $idFolioImport */ private function getBooking($idBooking) { if ($idBooking) { $booking = BookingQuery::create()->findByPK($idBooking)->toArray(); $freightForwarder = BookingFileQuery::create()->whereAdd(BookingFile::ID_BOOKING, $booking['id_booking'])->whereAdd(BookingFile::DOCUMENT_TYPE, BookingFile::$DocumentType['FreightForwarder'])->count(); if ($freightForwarder) { $freightForwarder = BookingFileQuery::create()->whereAdd(BookingFile::ID_BOOKING, $booking['id_booking'])->whereAdd(BookingFile::DOCUMENT_TYPE, BookingFile::$DocumentType['FreightForwarder'])->findOne()->getContent(); $booking['freight_forwarder'] = basename($freightForwarder); } $BlMaster = BookingFileQuery::create()->whereAdd(BookingFile::ID_BOOKING, $booking['id_booking'])->whereAdd(BookingFile::DOCUMENT_TYPE, BookingFile::$DocumentType['BlMaster'])->count(); if ($BlMaster) { $BlMaster = BookingFileQuery::create()->whereAdd(BookingFile::ID_BOOKING, $booking['id_booking'])->whereAdd(BookingFile::DOCUMENT_TYPE, BookingFile::$DocumentType['BlMaster'])->findOne()->getContent(); $booking['bl_master'] = basename($BlMaster); } $myItinerary = ItineraryQuery::create()->whereAdd(Itinerary::ID_BOOKING, $id)->count(); if ($myItinerary) { $myItinerary = ItineraryQuery::create()->whereAdd(Itinerary::ID_BOOKING, $id)->fetchAll(); $booking['myItinerary'] = $myItinerary; } } else { $booking = null; } return $booking; }
/** * * @author joseluis */ public function saveFileAction() { $params = $this->getRequest()->getParams(); $id = $params['id']; $booking = BookingQuery::create()->findByPK($id)->toArray(); $path = 'booking/' . $id . '/'; $documentType = $params['documentType']; $type = array_flip(BookingFile::$DocumentType); $name = $type[$documentType]; $savedFile = $this->saveFile('file', $path, $name); $bookingFile = new BookingFile(); $fileCount = BookingFileQuery::create()->whereAdd('BookingFile.' . BookingFile::ID_BOOKING, $id)->whereAdd('BookingFile.' . BookingFile::DOCUMENT_TYPE, $documentType)->count(); if ($fileCount) { $bookingFile = BookingFileQuery::create()->whereAdd('BookingFile.' . BookingFile::ID_BOOKING, $id)->whereAdd('BookingFile.' . BookingFile::DOCUMENT_TYPE, $documentType)->findOne(); // if($bookingFile->getType()==1){ // $point = strripos($bookingFile->getContent(), '.'); // $fileExtension = substr($bookingFile->getContent(),$point); // $fileName = substr($bookingFile->getContent(), 0,$point); // $file = 'public/'.$fileName.$fileExtension; // if (file_exists($file)) unlink($file); // $file = 'public/'.$fileName.'_o'.$fileExtension; // if (file_exists($file)) unlink($file); // $file = 'public/'.$fileName.'_mini'.$fileExtension; // if (file_exists($file)) unlink($file); // } // else{ // if (file_exists('public/'.$bookingFile->getContent())) // unlink('public/'.$bookingFile->getContent()); // } $bookingFile->setContent($savedFile->getContent()); $bookingFile->setType($savedFile->getType()); $this->getCatalog('BookingFileCatalog')->beginTransaction(); try { $this->getCatalog('BookingFileCatalog')->update($bookingFile); $this->getCatalog('BookingFileCatalog')->commit(); $this->setFlash('ok', $this->i18n->_($this->CREATE_FILE_OK)); } catch (Exception $e) { $this->getCatalog('BookingFileCatalog')->rollBack(); $this->setFlash('error', $this->i18n->_($this->ERROR)); } } else { $bookingFile->setContent($savedFile->getContent()); $bookingFile->setType($savedFile->getType()); $bookingFile->setIdBooking($id); $bookingFile->setDocumentType($documentType); $this->getCatalog('BookingFileCatalog')->beginTransaction(); try { $this->getCatalog('BookingFileCatalog')->create($bookingFile); $this->getCatalog('BookingFileCatalog')->commit(); $documentType = $this->getDocumentType($documentType); //callback functions switch ($documentType) { case 'FreightForwarder': break; case 'BlMaster': $this->blMasterCallBack($id); break; } $this->setFlash('ok', $this->i18n->_($this->CREATE_FILE_OK)); } catch (Exception $e) { $this->getCatalog('BookingFileCatalog')->rollBack(); $this->setFlash('error', $this->i18n->_($this->ERROR)); } } $this->_redirect('folio-import/list'); }