8
0

add filename extension if it's missing

Dieser Commit ist enthalten in:
Daniel Seifert 2020-06-05 10:06:58 +02:00
Ursprung d13dda978d
Commit 0edb64153a
Signiert von: DanielS
GPG-Schlüssel-ID: 8A7C4C6ED1915C6F
3 geänderte Dateien mit 50 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -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
*

Datei anzeigen

@ -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
]
)
);
}

Datei anzeigen

@ -65,4 +65,11 @@ interface pdfdocumentsGenericInterface
* @return string
*/
public function getFilename();
/**
* @param string $filename
*
* @return string
*/
public function addFilenameExtension($filename);
}