From f7cfdccefd89cb4f725e86ecb9bdeb2729b7160c Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sat, 30 May 2020 00:52:41 +0200 Subject: [PATCH] use registry instead of fix lists --- .../Controller/orderOverviewPdfGenerator.php | 57 +++++++--------- .../views/tpl/admin/orderoverview_pdfform.tpl | 8 +-- IntelliSenseHelper.php | 7 ++ .../Model/d3_Order_PdfDocuments.php | 10 ++- .../d3_overview_controller_pdfdocuments.php | 66 ++++++++++++++----- 5 files changed, 92 insertions(+), 56 deletions(-) diff --git a/Application/Controller/orderOverviewPdfGenerator.php b/Application/Controller/orderOverviewPdfGenerator.php index f752f04..df0e1a2 100644 --- a/Application/Controller/orderOverviewPdfGenerator.php +++ b/Application/Controller/orderOverviewPdfGenerator.php @@ -17,20 +17,25 @@ namespace D3\PdfDocuments\Application\Controller; use D3\PdfDocuments\Application\Model\Documents\deliverynotePdf; use D3\PdfDocuments\Application\Model\Documents\invoicePdf; -use D3\PdfDocuments\Application\Model\Exceptions\d3noPdfHandlerFoundException; +use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException; +use D3\PdfDocuments\Application\Model\Exceptions\noPdfHandlerFoundException; +use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract; +use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_order_interface; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_order_interface as OrderPdfInterface; +use D3\PdfDocuments\Application\Model\Registries\registry_orderoverview; use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Core\Registry; -class orderPdfGenerator +class orderOverviewPdfGenerator { /** - * @param Order $order - * @param $sFilename - * @param int $iSelLang + * @param Order $order + * @param $sFilename + * @param int $iSelLang * @param string $target - * - * @throws d3noPdfHandlerFoundException + * @throws noPdfHandlerFoundException + * @throws noBaseObjectSetException + * @throws pdfGeneratorExceptionAbstract */ public function generatePdf(Order $order, $sFilename, $iSelLang = 0, $target = 'I') { @@ -44,38 +49,22 @@ class orderPdfGenerator * @param Order $order * * @return OrderPdfInterface - * @throws d3noPdfHandlerFoundException + * @throws noPdfHandlerFoundException */ public function getPdfClass(Order $order) { - switch (Registry::getRequest()->getRequestParameter('pdftype')) { - case ('dnote'): - case ('dnote_without_logo'): - $pdfInstance= oxNew(deliverynotePdf::class); - $pdfInstance->setOrder($order); - return $pdfInstance; - case ('standart'): - case('standart_without_logo'): - $pdfInvoice= oxNew(invoicePdf::class); - $pdfInvoice->setOrder($order); - return $pdfInvoice; - default: - return $this->getCustomPdfClass($order); + $requestedType = Registry::getRequest()->getRequestParameter('pdftype'); + + $generatorList = oxNew(registry_orderoverview::class); + /** @var pdfdocuments_order_interface $generator */ + foreach ($generatorList->getList() as $generator) { + if ($generator->getRequestId() == $requestedType) { + return $generator; + } } - } - /** - * @param Order $order - * - * @return OrderPdfInterface - * @throws d3noPdfHandlerFoundException - */ - public function getCustomPdfClass(Order $order) - { - unset($order); - - /** @var d3noPdfHandlerFoundException $e */ - $e = oxNew(d3noPdfHandlerFoundException::class, Registry::getRequest()->getRequestParameter('pdftype')); + /** @var noPdfHandlerFoundException $e */ + $e = oxNew(noPdfHandlerFoundException::class, Registry::getRequest()->getRequestParameter('pdftype')); throw($e); } } \ No newline at end of file diff --git a/Application/views/tpl/admin/orderoverview_pdfform.tpl b/Application/views/tpl/admin/orderoverview_pdfform.tpl index f5a8f67..93a2d5b 100644 --- a/Application/views/tpl/admin/orderoverview_pdfform.tpl +++ b/Application/views/tpl/admin/orderoverview_pdfform.tpl @@ -15,10 +15,10 @@ [{oxmultilang ident="ORDER_OVERVIEW_PDF_TYPE"}]:  diff --git a/IntelliSenseHelper.php b/IntelliSenseHelper.php index ea4c112..53b1730 100644 --- a/IntelliSenseHelper.php +++ b/IntelliSenseHelper.php @@ -18,4 +18,11 @@ namespace D3\PdfDocuments\Modules\Application\controllers { use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview; class d3_overview_controller_pdfdocuments_parent extends OrderOverview {} +} + +namespace D3\PdfDocuments\Modules\Application\Model +{ + use OxidEsales\Eshop\Application\Model\Order; + + class d3_Order_PdfDocuments_parent extends Order {} } \ No newline at end of file diff --git a/Modules/Application/Model/d3_Order_PdfDocuments.php b/Modules/Application/Model/d3_Order_PdfDocuments.php index f31b34b..bbb2ee2 100644 --- a/Modules/Application/Model/d3_Order_PdfDocuments.php +++ b/Modules/Application/Model/d3_Order_PdfDocuments.php @@ -17,7 +17,10 @@ namespace D3\PdfDocuments\Modules\Application\Model; -use D3\PdfDocuments\Application\Controller\orderPdfGenerator; +use D3\PdfDocuments\Application\Controller\orderOverviewPdfGenerator; +use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException; +use D3\PdfDocuments\Application\Model\Exceptions\noPdfHandlerFoundException; +use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract; class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent { @@ -25,10 +28,13 @@ class d3_Order_PdfDocuments extends d3_Order_PdfDocuments_parent * @param string $sFilename * @param int $iSelLang * @param string $target + * @throws noBaseObjectSetException + * @throws noPdfHandlerFoundException + * @throws pdfGeneratorExceptionAbstract */ public function genPdf($sFilename, $iSelLang = 0, $target = 'I') { - $generator = oxNew( orderPdfGenerator::class ); + $generator = oxNew( orderOverviewPdfGenerator::class ); $generator->generatePdf($this, $sFilename, $iSelLang, $target); } } diff --git a/Modules/Application/controllers/d3_overview_controller_pdfdocuments.php b/Modules/Application/controllers/d3_overview_controller_pdfdocuments.php index f54a45e..2daf4e2 100644 --- a/Modules/Application/controllers/d3_overview_controller_pdfdocuments.php +++ b/Modules/Application/controllers/d3_overview_controller_pdfdocuments.php @@ -1,10 +1,31 @@ + * @link http://www.oxidmodule.com + */ + namespace D3\PdfDocuments\Modules\Application\controllers; +use D3\PdfDocuments\Application\Model\Exceptions\noBaseObjectSetException; +use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract; +use D3\PdfDocuments\Application\Model\Registries\registry_orderoverview; +use D3\PdfDocuments\Modules\Application\Model\d3_Order_PdfDocuments; use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Core\DatabaseProvider; use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\TableViewNameGenerator; +use OxidEsales\Eshop\Core\UtilsView; class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocuments_parent { @@ -27,25 +48,38 @@ class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocu { $soxId = $this->getEditObjectId(); if ($soxId != "-1" && isset($soxId)) { - // load object + /** @var d3_Order_PdfDocuments $oOrder */ $oOrder = oxNew(Order::class); if ($oOrder->load($soxId)) { - self::$_blIsAdmin = 0; - $oUtils = Registry::getUtils(); - $sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue()); - $sFilename = $oOrder->oxorder__oxordernr->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); + try { + self::$_blIsAdmin = 0; + $oUtils = Registry::getUtils(); + $sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue()); + $sFilename = $oOrder->oxorder__oxordernr->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); + } } } } + + /** + * @return registry_orderoverview + */ + public function d3getGeneratorList() + { + return oxNew(registry_orderoverview::class); + } } \ No newline at end of file