From d13dda978d768a597da0770bbbcd4d316684f2ca Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 5 Jun 2020 09:37:11 +0200 Subject: [PATCH 1/2] allow forced filename --- .../Model/AbstractClasses/pdfdocumentsGeneric.php | 11 +++++++++++ .../Model/AbstractClasses/pdfdocumentsOrder.php | 5 +++++ .../Model/Interfaces/pdfdocumentsGenericInterface.php | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/Application/Model/AbstractClasses/pdfdocumentsGeneric.php b/Application/Model/AbstractClasses/pdfdocumentsGeneric.php index b2b9292..eb70aa5 100644 --- a/Application/Model/AbstractClasses/pdfdocumentsGeneric.php +++ b/Application/Model/AbstractClasses/pdfdocumentsGeneric.php @@ -39,6 +39,9 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface /** @var Smarty */ public $oSmarty; + /** @var string */ + public $filename; + /** * pdfDocumentsGeneric constructor. */ @@ -126,6 +129,14 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface return [self::PDF_ORIENTATION_PORTRAIT, 'A4', 'de']; } + /** + * @param $filename + */ + public function setFilename($filename) + { + $this->filename = $filename; + } + /** * Gets proper file name * diff --git a/Application/Model/AbstractClasses/pdfdocumentsOrder.php b/Application/Model/AbstractClasses/pdfdocumentsOrder.php index b719dd8..14f7b1c 100644 --- a/Application/Model/AbstractClasses/pdfdocumentsOrder.php +++ b/Application/Model/AbstractClasses/pdfdocumentsOrder.php @@ -66,6 +66,11 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt */ public function getFilename() { + // forced filename from setFilename() + if ($this->filename) { + return $this->filename; + } + $sTrimmedBillName = trim($this->getOrder()->getFieldData('oxbilllname')); return implode( diff --git a/Application/Model/Interfaces/pdfdocumentsGenericInterface.php b/Application/Model/Interfaces/pdfdocumentsGenericInterface.php index acc0751..b8b1a97 100644 --- a/Application/Model/Interfaces/pdfdocumentsGenericInterface.php +++ b/Application/Model/Interfaces/pdfdocumentsGenericInterface.php @@ -56,6 +56,11 @@ interface pdfdocumentsGenericInterface */ public function genPdf($sFilename, $iSelLang = 0, $target = 'I'); + /** + * @param string $filename + */ + public function setFilename($filename); + /** * @return string */ From 0edb64153a37cecb08dda1f8093bb6f030fd30eb Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 5 Jun 2020 10:06:58 +0200 Subject: [PATCH 2/2] add filename extension if it's missing --- .../AbstractClasses/pdfdocumentsGeneric.php | 33 +++++++++++++++++++ .../AbstractClasses/pdfdocumentsOrder.php | 18 +++++----- .../pdfdocumentsGenericInterface.php | 7 ++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Application/Model/AbstractClasses/pdfdocumentsGeneric.php b/Application/Model/AbstractClasses/pdfdocumentsGeneric.php index eb70aa5..9009880 100644 --- a/Application/Model/AbstractClasses/pdfdocumentsGeneric.php +++ b/Application/Model/AbstractClasses/pdfdocumentsGeneric.php @@ -36,6 +36,8 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface const PDF_ORIENTATION_PORTRAIT = 'P'; const PDF_ORIENTATION_LANDSCAPE = 'L'; + public $filenameExtension = 'pdf'; + /** @var Smarty */ public $oSmarty; @@ -137,6 +139,37 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface $this->filename = $filename; } + /** + * @param string $sFilename + * + * @return string + */ + public function getFilename() + { + // forced filename from setFilename() + if ($this->filename) { + return $this->addFilenameExtension($this->filename); + } + + return $this->addFilenameExtension($this->getTypeForFilename()); + } + + /** + * @param string $filename + * + * @return string + */ + public function addFilenameExtension($filename) + { + $extension = $this->filenameExtension; + $extensionLength = (strlen($extension) + 1) * -1; + if ((bool) strlen($extension) && substr($filename, $extensionLength) != '.'.$extension) { + $filename .= '.'.$extension; + } + + return $filename; + } + /** * Gets proper file name * diff --git a/Application/Model/AbstractClasses/pdfdocumentsOrder.php b/Application/Model/AbstractClasses/pdfdocumentsOrder.php index 14f7b1c..78b3b62 100644 --- a/Application/Model/AbstractClasses/pdfdocumentsOrder.php +++ b/Application/Model/AbstractClasses/pdfdocumentsOrder.php @@ -68,18 +68,20 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt { // forced filename from setFilename() if ($this->filename) { - return $this->filename; + return $this->addFilenameExtension($this->filename); } $sTrimmedBillName = trim($this->getOrder()->getFieldData('oxbilllname')); - return implode( - '_', - [ - $this->getTypeForFilename(), - $this->getOrder()->getFieldData('oxordernr'), - $sTrimmedBillName . ".pdf" - ] + return $this->addFilenameExtension( + implode( + '_', + [ + $this->getTypeForFilename(), + $this->getOrder()->getFieldData('oxordernr'), + $sTrimmedBillName + ] + ) ); } diff --git a/Application/Model/Interfaces/pdfdocumentsGenericInterface.php b/Application/Model/Interfaces/pdfdocumentsGenericInterface.php index b8b1a97..a57fa81 100644 --- a/Application/Model/Interfaces/pdfdocumentsGenericInterface.php +++ b/Application/Model/Interfaces/pdfdocumentsGenericInterface.php @@ -65,4 +65,11 @@ interface pdfdocumentsGenericInterface * @return string */ public function getFilename(); + + /** + * @param string $filename + * + * @return string + */ + public function addFilenameExtension($filename); } \ No newline at end of file