From 9f7faa76f7657a370558ad22eb8da1274f041232 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Mon, 5 Jun 2023 15:14:32 +0200 Subject: [PATCH 1/5] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28a834a..8a7437c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ This plugin adds a new sub-menu *Recommendations* with recommendation archives a ## Features -- Compatible with Contao 4.9 and higher versions (PHP 8 Support) +- Compatible with Contao 4.13 and higher versions (PHP 8 Support) - Possibility to create multiple recommendation archives - Possibility to create recommendation items - Frontend- and Backend permissions for archives and items From 80dc9b760755c098e642670c64a65d6922fc195d Mon Sep 17 00:00:00 2001 From: doishub Date: Mon, 24 Jul 2023 12:08:53 +0200 Subject: [PATCH 2/5] Support `auto-item` --- contao/dca/tl_recommendation.php | 5 ++ contao/dca/tl_recommendation_archive.php | 8 ++- .../languages/de/tl_recommendation_list.xlf | 4 ++ .../languages/en/tl_recommendation_list.xlf | 3 + contao/modules/ModuleRecommendation.php | 9 +-- contao/modules/ModuleRecommendationForm.php | 15 +++++ contao/modules/ModuleRecommendationList.php | 55 ++++++++++++++++++- src/Model/RecommendationArchiveModel.php | 1 + 8 files changed, 91 insertions(+), 9 deletions(-) diff --git a/contao/dca/tl_recommendation.php b/contao/dca/tl_recommendation.php index 28f655b..71c6dd6 100644 --- a/contao/dca/tl_recommendation.php +++ b/contao/dca/tl_recommendation.php @@ -217,6 +217,11 @@ 'eval' => ['doNotCopy'=>true, 'maxlength'=>255, 'tl_class'=>'w100 clr'], 'sql' => "varchar(255) NOT NULL default ''" ], + 'scope' => [ + 'inputType' => 'text', + 'filter' => true, + 'sql' => "varchar(255) NOT NULL default ''" + ], 'cssClass' => [ 'exclude' => true, 'inputType' => 'text', diff --git a/contao/dca/tl_recommendation_archive.php b/contao/dca/tl_recommendation_archive.php index fe5a269..daa0e3c 100644 --- a/contao/dca/tl_recommendation_archive.php +++ b/contao/dca/tl_recommendation_archive.php @@ -89,7 +89,7 @@ // Palettes 'palettes' => [ '__selector__' => ['protected'], - 'default' => '{title_legend},title,jumpTo;{protected_legend:hide},protected' + 'default' => '{title_legend},title,jumpTo,useAutoItem;{protected_legend:hide},protected' ], // Subpalettes @@ -127,6 +127,12 @@ 'eval' => ['submitOnChange'=>true], 'sql' => "char(1) NOT NULL default ''" ], + 'useAutoItem' => [ + 'exclude' => true, + 'filter' => true, + 'inputType' => 'checkbox', + 'sql' => "char(1) NOT NULL default ''" + ], 'groups' => [ 'exclude' => true, 'inputType' => 'checkbox', diff --git a/contao/languages/de/tl_recommendation_list.xlf b/contao/languages/de/tl_recommendation_list.xlf index 4dcc15c..95c275c 100644 --- a/contao/languages/de/tl_recommendation_list.xlf +++ b/contao/languages/de/tl_recommendation_list.xlf @@ -53,6 +53,10 @@ Rating descending Bewertung absteigend + + %s Reviews + %s Bewertungen + diff --git a/contao/languages/en/tl_recommendation_list.xlf b/contao/languages/en/tl_recommendation_list.xlf index 7014289..e28fc8d 100644 --- a/contao/languages/en/tl_recommendation_list.xlf +++ b/contao/languages/en/tl_recommendation_list.xlf @@ -40,6 +40,9 @@ Rating descending + + %s Reviews + diff --git a/contao/modules/ModuleRecommendation.php b/contao/modules/ModuleRecommendation.php index e7a8b55..f0d50ec 100644 --- a/contao/modules/ModuleRecommendation.php +++ b/contao/modules/ModuleRecommendation.php @@ -185,15 +185,12 @@ protected function parseRecommendations(Collection $objRecommendations): array $count = 0; $arrRecommendations = []; - while ($objRecommendations->next()) + foreach ($objRecommendations as $recommendation) { - /** @var RecommendationModel $objRecommendation */ - $objRecommendation = $objRecommendations->current(); - /** @var RecommendationArchiveModel $objRecommendationArchive */ - $objRecommendationArchive = $objRecommendation->getRelated('pid'); + $objRecommendationArchive = $recommendation->getRelated('pid'); - $arrRecommendations[] = $this->parseRecommendation($objRecommendation, $objRecommendationArchive, ((++$count == 1) ? ' first' : '') . (($count == $limit) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even'), $count); + $arrRecommendations[] = $this->parseRecommendation($recommendation, $objRecommendationArchive, ((++$count == 1) ? ' first' : '') . (($count == $limit) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even'), $count); } return $arrRecommendations; diff --git a/contao/modules/ModuleRecommendationForm.php b/contao/modules/ModuleRecommendationForm.php index a5d76a3..90702e5 100644 --- a/contao/modules/ModuleRecommendationForm.php +++ b/contao/modules/ModuleRecommendationForm.php @@ -95,6 +95,10 @@ protected function compile(): void return; } + // Get archive record + $archive = RecommendationArchiveModel::findMultipleByIds($this->recommendation_archives); + $archive = $archive[0] ?? null; + // Form fields $arrFields = [ 'author' => [ @@ -142,6 +146,16 @@ protected function compile(): void ], ]; + // Add scope for auto alias archives + if($archive && $archive->useAutoItem) + { + $arrFields['scope'] = [ + 'name' => 'scope', + 'inputType' => 'hidden', + 'value' => Input::get('auto_item') + ]; + } + // Captcha if (!$this->recommendation_disableCaptcha) { @@ -266,6 +280,7 @@ protected function compile(): void 'time' => $time, 'text' => $this->convertLineFeeds($strText), 'rating' => $arrWidgets['rating']->value, + 'scope' => $arrWidgets['scope']->value ?? '', 'published' => $this->recommendation_moderate ? '' : 1 ]; diff --git a/contao/modules/ModuleRecommendationList.php b/contao/modules/ModuleRecommendationList.php index d74745a..0bbdb99 100644 --- a/contao/modules/ModuleRecommendationList.php +++ b/contao/modules/ModuleRecommendationList.php @@ -10,6 +10,7 @@ use Contao\BackendTemplate; use Contao\Config; +use Contao\Controller; use Contao\CoreBundle\Exception\PageNotFoundException; use Contao\Environment; use Contao\Input; @@ -17,6 +18,7 @@ use Contao\Pagination; use Contao\StringUtil; use Contao\System; +use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel; use Oveleon\ContaoRecommendationBundle\Model\RecommendationModel; /** @@ -162,6 +164,10 @@ protected function compile() $objRecommendations = $this->fetchItems($this->recommendation_archives, $blnFeatured, ($limit ?: 0), $offset, $minRating); + // Add summary details + $this->Template->totalCount = $intTotal; + $this->addSummary($objRecommendations); + // Add recommendations if ($objRecommendations !== null) { @@ -169,6 +175,23 @@ protected function compile() } } + protected function addSummary($objRecommendations): void + { + Controller::loadLanguageFile('tl_recommendation_list'); + + $ratings = $objRecommendations->fetchEach('rating'); + $grouped = \array_count_values($ratings); + $average = 0; + + \array_walk($grouped, static function ($count, $number) use (&$average){ + $average += ($number * $count); + }); + + $this->Template->average = $average / $this->Template->totalCount; + $this->Template->averageRound = ceil($this->Template->average); + $this->Template->countLabel = sprintf($GLOBALS['TL_LANG']['tl_recommendation_list']['recommendation_count'], $this->Template->totalCount); + } + /** * Count the total matching items * @@ -196,7 +219,8 @@ protected function countItems($recommendationArchives, $blnFeatured, $minRating) } } - return RecommendationModel::countPublishedByPids($recommendationArchives, $blnFeatured, $minRating); + //return RecommendationModel::countPublishedByPids($recommendationArchives, $blnFeatured, $minRating); + return $this->fetchItems($recommendationArchives, $blnFeatured, 0, 0, $minRating)?->count() ?? 0; } /** @@ -247,7 +271,34 @@ protected function fetchItems($recommendationArchives, $blnFeatured, $limit, $of $order .= "$t.date DESC"; } - return RecommendationModel::findPublishedByPids($recommendationArchives, $blnFeatured, $limit, $offset, $minRating, ['order'=>$order]); + // Get archives + $archives = RecommendationArchiveModel::findMultipleByIds($recommendationArchives); + $archives = array_combine( + $archives->fetchEach('id'), + $archives->fetchAll() + ); + + // Fetch items + $items = []; + + // Get auto item + $autoItem = Input::get('auto_item'); + + foreach (RecommendationModel::findPublishedByPids($recommendationArchives, $blnFeatured, $limit, $offset, $minRating, ['order'=>$order]) ?? [] as $item) + { + if($archives[$item->pid]['useAutoItem'] ?? null) + { + // Add only if the scope match to the current auto_item + if($autoItem === $item->scope) + { + $items[] = $item; + } + }else{ + $items[] = $item; + } + } + + return new Collection($items, $t); } } diff --git a/src/Model/RecommendationArchiveModel.php b/src/Model/RecommendationArchiveModel.php index a283ac5..d59c494 100644 --- a/src/Model/RecommendationArchiveModel.php +++ b/src/Model/RecommendationArchiveModel.php @@ -19,6 +19,7 @@ * @property string $title * @property integer $jumpTo * @property boolean $protected + * @property boolean $useAutoItem * @property string $groups * * @method static RecommendationArchiveModel|null findById($id, array $opt=array()) From 127c2cee74ca5b413e7feda0e4be85a95c1adf53 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Mon, 24 Jul 2023 12:25:04 +0200 Subject: [PATCH 3/5] Add auto-item translations --- contao/languages/de/tl_recommendation_archive.xlf | 8 ++++++++ contao/languages/en/tl_recommendation_archive.xlf | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/contao/languages/de/tl_recommendation_archive.xlf b/contao/languages/de/tl_recommendation_archive.xlf index dade3fa..3be91b5 100644 --- a/contao/languages/de/tl_recommendation_archive.xlf +++ b/contao/languages/de/tl_recommendation_archive.xlf @@ -25,6 +25,14 @@ Show recommendations to certain member groups only. Bewertungen nur bestimmten Frontend-Gruppen anzeigen. + + Use auto-item + Auto-item nutzen + + + Activate auto-item parameter for this archive. + Auto-Item Parameter für dieses Archiv aktivieren. + Allowed member groups Erlaubte Mitgliedergruppen diff --git a/contao/languages/en/tl_recommendation_archive.xlf b/contao/languages/en/tl_recommendation_archive.xlf index 966798d..5ad8ea7 100644 --- a/contao/languages/en/tl_recommendation_archive.xlf +++ b/contao/languages/en/tl_recommendation_archive.xlf @@ -19,6 +19,12 @@ Show recommendations to certain member groups only. + + Use auto-item + + + Activate auto-item parameter for this archive. + Allowed member groups From 5dfabdbbd1545dc1b4f35b0095507dcdaea99ee6 Mon Sep 17 00:00:00 2001 From: doishub Date: Mon, 24 Jul 2023 12:29:27 +0200 Subject: [PATCH 4/5] Move field `useAutoItem` to expert legend --- contao/dca/tl_recommendation_archive.php | 2 +- contao/languages/de/tl_recommendation_archive.xlf | 4 ++++ contao/languages/en/tl_recommendation_archive.xlf | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/contao/dca/tl_recommendation_archive.php b/contao/dca/tl_recommendation_archive.php index daa0e3c..bc83dcb 100644 --- a/contao/dca/tl_recommendation_archive.php +++ b/contao/dca/tl_recommendation_archive.php @@ -89,7 +89,7 @@ // Palettes 'palettes' => [ '__selector__' => ['protected'], - 'default' => '{title_legend},title,jumpTo,useAutoItem;{protected_legend:hide},protected' + 'default' => '{title_legend},title,jumpTo;{expert_legend:hide},useAutoItem;{protected_legend:hide},protected' ], // Subpalettes diff --git a/contao/languages/de/tl_recommendation_archive.xlf b/contao/languages/de/tl_recommendation_archive.xlf index dade3fa..10af656 100644 --- a/contao/languages/de/tl_recommendation_archive.xlf +++ b/contao/languages/de/tl_recommendation_archive.xlf @@ -49,6 +49,10 @@ Access protection Zugriffsschutz + + Expert settings + Experteneinstellungen + Settings Einstellungen diff --git a/contao/languages/en/tl_recommendation_archive.xlf b/contao/languages/en/tl_recommendation_archive.xlf index 966798d..1840f49 100644 --- a/contao/languages/en/tl_recommendation_archive.xlf +++ b/contao/languages/en/tl_recommendation_archive.xlf @@ -34,6 +34,9 @@ Title and redirect page + + Expert settings + Access protection From ae654943b4dd3f9a60cbd8713cd205aa0b0f30b7 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Mon, 24 Jul 2023 12:32:32 +0200 Subject: [PATCH 5/5] Move archive expert legend to bottom --- contao/dca/tl_recommendation_archive.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contao/dca/tl_recommendation_archive.php b/contao/dca/tl_recommendation_archive.php index bc83dcb..75d9053 100644 --- a/contao/dca/tl_recommendation_archive.php +++ b/contao/dca/tl_recommendation_archive.php @@ -89,7 +89,7 @@ // Palettes 'palettes' => [ '__selector__' => ['protected'], - 'default' => '{title_legend},title,jumpTo;{expert_legend:hide},useAutoItem;{protected_legend:hide},protected' + 'default' => '{title_legend},title,jumpTo;{protected_legend:hide},protected;{expert_legend:hide},useAutoItem' ], // Subpalettes