106 lines
2.8 KiB
PHP
106 lines
2.8 KiB
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\Application\Model\AbstractClasses;
|
|
|
|
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_generic as genericInterface;
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
use Smarty;
|
|
use Spipu\Html2Pdf\Html2Pdf;
|
|
|
|
abstract class pdfDocuments_generic implements genericInterface
|
|
{
|
|
/**
|
|
* @param $sFilename
|
|
* @param int $iSelLang
|
|
* @param string $target
|
|
*/
|
|
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
|
|
{
|
|
$sFilename = $this->getFilename( $sFilename);
|
|
|
|
$oPdf = call_user_func_array('oxNew', array_merge([Html2Pdf::class], $this->getPdfProperties()));
|
|
//$oPdf = oxNew(Html2Pdf::class, 'P', 'A4', 'de');
|
|
$oPdf->writeHTML($this->getHTMLContent($iSelLang));
|
|
$oPdf->output($sFilename, $target);
|
|
}
|
|
|
|
/**
|
|
* @param Smarty $smarty
|
|
*
|
|
* @return Smarty
|
|
*/
|
|
public function setSmartyVars($smarty)
|
|
{
|
|
$smarty->assign('oConfig', Registry::getSession()->getConfig());
|
|
$smarty->assign('oViewConf', Registry::getSession()->getConfig()->getActiveView()->getViewConfig());
|
|
$smarty->assign('shop', Registry::getSession()->getConfig()->getActiveShop());
|
|
$smarty->assign('lang', Registry::getLang());
|
|
|
|
return $smarty;
|
|
}
|
|
|
|
/**
|
|
* @param string $sFilename
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getFilename($sFilename)
|
|
{
|
|
return $sFilename;
|
|
}
|
|
|
|
/**
|
|
* @param int $iSelLang
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function getHTMLContent($iSelLang = 0)
|
|
{
|
|
$lang = Registry::getLang();
|
|
|
|
/** @var Smarty $oSmarty */
|
|
$oSmarty = Registry::getUtilsView()->getSmarty();
|
|
|
|
$currTplLang = $lang->getTplLanguage();
|
|
$lang->setTplLanguage($iSelLang);
|
|
|
|
$oSmarty = $this->setSmartyVars($oSmarty);
|
|
|
|
$content = $oSmarty->fetch($this->getTemplate());
|
|
|
|
$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'];
|
|
}
|
|
} |