use registry instead of fix lists
This commit is contained in:
parent
3da3d1e3ab
commit
f7cfdccefd
@ -17,20 +17,25 @@ namespace D3\PdfDocuments\Application\Controller;
|
|||||||
|
|
||||||
use D3\PdfDocuments\Application\Model\Documents\deliverynotePdf;
|
use D3\PdfDocuments\Application\Model\Documents\deliverynotePdf;
|
||||||
use D3\PdfDocuments\Application\Model\Documents\invoicePdf;
|
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\Interfaces\pdfdocuments_order_interface as OrderPdfInterface;
|
||||||
|
use D3\PdfDocuments\Application\Model\Registries\registry_orderoverview;
|
||||||
use OxidEsales\Eshop\Application\Model\Order;
|
use OxidEsales\Eshop\Application\Model\Order;
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
|
|
||||||
class orderPdfGenerator
|
class orderOverviewPdfGenerator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param Order $order
|
* @param Order $order
|
||||||
* @param $sFilename
|
* @param $sFilename
|
||||||
* @param int $iSelLang
|
* @param int $iSelLang
|
||||||
* @param string $target
|
* @param string $target
|
||||||
*
|
* @throws noPdfHandlerFoundException
|
||||||
* @throws d3noPdfHandlerFoundException
|
* @throws noBaseObjectSetException
|
||||||
|
* @throws pdfGeneratorExceptionAbstract
|
||||||
*/
|
*/
|
||||||
public function generatePdf(Order $order, $sFilename, $iSelLang = 0, $target = 'I')
|
public function generatePdf(Order $order, $sFilename, $iSelLang = 0, $target = 'I')
|
||||||
{
|
{
|
||||||
@ -44,38 +49,22 @@ class orderPdfGenerator
|
|||||||
* @param Order $order
|
* @param Order $order
|
||||||
*
|
*
|
||||||
* @return OrderPdfInterface
|
* @return OrderPdfInterface
|
||||||
* @throws d3noPdfHandlerFoundException
|
* @throws noPdfHandlerFoundException
|
||||||
*/
|
*/
|
||||||
public function getPdfClass(Order $order)
|
public function getPdfClass(Order $order)
|
||||||
{
|
{
|
||||||
switch (Registry::getRequest()->getRequestParameter('pdftype')) {
|
$requestedType = Registry::getRequest()->getRequestParameter('pdftype');
|
||||||
case ('dnote'):
|
|
||||||
case ('dnote_without_logo'):
|
$generatorList = oxNew(registry_orderoverview::class);
|
||||||
$pdfInstance= oxNew(deliverynotePdf::class);
|
/** @var pdfdocuments_order_interface $generator */
|
||||||
$pdfInstance->setOrder($order);
|
foreach ($generatorList->getList() as $generator) {
|
||||||
return $pdfInstance;
|
if ($generator->getRequestId() == $requestedType) {
|
||||||
case ('standart'):
|
return $generator;
|
||||||
case('standart_without_logo'):
|
}
|
||||||
$pdfInvoice= oxNew(invoicePdf::class);
|
|
||||||
$pdfInvoice->setOrder($order);
|
|
||||||
return $pdfInvoice;
|
|
||||||
default:
|
|
||||||
return $this->getCustomPdfClass($order);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/** @var noPdfHandlerFoundException $e */
|
||||||
* @param Order $order
|
$e = oxNew(noPdfHandlerFoundException::class, Registry::getRequest()->getRequestParameter('pdftype'));
|
||||||
*
|
|
||||||
* @return OrderPdfInterface
|
|
||||||
* @throws d3noPdfHandlerFoundException
|
|
||||||
*/
|
|
||||||
public function getCustomPdfClass(Order $order)
|
|
||||||
{
|
|
||||||
unset($order);
|
|
||||||
|
|
||||||
/** @var d3noPdfHandlerFoundException $e */
|
|
||||||
$e = oxNew(d3noPdfHandlerFoundException::class, Registry::getRequest()->getRequestParameter('pdftype'));
|
|
||||||
throw($e);
|
throw($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,10 +15,10 @@
|
|||||||
[{oxmultilang ident="ORDER_OVERVIEW_PDF_TYPE"}]:
|
[{oxmultilang ident="ORDER_OVERVIEW_PDF_TYPE"}]:
|
||||||
<select name="pdftype" class="editinput" style="width:80px;">
|
<select name="pdftype" class="editinput" style="width:80px;">
|
||||||
[{block name="d3_pdfdocuments_order_overview_pdfTypeOptions"}]
|
[{block name="d3_pdfdocuments_order_overview_pdfTypeOptions"}]
|
||||||
<option value="standart" SELECTED>[{oxmultilang ident="ORDER_OVERVIEW_PDF_STANDART"}]</option>
|
[{assign var="generatorList" value=$oView->d3getGeneratorList()}]
|
||||||
<option value="dnote">[{oxmultilang ident="ORDER_OVERVIEW_PDF_DNOTE"}]</option>
|
[{foreach from=$generatorList->getList() item="generator"}]
|
||||||
<option value="standart_without_logo">[{oxmultilang ident="ORDER_OVERVIEW_PDF_STANDART_WITHOUT_LOGO" }]</option>
|
<option value="[{$generator->getRequestId()}]">[{oxmultilang ident=$generator->getTitleIdent()}]</option>
|
||||||
<option value="dnote_without_logo">[{oxmultilang ident="ORDER_OVERVIEW_PDF_DNOTE_WITHOUT_LOGO" }]</option>
|
[{/foreach}]
|
||||||
[{/block}]
|
[{/block}]
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
|
@ -18,4 +18,11 @@ namespace D3\PdfDocuments\Modules\Application\controllers {
|
|||||||
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview;
|
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview;
|
||||||
|
|
||||||
class d3_overview_controller_pdfdocuments_parent extends 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 {}
|
||||||
}
|
}
|
@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
namespace D3\PdfDocuments\Modules\Application\Model;
|
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
|
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 string $sFilename
|
||||||
* @param int $iSelLang
|
* @param int $iSelLang
|
||||||
* @param string $target
|
* @param string $target
|
||||||
|
* @throws noBaseObjectSetException
|
||||||
|
* @throws noPdfHandlerFoundException
|
||||||
|
* @throws pdfGeneratorExceptionAbstract
|
||||||
*/
|
*/
|
||||||
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
||||||
{
|
{
|
||||||
$generator = oxNew( orderPdfGenerator::class );
|
$generator = oxNew( orderOverviewPdfGenerator::class );
|
||||||
$generator->generatePdf($this, $sFilename, $iSelLang, $target);
|
$generator->generatePdf($this, $sFilename, $iSelLang, $target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,31 @@
|
|||||||
<?php
|
<?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;
|
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\Application\Model\Order;
|
||||||
use OxidEsales\Eshop\Core\DatabaseProvider;
|
use OxidEsales\Eshop\Core\DatabaseProvider;
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
use OxidEsales\Eshop\Core\TableViewNameGenerator;
|
use OxidEsales\Eshop\Core\TableViewNameGenerator;
|
||||||
|
use OxidEsales\Eshop\Core\UtilsView;
|
||||||
|
|
||||||
class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocuments_parent
|
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();
|
$soxId = $this->getEditObjectId();
|
||||||
if ($soxId != "-1" && isset($soxId)) {
|
if ($soxId != "-1" && isset($soxId)) {
|
||||||
// load object
|
/** @var d3_Order_PdfDocuments $oOrder */
|
||||||
$oOrder = oxNew(Order::class);
|
$oOrder = oxNew(Order::class);
|
||||||
if ($oOrder->load($soxId)) {
|
if ($oOrder->load($soxId)) {
|
||||||
self::$_blIsAdmin = 0;
|
try {
|
||||||
$oUtils = Registry::getUtils();
|
self::$_blIsAdmin = 0;
|
||||||
$sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue());
|
$oUtils = Registry::getUtils();
|
||||||
$sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".pdf";
|
$sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue());
|
||||||
$sFilename = $this->makeValidFileName($sFilename);
|
$sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".pdf";
|
||||||
ob_start();
|
$sFilename = $this->makeValidFileName($sFilename);
|
||||||
$oOrder->genPDF($sFilename, Registry::getConfig()->getRequestParameter("pdflanguage"));
|
ob_start();
|
||||||
$sPDF = ob_get_contents();
|
$oOrder->genPdf($sFilename, Registry::getConfig()->getRequestParameter("pdflanguage"));
|
||||||
ob_end_clean();
|
$sPDF = ob_get_contents();
|
||||||
$oUtils->setHeader("Pragma: public");
|
ob_end_clean();
|
||||||
$oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
$oUtils->setHeader("Pragma: public");
|
||||||
$oUtils->setHeader("Expires: 0");
|
$oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
||||||
$oUtils->setHeader("Content-type: application/pdf");
|
$oUtils->setHeader("Expires: 0");
|
||||||
$oUtils->setHeader("Content-Disposition: attachment; filename=" . $sFilename);
|
$oUtils->setHeader("Content-type: application/pdf");
|
||||||
Registry::getUtils()->showMessageAndExit($sPDF);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user