-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a draft for Header and Footer ViewHelper support
- Loading branch information
Showing
8 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace Bithost\Pdfviewhelpers\Model; | ||
|
||
/*** | ||
* | ||
* This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS. | ||
* | ||
* (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH | ||
* Esteban Marin <esteban.marin@bithost.ch>, Bithost GmbH | ||
* | ||
* All rights reserved | ||
* | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
***/ | ||
|
||
use FPDI; | ||
use Closure; | ||
|
||
/** | ||
* BasePDF | ||
* | ||
* @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Marin <esteban.marin@bithost.ch> | ||
*/ | ||
class BasePDF extends FPDI | ||
{ | ||
/** | ||
* Indicating whether the current page is using a template. | ||
* This is needed to automatically add the template on an automatic page break. | ||
* | ||
* @var bool | ||
*/ | ||
protected $importTemplateOnThisPage = false; | ||
|
||
/** | ||
* @var Closure | ||
*/ | ||
protected $headerClosure = null; | ||
|
||
/** | ||
* @var Closure | ||
*/ | ||
protected $footerClosure = null; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function Header() // phpcs:ignore | ||
{ | ||
if ($this->headerClosure instanceof Closure) { | ||
$this->headerClosure->__invoke(); | ||
} | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function Footer() // phpcs:ignore | ||
{ | ||
if ($this->footerClosure instanceof Closure) { | ||
$this->footerClosure->__invoke(); | ||
} | ||
} | ||
|
||
/** | ||
* Fixes importPage not working with autoPageBreak=1, see https://github.com/bithost-gmbh/pdfviewhelpers/issues/41 | ||
* | ||
* @return void | ||
*/ | ||
public function AddPage($orientation = '', $format = '', $rotationOrKeepmargins = false, $tocpage = false) // phpcs:ignore | ||
{ | ||
parent::AddPage($orientation, $format, $rotationOrKeepmargins, $tocpage); | ||
|
||
if ($this->importTemplateOnThisPage && $this->tpl !== 0) { | ||
$this->useTemplate($this->tpl); | ||
} | ||
} | ||
|
||
/** | ||
* @param bool $importTemplateOnThisPage | ||
* | ||
* @return void | ||
*/ | ||
public function setImportTemplateOnThisPage($importTemplateOnThisPage) | ||
{ | ||
$this->importTemplateOnThisPage = $importTemplateOnThisPage; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function setHeaderClosure(Closure $closure) | ||
{ | ||
$this->headerClosure = $closure; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function setFooterClosure(Closure $closure) | ||
{ | ||
$this->footerClosure = $closure; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Bithost\Pdfviewhelpers\ViewHelpers; | ||
|
||
/* * * | ||
* | ||
* This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS. | ||
* | ||
* (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH | ||
* Esteban Marin <esteban.marin@bithost.ch>, Bithost GmbH | ||
* | ||
* All rights reserved | ||
* | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* * */ | ||
|
||
use Bithost\Pdfviewhelpers\Exception\Exception; | ||
use Bithost\Pdfviewhelpers\Model\BasePDF; | ||
|
||
/** | ||
* FooterViewHelper | ||
* | ||
* @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Marin <esteban.marin@bithost.ch> | ||
*/ | ||
class FooterViewHelper extends AbstractContentElementViewHelper | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
public function initializeArguments() | ||
{ | ||
parent::initializeArguments(); | ||
|
||
$this->overrideArgument('posY', 'integer', '', false, $this->settings['footer']['posY']); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* | ||
* @return void | ||
*/ | ||
public function render() | ||
{ | ||
if (!($this->getPDF() instanceof BasePDF)) { | ||
throw new Exception("Your PDF class must be an instance of Bithost\\Pdfviewhelpers\\Model\\BasePDF in order to support Header and Footer ViewHelper."); | ||
} | ||
|
||
$arguments = $this->arguments; | ||
$renderChildrenClosure = $this->buildRenderChildrenClosure(); | ||
$pdf = $this->getPDF(); | ||
$footerClosure = function() use ($pdf, $arguments, $renderChildrenClosure) { | ||
if ($arguments['posY']) { | ||
$pdf->SetY($arguments['posY']); | ||
} | ||
|
||
$renderChildrenClosure(); | ||
}; | ||
|
||
$this->getPDF()->setFooterClosure($footerClosure); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Bithost\Pdfviewhelpers\ViewHelpers; | ||
|
||
/* * * | ||
* | ||
* This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS. | ||
* | ||
* (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH | ||
* Esteban Marin <esteban.marin@bithost.ch>, Bithost GmbH | ||
* | ||
* All rights reserved | ||
* | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* * */ | ||
|
||
/** | ||
* GetPageNumberAliasViewHelper | ||
* | ||
* @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Marin <esteban.marin@bithost.ch> | ||
*/ | ||
class GetPageNumberAliasViewHelper extends AbstractPDFViewHelper | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function render() | ||
{ | ||
return $this->getPDF()->getAliasNumPage(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Classes/ViewHelpers/GetTotalNumberOfPagesAliasViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Bithost\Pdfviewhelpers\ViewHelpers; | ||
|
||
/* * * | ||
* | ||
* This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS. | ||
* | ||
* (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH | ||
* Esteban Marin <esteban.marin@bithost.ch>, Bithost GmbH | ||
* | ||
* All rights reserved | ||
* | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* * */ | ||
|
||
/** | ||
* GetTotalNumberOfPagesAliasViewHelper | ||
* | ||
* @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Marin <esteban.marin@bithost.ch> | ||
*/ | ||
class GetTotalNumberOfPagesAliasViewHelper extends AbstractPDFViewHelper | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function render() | ||
{ | ||
return $this->getPDF()->getAliasNbPages(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Bithost\Pdfviewhelpers\ViewHelpers; | ||
|
||
/* * * | ||
* | ||
* This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS. | ||
* | ||
* (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH | ||
* Esteban Marin <esteban.marin@bithost.ch>, Bithost GmbH | ||
* | ||
* All rights reserved | ||
* | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
* * */ | ||
|
||
use Bithost\Pdfviewhelpers\Exception\Exception; | ||
use Bithost\Pdfviewhelpers\Model\BasePDF; | ||
|
||
/** | ||
* HeaderViewHelper | ||
* | ||
* @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Marin <esteban.marin@bithost.ch> | ||
*/ | ||
class HeaderViewHelper extends AbstractContentElementViewHelper | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
public function initializeArguments() | ||
{ | ||
parent::initializeArguments(); | ||
|
||
$this->overrideArgument('posY', 'integer', '', false, $this->settings['header']['posY']); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* | ||
* @return void | ||
*/ | ||
public function render() | ||
{ | ||
if (!($this->getPDF() instanceof BasePDF)) { | ||
throw new Exception("Your PDF class must be an instance of Bithost\\Pdfviewhelpers\\Model\\BasePDF in order to support Header and Footer ViewHelper."); | ||
} | ||
|
||
$arguments = $this->arguments; | ||
$renderChildrenClosure = $this->buildRenderChildrenClosure(); | ||
$pdf = $this->getPDF(); | ||
$headerClosure = function() use ($pdf, $arguments, $renderChildrenClosure) { | ||
if ($arguments['posY']) { | ||
$pdf->SetY($arguments['posY']); | ||
} | ||
|
||
$renderChildrenClosure(); | ||
}; | ||
|
||
$this->getPDF()->setHeaderClosure($headerClosure); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{namespace pdf=Bithost\Pdfviewhelpers\ViewHelpers} | ||
|
||
<pdf:document outputDestination="I" title="Bithost Example"> | ||
<pdf:header> | ||
<pdf:text>Header - page {pdf:getPageNumberAlias()} of {pdf:getTotalNumberOfPagesAlias()}</pdf:text> | ||
</pdf:header> | ||
<pdf:footer> | ||
<pdf:text>Footer - page {pdf:getPageNumberAlias()} of {pdf:getTotalNumberOfPagesAlias()}</pdf:text> | ||
</pdf:footer> | ||
<pdf:page> | ||
<pdf:text>Content goes here: page 1</pdf:text> | ||
<pdf:pageBreak /> | ||
<pdf:text>Content goes here: page 2</pdf:text> | ||
</pdf:page> | ||
</pdf:document> |
Oops, something went wrong.