Skip to content

Commit

Permalink
review CE: allow to gather all products vs. selected ones
Browse files Browse the repository at this point in the history
only synchronize products that aren't obsolete
  • Loading branch information
m-vo committed Jun 27, 2019
1 parent 6a22bd0 commit bc3fbc5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
17 changes: 14 additions & 3 deletions src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/*
* Regiondo Bundle for Contao Open Source CMS.
*
* @copyright Copyright (c) 2018, derhaeuptling
* @copyright Copyright (c) 2019, derhaeuptling
* @author Codefog <https://codefog.pl>
* @author Moritz V. <https://github.com/m-vo>
* @license MIT
*/

Expand All @@ -18,9 +19,11 @@
/*
* Add palettes
*/
$GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'regiondo_filterProducts';
$GLOBALS['TL_DCA']['tl_content']['palettes']['regiondo_event_booking_iframe'] = '{type_legend},type;{include_legend},regiondo_calendar,regiondo_iframeWidth;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;{invisible_legend:hide},invisible,start,stop';
$GLOBALS['TL_DCA']['tl_content']['palettes']['regiondo_reviews'] = '{type_legend},type;{include_legend},regiondo_products,regiondo_reviewsLimit,regiondo_syncReviews;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;{invisible_legend:hide},invisible,start,stop';
$GLOBALS['TL_DCA']['tl_content']['palettes']['regiondo_reviews'] = '{type_legend},type;{include_legend},regiondo_filterProducts,regiondo_reviewsLimit,regiondo_syncReviews;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;{invisible_legend:hide},invisible,start,stop';
$GLOBALS['TL_DCA']['tl_content']['palettes']['regiondo_voucher'] = '{type_legend},type;{include_legend},regiondo_voucher,regiondo_iframeWidth;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;{invisible_legend:hide},invisible,start,stop';
$GLOBALS['TL_DCA']['tl_content']['subpalettes']['regiondo_filterProducts'] = 'regiondo_products';

/*
* Add fields
Expand Down Expand Up @@ -65,7 +68,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_content']['regiondo_reviewsLimit'],
'exclude' => true,
'inputType' => 'text',
'eval' => ['mandatory' => true, 'rgxp' => 'natural', 'tl_class' => 'w50'],
'eval' => ['mandatory' => true, 'rgxp' => 'natural', 'tl_class' => 'w50 clr'],
'sql' => ['type' => 'smallint', 'unsigned' => true, 'default' => 0],
];

Expand All @@ -85,3 +88,11 @@
$GLOBALS['TL_DCA']['tl_content']['fields']['regiondo_reviews'] = [
'sql' => ['type' => 'blob'],
];

$GLOBALS['TL_DCA']['tl_content']['fields']['regiondo_filterProducts'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['regiondo_filterProducts'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => ['submitOnChange' => true],
'sql' => ['type' => 'string', 'default' => '1', 'length' => 1, 'options' => ['fixed' => true]],
];
1 change: 1 addition & 0 deletions src/Resources/contao/languages/de/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

$GLOBALS['TL_LANG']['tl_content']['regiondo_calendar'] = ['Regiondo calendar', 'Please choose the Regiondo calendar.'];
$GLOBALS['TL_LANG']['tl_content']['regiondo_filterProducts'] = ['Filter Regiondo products', 'Enable to select a range of products. If disabled all available products will be used.'];
$GLOBALS['TL_LANG']['tl_content']['regiondo_products'] = ['Regiondo products', 'Please choose one or more Regiondo products to get the reviews from.'];
$GLOBALS['TL_LANG']['tl_content']['regiondo_voucher'] = ['Regiondo voucher', 'Please choose the Regiondo voucher.'];
$GLOBALS['TL_LANG']['tl_content']['regiondo_eventTemplate'] = ['Regiondo event template', 'Here you can choose the Regiondo event template.'];
Expand Down
1 change: 1 addition & 0 deletions src/Resources/contao/languages/en/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

$GLOBALS['TL_LANG']['tl_content']['regiondo_calendar'] = ['Regiondo calendar', 'Please choose the Regiondo calendar.'];
$GLOBALS['TL_LANG']['tl_content']['regiondo_filterProducts'] = ['Filter Regiondo products', 'Enable to select a range of products. If disabled all available products will be used.'];
$GLOBALS['TL_LANG']['tl_content']['regiondo_products'] = ['Regiondo products', 'Please choose one or more Regiondo products to get the reviews from.'];
$GLOBALS['TL_LANG']['tl_content']['regiondo_voucher'] = ['Regiondo voucher', 'Please choose the Regiondo voucher.'];
$GLOBALS['TL_LANG']['tl_content']['regiondo_eventTemplate'] = ['Regiondo event template', 'Here you can choose the Regiondo event template.'];
Expand Down
38 changes: 29 additions & 9 deletions src/Synchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,18 @@ public function synchronizeReviews(int $contentElementId): array
throw new SynchronizerException(\sprintf('Content element ID %s does not exist', $contentElementId));
}

$productIds = $this->getProductIds($contentElement['regiondo_products']);
if($contentElement['regiondo_filterProducts']) {
$productIds = $this->getProductIds($contentElement['regiondo_products'], false);

if (0 === \count($productIds)) {
throw new SynchronizerException(\sprintf('Content element ID %s has no Regiondo products', $contentElementId));
if (0 === \count($productIds)) {
throw new SynchronizerException(\sprintf('Content element ID %s has no Regiondo products', $contentElementId));
}
} else {
$productIds = $this->getProductIds(null, false);

if(0 === \count($productIds)) {
return [];
}
}

$reviews = [];
Expand Down Expand Up @@ -570,20 +578,32 @@ private function storeImage(Client $client, int $calendarId, string $url, string
/**
* Get the product IDs.
*
* @param string|array $recordIds
* @param string|array|null $recordIds Record ids to filter for.
* @param bool $includeObsolete Whether to include products marked as 'obsolete'.
*
* @return array
*/
private function getProductIds($recordIds): array
private function getProductIds($recordIds = null, $includeObsolete = true): array
{
$recordIds = StringUtil::deserialize($recordIds, true);
$filterConditions = [];

if (0 === \count($recordIds)) {
return [];
if(null !== $recordIds) {
$recordIds = StringUtil::deserialize($recordIds, true);

if (0 === \count($recordIds)) {
return [];
}

$filterConditions[] = 'id IN ('.\implode(',', $recordIds).')';
}

if(!$includeObsolete) {
$filterConditions[] = 'obsolete = 0';
}

$productIds = [];
$records = $this->db->fetchAll('SELECT product FROM tl_regiondo_product WHERE id IN ('.\implode(',', $recordIds).')');
$filterCondition = \count($filterConditions) > 0 ? ' WHERE ' . implode(' AND ', $filterConditions) : '';
$records = $this->db->fetchAll('SELECT product FROM tl_regiondo_product' . $filterCondition);

foreach ($records as $record) {
$productIds[] = (int) $record['product'];
Expand Down

0 comments on commit bc3fbc5

Please sign in to comment.