Skip to content

Commit

Permalink
- Creation of warning and error messages
Browse files Browse the repository at this point in the history
- Fix CSV import
  • Loading branch information
doishub committed Apr 24, 2020
1 parent 5ebe43f commit 40d48bd
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 36 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,3 @@ The following insert tags are available:
> Produkt 1: ABCD-EFGH-IJKL-QRST-MNOP\
> Produkt 2: EFGH-ABCD-MNOP-QRST-IJKL\
> Produkt 3: IJKL-ABCD-EFGH-MNOP-QRST
### Todo´s
- Error handling, should no more licenses be available
- (Define licenses directly in the product itself)

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

/*
* This file is part of Oveleon company bundle.
* This file is part of Oveleon Isotope Product License.
*
* (c) https://www.oveleon.de/
*/
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/InsertTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

/*
* This file is part of Oveleon company bundle.
* This file is part of Oveleon Isotope Product License.
*
* (c) https://www.oveleon.de/
*/
Expand Down
27 changes: 20 additions & 7 deletions src/Resources/contao/classes/LicenseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace Oveleon\IsotopeProductLicenses;

use Contao\CoreBundle\Monolog\ContaoContext;
use Psr\Log\LogLevel;

class LicenseHandler
{
/**
Expand All @@ -24,27 +27,37 @@ public static function getNextLicense($product)
$product = LicenseModel::findOneByProduct($product);
}

$logger = \System::getContainer()->get('monolog.logger.contao');

if($product !== null)
{
$arrValidLicenses = array_filter(\StringUtil::deserialize($product->validLicenses));
$arrUsedLicenses = array_filter(\StringUtil::deserialize($product->usedLicenses));
$arrValidLicenses = array_filter(\StringUtil::deserialize($product->listitems, true));
$arrUsedLicenses = array_filter(\StringUtil::deserialize($product->useditems, true));

if(empty($arrValidLicenses))
// ToDo: The number from when the warning is to be output should come from a configuration.
// ToDo: Send a warning e-mail to the administrator
if(count($arrValidLicenses) < 10 && !empty($arrValidLicenses))
{
$logger->log(LogLevel::WARNING, sprintf($GLOBALS['TL_LANG']['ERR']['lowNumberOfLicenses'], $product->product), array('contao' => new ContaoContext('getNextLicense', 'WARNING')));
}
elseif(empty($arrValidLicenses))
{
return 'NO MORE LICENSES';
$logger->log(LogLevel::ERROR, sprintf($GLOBALS['TL_LANG']['ERR']['noMoreLicenses'], $product->product), array('contao' => new ContaoContext('getNextLicense', 'ERROR')));
return '';
}

$strNewLicense = array_shift($arrValidLicenses);
$arrUsedLicenses[] = $strNewLicense;

$product->validLicenses = serialize($arrValidLicenses);
$product->usedLicenses = serialize($arrUsedLicenses);
$product->listitems = serialize($arrValidLicenses);
$product->useditems = serialize($arrUsedLicenses);

$product->save();

return $strNewLicense;
}

return 'LICENSE NOT FOUND';
$logger->log(LogLevel::ERROR, $GLOBALS['TL_LANG']['ERR']['noLicenseFound'], array('contao' => new ContaoContext('getNextLicense', 'ERROR')));
return '';
}
}
17 changes: 5 additions & 12 deletions src/Resources/contao/dca/tl_license.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php

/*
* This file is part of Contao.
* This file is part of Oveleon Isotope Product License.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
* (c) https://www.oveleon.de/
*/

$GLOBALS['TL_DCA']['tl_license'] = array
(
// Config
Expand Down Expand Up @@ -77,7 +74,7 @@
// Palettes
'palettes' => array
(
'default' => '{title_legend},title,product;{license_legend},validLicenses,usedLicenses',
'default' => '{title_legend},title,product;{license_legend},listitems,useditems',
),

// Fields
Expand Down Expand Up @@ -106,7 +103,7 @@
'eval' => array('mandatory'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'validLicenses' => array
'listitems' => array
(
'inputType' => 'listWizard',
'eval' => array('mandatory'=>true, 'tl_class'=>'w50 clr'),
Expand All @@ -116,14 +113,10 @@
),
'sql' => "blob NULL"
),
'usedLicenses' => array
'useditems' => array
(
'inputType' => 'listWizard',
'eval' => array('tl_class'=>'w50 clr'),
'xlabel' => array
(
array('tl_license', 'listImportWizard')
),
'sql' => "blob NULL"
),
)
Expand Down
18 changes: 18 additions & 0 deletions src/Resources/contao/languages/de/default.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/default.php" source-language="en" target-language="de">
<body>
<trans-unit id="ERR.noMoreLicenses">
<source>Licences for the product "%s" is exhausted</source>
<target>Lizenzen für das Produkt "%s" sind ausgeschöpft</target>
</trans-unit>
<trans-unit id="ERR.noLicenseFound">
<source>No license could be found for the referenced product</source>
<target>Für das referenzierte Produkt konnte keine Lizenz gefunden werden</target>
</trans-unit>
<trans-unit id="ERR.lowNumberOfLicenses">
<source>Only a few licenses left for product "%s"</source>
<target>Nur noch wenige Lizenzen für Produkt "%s"</target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 2 additions & 2 deletions src/Resources/contao/languages/de/tl_license.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<source>Here you can enter the ID of a product for which the licenses should be available.</source>
<target>Hier kannst du die ID eines Produktes eintragen, für das die Lizenzen gelten sollen.</target>
</trans-unit>
<trans-unit id="tl_license.validLicenses.0">
<trans-unit id="tl_license.listitems.0">
<source>Valid licenses</source>
<target>Gültige Lizenzen</target>
</trans-unit>
<trans-unit id="tl_license.usedLicenses.0">
<trans-unit id="tl_license.useditems.0">
<source>Licenses in use.</source>
<target>Bereits verwendete Lizenzen.</target>
</trans-unit>
Expand Down
15 changes: 15 additions & 0 deletions src/Resources/contao/languages/en/default.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/default.php" source-language="en">
<body>
<trans-unit id="ERR.noMoreLicenses">
<source>Licences for the product "%s" is exhausted</source>
</trans-unit>
<trans-unit id="ERR.noLicenseFound">
<source>No license could be found for the referenced product</source>
</trans-unit>
<trans-unit id="ERR.lowNumberOfLicenses">
<source>Only a few licenses left for product "%s"</source>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 2 additions & 2 deletions src/Resources/contao/languages/en/tl_license.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<trans-unit id="tl_license.product.1">
<source>Here you can enter the ID of a product for which the licenses should be available.</source>
</trans-unit>
<trans-unit id="tl_license.validLicenses.0">
<trans-unit id="tl_license.listitems.0">
<source>Valid licenses</source>
</trans-unit>
<trans-unit id="tl_license.usedLicenses.0">
<trans-unit id="tl_license.useditems.0">
<source>Licenses in use.</source>
</trans-unit>
</body>
Expand Down
10 changes: 4 additions & 6 deletions src/Resources/contao/models/LicenseModel.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

/*
* This file is part of Contao.
* This file is part of Oveleon Isotope Product License.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
* (c) https://www.oveleon.de/
*/

namespace Oveleon\IsotopeProductLicenses;
Expand All @@ -16,8 +14,8 @@
* @property integer $id
* @property string $title
* @property string $product
* @property string $validLicenses
* @property string $usedLicenses
* @property string $listitems
* @property string $useditems
*
* @method static LicenseModel|null findById($id, array $opt=array())
* @method static LicenseModel|null findByPk($id, array $opt=array())
Expand Down

0 comments on commit 40d48bd

Please sign in to comment.