use registry instead of fix lists

This commit is contained in:
Daniel Seifert 2020-05-30 00:52:41 +02:00
parent 3da3d1e3ab
commit f7cfdccefd
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
5 changed files with 92 additions and 56 deletions

View File

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

View File

@ -15,10 +15,10 @@
[{oxmultilang ident="ORDER_OVERVIEW_PDF_TYPE"}]: 
<select name="pdftype" class="editinput" style="width:80px;">
[{block name="d3_pdfdocuments_order_overview_pdfTypeOptions"}]
<option value="standart" SELECTED>[{oxmultilang ident="ORDER_OVERVIEW_PDF_STANDART"}]</option>
<option value="dnote">[{oxmultilang ident="ORDER_OVERVIEW_PDF_DNOTE"}]</option>
<option value="standart_without_logo">[{oxmultilang ident="ORDER_OVERVIEW_PDF_STANDART_WITHOUT_LOGO" }]</option>
<option value="dnote_without_logo">[{oxmultilang ident="ORDER_OVERVIEW_PDF_DNOTE_WITHOUT_LOGO" }]</option>
[{assign var="generatorList" value=$oView->d3getGeneratorList()}]
[{foreach from=$generatorList->getList() item="generator"}]
<option value="[{$generator->getRequestId()}]">[{oxmultilang ident=$generator->getTitleIdent()}]</option>
[{/foreach}]
[{/block}]
</select>
</td>

View File

@ -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 {}
}

View File

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

View File

@ -1,10 +1,31 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
*
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Max Buhe <support@shopmodule.com>
* @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);
}
}