add filename extension if it's missing
This commit is contained in:
parent
d13dda978d
commit
0edb64153a
@ -36,6 +36,8 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
|
|||||||
const PDF_ORIENTATION_PORTRAIT = 'P';
|
const PDF_ORIENTATION_PORTRAIT = 'P';
|
||||||
const PDF_ORIENTATION_LANDSCAPE = 'L';
|
const PDF_ORIENTATION_LANDSCAPE = 'L';
|
||||||
|
|
||||||
|
public $filenameExtension = 'pdf';
|
||||||
|
|
||||||
/** @var Smarty */
|
/** @var Smarty */
|
||||||
public $oSmarty;
|
public $oSmarty;
|
||||||
|
|
||||||
@ -137,6 +139,37 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
|
|||||||
$this->filename = $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
|
* Gets proper file name
|
||||||
*
|
*
|
||||||
|
@ -68,18 +68,20 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
|
|||||||
{
|
{
|
||||||
// forced filename from setFilename()
|
// forced filename from setFilename()
|
||||||
if ($this->filename) {
|
if ($this->filename) {
|
||||||
return $this->filename;
|
return $this->addFilenameExtension($this->filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sTrimmedBillName = trim($this->getOrder()->getFieldData('oxbilllname'));
|
$sTrimmedBillName = trim($this->getOrder()->getFieldData('oxbilllname'));
|
||||||
|
|
||||||
return implode(
|
return $this->addFilenameExtension(
|
||||||
'_',
|
implode(
|
||||||
[
|
'_',
|
||||||
$this->getTypeForFilename(),
|
[
|
||||||
$this->getOrder()->getFieldData('oxordernr'),
|
$this->getTypeForFilename(),
|
||||||
$sTrimmedBillName . ".pdf"
|
$this->getOrder()->getFieldData('oxordernr'),
|
||||||
]
|
$sTrimmedBillName
|
||||||
|
]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,4 +65,11 @@ interface pdfdocumentsGenericInterface
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getFilename();
|
public function getFilename();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function addFilenameExtension($filename);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user