move pdf download to pdf models, use different (changeable) filenames for every document
This commit is contained in:
parent
0f03cdfe84
commit
68171b86de
@ -34,12 +34,12 @@ class orderOverviewPdfGenerator
|
|||||||
* @throws noBaseObjectSetException
|
* @throws noBaseObjectSetException
|
||||||
* @throws pdfGeneratorExceptionAbstract
|
* @throws pdfGeneratorExceptionAbstract
|
||||||
*/
|
*/
|
||||||
public function generatePdf(Order $order, $sFilename, $iSelLang = 0, $target = 'I')
|
public function generatePdf(Order $order, $iSelLang = 0)
|
||||||
{
|
{
|
||||||
$Pdf= $this->getPdfClass();
|
$Pdf= $this->getPdfClass();
|
||||||
|
|
||||||
$Pdf->setOrder($order);
|
$Pdf->setOrder($order);
|
||||||
$Pdf->genPdf($sFilename, $iSelLang, $target);
|
$Pdf->downloadPdf($iSelLang);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,13 +18,18 @@
|
|||||||
namespace D3\PdfDocuments\Application\Model\AbstractClasses;
|
namespace D3\PdfDocuments\Application\Model\AbstractClasses;
|
||||||
|
|
||||||
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
|
use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException;
|
||||||
|
use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract;
|
||||||
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface as genericInterface;
|
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface as genericInterface;
|
||||||
|
use OxidEsales\Eshop\Core\Base;
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
|
use OxidEsales\Eshop\Core\UtilsView;
|
||||||
use Smarty;
|
use Smarty;
|
||||||
use Spipu\Html2Pdf\Html2Pdf;
|
use Spipu\Html2Pdf\Html2Pdf;
|
||||||
|
|
||||||
abstract class pdfdocumentsGeneric implements genericInterface
|
abstract class pdfdocumentsGeneric extends Base implements genericInterface
|
||||||
{
|
{
|
||||||
|
const PDF_DOWNLOAD = 'I';
|
||||||
|
|
||||||
/** @var Smarty */
|
/** @var Smarty */
|
||||||
public $oSmarty;
|
public $oSmarty;
|
||||||
|
|
||||||
@ -33,6 +38,8 @@ abstract class pdfdocumentsGeneric implements genericInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
/** @var Smarty $oSmarty */
|
/** @var Smarty $oSmarty */
|
||||||
$this->oSmarty = Registry::getUtilsView()->getSmarty();
|
$this->oSmarty = Registry::getUtilsView()->getSmarty();
|
||||||
}
|
}
|
||||||
@ -45,12 +52,33 @@ abstract class pdfdocumentsGeneric implements genericInterface
|
|||||||
*/
|
*/
|
||||||
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
||||||
{
|
{
|
||||||
$sFilename = $this->getFilename( $sFilename);
|
$sFilename = $this->getFilename();
|
||||||
$oPdf = oxNew(Html2Pdf::class, ...$this->getPdfProperties());
|
$oPdf = oxNew(Html2Pdf::class, ...$this->getPdfProperties());
|
||||||
$oPdf->writeHTML($this->getHTMLContent($iSelLang));
|
$oPdf->writeHTML($this->getHTMLContent($iSelLang));
|
||||||
$oPdf->output($sFilename, $target);
|
$oPdf->output($sFilename, $target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function downloadPdf($iLanguage = 0)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$oUtils = Registry::getUtils();
|
||||||
|
$sFilename = $this->makeValidFileName($this->getFilename());
|
||||||
|
ob_start();
|
||||||
|
$this->genPdf($sFilename, $iLanguage, self::PDF_DOWNLOAD);
|
||||||
|
$sPDF = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
$oUtils->setHeader("Pragma: public");
|
||||||
|
$oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
||||||
|
$oUtils->setHeader("Expires: 0");
|
||||||
|
$oUtils->setHeader("Content-type: application/pdf");
|
||||||
|
$oUtils->setHeader("Content-Disposition: attachment; filename=" . $sFilename);
|
||||||
|
Registry::getUtils()->showMessageAndExit($sPDF);
|
||||||
|
} catch (pdfGeneratorExceptionAbstract $e) {
|
||||||
|
Registry::get(UtilsView::class)->addErrorToDisplay($e);
|
||||||
|
Registry::getLogger()->error($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function setSmartyVars()
|
public function setSmartyVars()
|
||||||
{
|
{
|
||||||
$this->oSmarty->assign('oConfig', Registry::getSession()->getConfig());
|
$this->oSmarty->assign('oConfig', Registry::getSession()->getConfig());
|
||||||
@ -59,16 +87,6 @@ abstract class pdfdocumentsGeneric implements genericInterface
|
|||||||
$this->oSmarty->assign('lang', Registry::getLang());
|
$this->oSmarty->assign('lang', Registry::getLang());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sFilename
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFilename($sFilename)
|
|
||||||
{
|
|
||||||
return $sFilename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $iSelLang
|
* @param int $iSelLang
|
||||||
*
|
*
|
||||||
@ -76,6 +94,8 @@ abstract class pdfdocumentsGeneric implements genericInterface
|
|||||||
*/
|
*/
|
||||||
public function getHTMLContent($iSelLang = 0)
|
public function getHTMLContent($iSelLang = 0)
|
||||||
{
|
{
|
||||||
|
self::$_blIsAdmin = $this->renderTemplateFromAdmin();
|
||||||
|
|
||||||
$lang = Registry::getLang();
|
$lang = Registry::getLang();
|
||||||
|
|
||||||
$currTplLang = $lang->getTplLanguage();
|
$currTplLang = $lang->getTplLanguage();
|
||||||
@ -105,4 +125,27 @@ abstract class pdfdocumentsGeneric implements genericInterface
|
|||||||
{
|
{
|
||||||
return ['P', 'A4', 'de'];
|
return ['P', 'A4', 'de'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets proper file name
|
||||||
|
*
|
||||||
|
* @param string $sFilename file name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function makeValidFileName($sFilename)
|
||||||
|
{
|
||||||
|
$sFilename = preg_replace('/[\s]+/', '_', $sFilename);
|
||||||
|
$sFilename = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $sFilename);
|
||||||
|
|
||||||
|
return str_replace(' ', '_', $sFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function renderTemplateFromAdmin()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -64,14 +64,18 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getFilename($sFilename)
|
public function getFilename()
|
||||||
{
|
{
|
||||||
$sFilename = parent::getFilename( $sFilename);
|
$sTrimmedBillName = trim($this->getOrder()->getFieldData('oxbilllname'));
|
||||||
|
|
||||||
$ordernr = $this->getOrder()->getFieldData('oxordernr');
|
return implode(
|
||||||
$billnr = $this->getOrder()->getFieldData('oxbillnr');;
|
'_',
|
||||||
|
[
|
||||||
return str_replace($ordernr, $billnr, $sFilename);
|
$this->getTypeForFilename(),
|
||||||
|
$this->getOrder()->getFieldData('oxordernr'),
|
||||||
|
$sTrimmedBillName . ".pdf"
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,6 +37,14 @@ class deliverynotePdf extends pdfdocumentsOrder
|
|||||||
return "ORDER_OVERVIEW_PDF_DNOTE";
|
return "ORDER_OVERVIEW_PDF_DNOTE";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTypeForFilename()
|
||||||
|
{
|
||||||
|
return 'delnote';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +42,14 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
|
|||||||
return "ORDER_OVERVIEW_PDF_STANDART";
|
return "ORDER_OVERVIEW_PDF_STANDART";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTypeForFilename()
|
||||||
|
{
|
||||||
|
return 'invoice';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $sFilename
|
* @param $sFilename
|
||||||
* @param int $iSelLang
|
* @param int $iSelLang
|
||||||
@ -88,4 +96,20 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
|
|||||||
public function getTemplate(){
|
public function getTemplate(){
|
||||||
return 'd3invoice_pdf.tpl';
|
return 'd3invoice_pdf.tpl';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sFilename
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getFilename()
|
||||||
|
{
|
||||||
|
$filename = parent::getFilename();
|
||||||
|
|
||||||
|
return str_replace(
|
||||||
|
$this->getOrder()->getFieldData('oxordernr'),
|
||||||
|
$this->getOrder()->getFieldData('oxbillnr'),
|
||||||
|
$filename
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -41,6 +41,11 @@ interface pdfdocumentsGenericInterface
|
|||||||
*/
|
*/
|
||||||
public function getHTMLContent();
|
public function getHTMLContent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $iLanguage
|
||||||
|
*/
|
||||||
|
public function downloadPdf($iLanguage = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $sFilename
|
* @param $sFilename
|
||||||
* @param int $iSelLang
|
* @param int $iSelLang
|
||||||
@ -50,4 +55,9 @@ interface pdfdocumentsGenericInterface
|
|||||||
* @throws noBaseObjectSetException
|
* @throws noBaseObjectSetException
|
||||||
*/
|
*/
|
||||||
public function genPdf($sFilename, $iSelLang = 0, $target = 'I');
|
public function genPdf($sFilename, $iSelLang = 0, $target = 'I');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getFilename();
|
||||||
}
|
}
|
@ -30,4 +30,9 @@ interface pdfdocumentsOrderInterface extends pdfdocumentsGenericInterface
|
|||||||
* @return Order
|
* @return Order
|
||||||
*/
|
*/
|
||||||
public function getOrder();
|
public function getOrder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTypeForFilename();
|
||||||
}
|
}
|
@ -13,7 +13,7 @@
|
|||||||
* @link http://www.oxidmodule.com
|
* @link http://www.oxidmodule.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace D3\PdfDocuments\Modules\Application\controllers {
|
namespace D3\PdfDocuments\Modules\Application\Controller {
|
||||||
|
|
||||||
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview;
|
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview;
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
* @link http://www.oxidmodule.com
|
* @link http://www.oxidmodule.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace D3\PdfDocuments\Modules\Application\controllers;
|
namespace D3\PdfDocuments\Modules\Application\Controller;
|
||||||
|
|
||||||
|
use D3\PdfDocuments\Application\Controller\orderOverviewPdfGenerator;
|
||||||
use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract;
|
use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract;
|
||||||
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverview;
|
use D3\PdfDocuments\Application\Model\Registries\registryOrderoverview;
|
||||||
use D3\PdfDocuments\Modules\Application\Model\d3_Order_PdfDocuments;
|
use D3\PdfDocuments\Modules\Application\Model\d3_Order_PdfDocuments;
|
||||||
@ -50,27 +51,9 @@ class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocu
|
|||||||
/** @var d3_Order_PdfDocuments $oOrder */
|
/** @var d3_Order_PdfDocuments $oOrder */
|
||||||
$oOrder = oxNew(Order::class);
|
$oOrder = oxNew(Order::class);
|
||||||
if ($oOrder->load($soxId)) {
|
if ($oOrder->load($soxId)) {
|
||||||
try {
|
|
||||||
self::$_blIsAdmin = 0;
|
self::$_blIsAdmin = 0;
|
||||||
$oUtils = Registry::getUtils();
|
$generator = oxNew( orderOverviewPdfGenerator::class );
|
||||||
$sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue());
|
$generator->generatePdf($oOrder, Registry::getRequest()->getRequestEscapedParameter("pdflanguage"));
|
||||||
//oxbillr nicht so eingeschrieben lassen
|
|
||||||
$sFilename = $oOrder->oxorder__oxbillnr->value . "_" . $sTrimmedBillName . ".pdf";
|
|
||||||
$sFilename = $this->makeValidFileName($sFilename);
|
|
||||||
ob_start();
|
|
||||||
$oOrder->genPdf($sFilename, Registry::getConfig()->getRequestParameter("pdflanguage"));
|
|
||||||
$sPDF = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
$oUtils->setHeader("Pragma: public");
|
|
||||||
$oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
|
||||||
$oUtils->setHeader("Expires: 0");
|
|
||||||
$oUtils->setHeader("Content-type: application/pdf");
|
|
||||||
$oUtils->setHeader("Content-Disposition: attachment; filename=" . $sFilename);
|
|
||||||
Registry::getUtils()->showMessageAndExit($sPDF);
|
|
||||||
} catch (pdfGeneratorExceptionAbstract $e) {
|
|
||||||
Registry::get(UtilsView::class)->addErrorToDisplay($e);
|
|
||||||
Registry::getLogger()->error($e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract;
|
|||||||
class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent
|
class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* compatibility to OXID Invoice PDF module
|
||||||
* @param string $sFilename
|
* @param string $sFilename
|
||||||
* @param int $iSelLang
|
* @param int $iSelLang
|
||||||
* @param string $target
|
* @param string $target
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use D3\ModCfg\Application\Model\d3utils;
|
use D3\ModCfg\Application\Model\d3utils;
|
||||||
use D3\PdfDocuments\Modules\Application\controllers\d3_overview_controller_pdfdocuments;
|
use D3\PdfDocuments\Modules\Application\Controller\d3_overview_controller_pdfdocuments;
|
||||||
use D3\PdfDocuments\Modules\Application\Model\d3_Order_PdfDocuments as d3_pdfdocs_OrderModel;
|
use D3\PdfDocuments\Modules\Application\Model\d3_Order_PdfDocuments as d3_pdfdocs_OrderModel;
|
||||||
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview;
|
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview;
|
||||||
use OxidEsales\Eshop\Application\Model as OxidModel;
|
use OxidEsales\Eshop\Application\Model as OxidModel;
|
||||||
|
Loading…
Reference in New Issue
Block a user