Skip to content

Commit

Permalink
The licenses are now output via a template
Browse files Browse the repository at this point in the history
  • Loading branch information
doishub committed Dec 17, 2020
1 parent 3a66fa3 commit 31d0c05
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ With the module Ordered-Licenses the booked licenses can be displayed in the ord
> Produkt 1: ABCD-EFGH-IJKL-QRST-MNOP\
> Produkt 2: EFGH-ABCD-MNOP-QRST-IJKL\
> Produkt 3: IJKL-ABCD-EFGH-MNOP-QRST
When using an insert tag, the licenses are delivered via the "iso_licenses_default" template by default. If a third parameter is specified, an own template can be used. (For example `{{license_collection::*::iso_licenses_mail}}`).
21 changes: 17 additions & 4 deletions src/EventListener/InsertTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\Database;
use Contao\FrontendTemplate;
use Isotope\Model\ProductCollectionItem;

use Oveleon\IsotopeProductLicenses\LicenseModel;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function onReplaceInsertTags(string $tag)
$key = strtolower($elements[0]);

if (\in_array($key, self::SUPPORTED_TAGS, true)) {
return $this->replaceLicenseInsertTags($key, $elements[1]);
return $this->replaceLicenseInsertTags($key, $elements[1], $elements[2]);
}

return false;
Expand All @@ -68,10 +69,11 @@ public function onReplaceInsertTags(string $tag)
*
* @param string $insertTag
* @param string $intId
* @param null $strTemplate
*
* @return string
*/
private function replaceLicenseInsertTags($insertTag, $intId)
private function replaceLicenseInsertTags($insertTag, $intId, $strTemplate = null)
{
$arrProductIds = [];
$arrProductLicenses = [];
Expand Down Expand Up @@ -101,10 +103,21 @@ private function replaceLicenseInsertTags($insertTag, $intId)

if($newLicence = LicenseHandler::getNextLicense($objLicences, $memberId, $orderId))
{
$arrProductLicenses[] = sprintf("%s: %s", $objLicences->title, $newLicence);
if(!isset($arrProductLicenses[$productId]))
{
$arrProductLicenses[$productId] = array(
'label' => $objLicences->title,
'licenses' => []
);
}

$arrProductLicenses[$productId]['licenses'][] = $newLicence;
}
}

return implode("\n", $arrProductLicenses);
$objTemplate = new FrontendTemplate($strTemplate ?: 'iso_licenses_default');
$objTemplate->items = $arrProductLicenses;

return $objTemplate->parse();
}
}
2 changes: 1 addition & 1 deletion src/Resources/contao/classes/LicenseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LicenseHandler
*/
public static function getNextLicense($varProductLicence, $intMemberId = null, $intOrderId = null)
{
$logger = \System::getContainer()->get('monolog.logger.contao');
$logger = System::getContainer()->get('monolog.logger.contao');

if(is_int($varProductLicence))
{
Expand Down
12 changes: 12 additions & 0 deletions src/Resources/contao/templates/iso_licenses_default.html5
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<table width="100%" border="0" cellpadding="4">
<?php foreach($this->items as $item): ?>
<tr>
<td><strong><?= $item['label'] ?>:</strong></td>
</tr>
<?php foreach($item['licenses'] as $license): ?>
<tr>
<td><?= $license ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</table>

0 comments on commit 31d0c05

Please sign in to comment.