2020-05-26 16:32:22 +02:00
|
|
|
<?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\Application\Model\AbstractClasses;
|
|
|
|
|
2020-05-28 12:21:11 +02:00
|
|
|
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_generic_interface as genericInterface;
|
2020-05-26 16:32:22 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2020-05-27 09:46:44 +02:00
|
|
|
use Smarty;
|
2020-05-26 16:32:22 +02:00
|
|
|
use Spipu\Html2Pdf\Html2Pdf;
|
|
|
|
|
|
|
|
abstract class pdfDocuments_generic implements genericInterface
|
|
|
|
{
|
2020-05-28 12:21:11 +02:00
|
|
|
/** @var Smarty */
|
|
|
|
public $oSmarty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pdfDocuments_generic constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
/** @var Smarty $oSmarty */
|
|
|
|
$this->oSmarty = Registry::getUtilsView()->getSmarty();
|
|
|
|
}
|
|
|
|
|
2020-05-27 09:46:44 +02:00
|
|
|
/**
|
|
|
|
* @param $sFilename
|
|
|
|
* @param int $iSelLang
|
|
|
|
* @param string $target
|
|
|
|
*/
|
|
|
|
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
|
|
|
{
|
|
|
|
$sFilename = $this->getFilename( $sFilename);
|
2020-05-28 12:21:11 +02:00
|
|
|
$oPdf = oxNew(Html2Pdf::class, ...$this->getPdfProperties());
|
2020-05-27 09:46:44 +02:00
|
|
|
$oPdf->writeHTML($this->getHTMLContent($iSelLang));
|
|
|
|
$oPdf->output($sFilename, $target);
|
|
|
|
}
|
|
|
|
|
2020-05-28 12:21:11 +02:00
|
|
|
public function setSmartyVars()
|
2020-05-27 09:46:44 +02:00
|
|
|
{
|
2020-05-28 12:21:11 +02:00
|
|
|
$this->oSmarty->assign('oConfig', Registry::getSession()->getConfig());
|
|
|
|
$this->oSmarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig());
|
|
|
|
$this->oSmarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop());
|
|
|
|
$this->oSmarty->assign('lang', Registry::getLang());
|
2020-05-27 09:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $sFilename
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFilename($sFilename)
|
|
|
|
{
|
|
|
|
return $sFilename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $iSelLang
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getHTMLContent($iSelLang = 0)
|
|
|
|
{
|
|
|
|
$lang = Registry::getLang();
|
|
|
|
|
|
|
|
$currTplLang = $lang->getTplLanguage();
|
|
|
|
$lang->setTplLanguage($iSelLang);
|
|
|
|
|
2020-05-28 12:21:11 +02:00
|
|
|
$this->setSmartyVars();
|
2020-05-27 09:46:44 +02:00
|
|
|
|
2020-05-28 12:21:11 +02:00
|
|
|
$content = $this->oSmarty->fetch($this->getTemplate());
|
2020-05-27 09:46:44 +02:00
|
|
|
|
|
|
|
$lang->setTplLanguage($currTplLang);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* arguments for Html2Pdf class constructor
|
|
|
|
* - $orientation = 'P',
|
|
|
|
* - $format = 'A4',
|
|
|
|
* - $lang = 'fr',
|
|
|
|
* - $unicode = true,
|
|
|
|
* - $encoding = 'UTF-8',
|
|
|
|
* - $margins = array(5, 5, 5, 8),
|
|
|
|
* - $pdfa = false
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getPdfProperties()
|
|
|
|
{
|
|
|
|
return ['P', 'A4', 'de'];
|
|
|
|
}
|
2020-05-26 16:32:22 +02:00
|
|
|
}
|