diff --git a/Application/Model/AbstractClasses/pdfdocumentsGeneric.php b/Application/Model/AbstractClasses/pdfdocumentsGeneric.php index b2b9292..9009880 100644 --- a/Application/Model/AbstractClasses/pdfdocumentsGeneric.php +++ b/Application/Model/AbstractClasses/pdfdocumentsGeneric.php @@ -36,9 +36,14 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface const PDF_ORIENTATION_PORTRAIT = 'P'; const PDF_ORIENTATION_LANDSCAPE = 'L'; + public $filenameExtension = 'pdf'; + /** @var Smarty */ public $oSmarty; + /** @var string */ + public $filename; + /** * pdfDocumentsGeneric constructor. */ @@ -126,6 +131,45 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface return [self::PDF_ORIENTATION_PORTRAIT, 'A4', 'de']; } + /** + * @param $filename + */ + public function setFilename($filename) + { + $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 b719dd8..78b3b62 100644 --- a/Application/Model/AbstractClasses/pdfdocumentsOrder.php +++ b/Application/Model/AbstractClasses/pdfdocumentsOrder.php @@ -66,15 +66,22 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt */ public function getFilename() { + // forced filename from setFilename() + if ($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 acc0751..a57fa81 100644 --- a/Application/Model/Interfaces/pdfdocumentsGenericInterface.php +++ b/Application/Model/Interfaces/pdfdocumentsGenericInterface.php @@ -56,8 +56,20 @@ interface pdfdocumentsGenericInterface */ public function genPdf($sFilename, $iSelLang = 0, $target = 'I'); + /** + * @param string $filename + */ + public function setFilename($filename); + /** * @return string */ public function getFilename(); + + /** + * @param string $filename + * + * @return string + */ + public function addFilenameExtension($filename); } \ No newline at end of file