From d9c723e2a36471b906638b3b883a7b2eac0faea6 Mon Sep 17 00:00:00 2001 From: Eike Starkmann Date: Mon, 27 Nov 2023 15:44:16 +0100 Subject: [PATCH 1/2] [TASK] add rating functionality as use case for #893 Ref:#893 --- .../Controller/FrontEndEditorController.php | 4 +- Classes/Controller/RatingController.php | 28 +++++++++++++ Classes/Domain/Model/Product/Tea.php | 24 +++++++++++ .../TCA/tx_tea_domain_model_product_tea.php | 12 +++++- Resources/Private/Language/de.locallang.xlf | 8 ++++ .../Private/Language/de.locallang_db.xlf | 4 ++ Resources/Private/Language/locallang.xlf | 6 +++ Resources/Private/Language/locallang_db.xlf | 3 ++ .../Private/Partials/FrontEndEditor/Form.html | 11 +++++ .../Templates/FrontEndEditor/Index.html | 11 +++++ .../Private/Templates/Rating/Filter.html | 41 +++++++++++++++++++ Resources/Private/Templates/Tea/Index.html | 6 ++- ext_localconf.php | 4 ++ ext_tables.sql | 1 + 14 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 Classes/Controller/RatingController.php create mode 100644 Resources/Private/Templates/Rating/Filter.html diff --git a/Classes/Controller/FrontEndEditorController.php b/Classes/Controller/FrontEndEditorController.php index 1e6ca69..564f27d 100644 --- a/Classes/Controller/FrontEndEditorController.php +++ b/Classes/Controller/FrontEndEditorController.php @@ -19,7 +19,7 @@ class FrontEndEditorController extends ActionController { private Context $context; - private TeaRepository $teaRepository; + protected TeaRepository $teaRepository; public function __construct(Context $context, TeaRepository $teaRepository) { @@ -60,7 +60,7 @@ class FrontEndEditorController extends ActionController /** * @throws \RuntimeException */ - private function checkIfUserIsOwner(Tea $tea): void + protected function checkIfUserIsOwner(Tea $tea): void { if ($tea->getOwnerUid() !== $this->getUidOfLoggedInUser()) { throw new \RuntimeException('You do not have the permissions to edit this tea.', 1687363749); diff --git a/Classes/Controller/RatingController.php b/Classes/Controller/RatingController.php new file mode 100644 index 0000000..0462649 --- /dev/null +++ b/Classes/Controller/RatingController.php @@ -0,0 +1,28 @@ +checkIfUserIsOwner($tea); + $tea->setStars($stars); + $this->teaRepository->update($tea); + + return $this->redirect('index','FrontEndEditor'); + } + + public function filterAction(int $stars) + { + $this->view->assign('teas', $this->teaRepository->findByStars($stars)); + return $this->htmlResponse(); + } + +} diff --git a/Classes/Domain/Model/Product/Tea.php b/Classes/Domain/Model/Product/Tea.php index 9060a55..fc1b20c 100644 --- a/Classes/Domain/Model/Product/Tea.php +++ b/Classes/Domain/Model/Product/Tea.php @@ -32,6 +32,11 @@ class Tea extends AbstractEntity */ protected $image; + /** + * @var int + */ + protected $stars = null; + // Note: We cannot use `@var` for the more specific type annotation here as this confuses the Extbase type mapper. /** @@ -90,4 +95,23 @@ class Tea extends AbstractEntity { $this->ownerUid = $ownerUid; } + + /** + * @return int|null + */ + public function getStars(): ?int + { + return $this->stars; + } + + /** + * @param int|null $stars + * @return void + */ + public function setStars(?int $stars): void + { + $this->stars = $stars; + } + + } diff --git a/Configuration/TCA/tx_tea_domain_model_product_tea.php b/Configuration/TCA/tx_tea_domain_model_product_tea.php index 781270e..897d3c1 100644 --- a/Configuration/TCA/tx_tea_domain_model_product_tea.php +++ b/Configuration/TCA/tx_tea_domain_model_product_tea.php @@ -25,7 +25,7 @@ $tca = [ '1' => [ 'showitem' => '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, - title, description, image, owner, + title, description, image, stars, owner, --div--;LLL:EXT:tea/Resources/Private/Language/locallang_db.xlf:tx_tea_domain_model_product_tea.tabs.access, --palette--;;hidden, --palette--;;access,', @@ -202,6 +202,16 @@ $tca = [ 'hideSuggest' => true, ], ], + 'stars' => [ + 'exclude' => true, + 'label' => 'LLL:EXT:tea/Resources/Private/Language/locallang_db.xlf:tx_tea_domain_model_product_tea.stars', + 'config' => [ + 'type' => 'input', + 'size' => 8, + 'eval' => 'trim', + 'max' => 255, + ] + ], ], ]; diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 7357618..0874a53 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -27,6 +27,10 @@ Title Titel + + Stars + Sterne + My teas Meine Tees @@ -55,6 +59,10 @@ Actions Aktionen + + Rating + Bewertung + Edit Bearbeiten diff --git a/Resources/Private/Language/de.locallang_db.xlf b/Resources/Private/Language/de.locallang_db.xlf index 939220c..13dea36 100644 --- a/Resources/Private/Language/de.locallang_db.xlf +++ b/Resources/Private/Language/de.locallang_db.xlf @@ -35,6 +35,10 @@ Visible Sichtbar + + Stars + Sterne + diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 7f219ef..1247f42 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -36,12 +36,18 @@ Title + + Stars + Edit tea Actions + + Rating + Edit diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index de64197..7d321c4 100644 --- a/Resources/Private/Language/locallang_db.xlf +++ b/Resources/Private/Language/locallang_db.xlf @@ -27,6 +27,9 @@ Visible + + Stars + diff --git a/Resources/Private/Partials/FrontEndEditor/Form.html b/Resources/Private/Partials/FrontEndEditor/Form.html index 8cb35cb..bbe957b 100644 --- a/Resources/Private/Partials/FrontEndEditor/Form.html +++ b/Resources/Private/Partials/FrontEndEditor/Form.html @@ -25,6 +25,17 @@ + +
+ +
+ + +
+
diff --git a/Resources/Private/Templates/FrontEndEditor/Index.html b/Resources/Private/Templates/FrontEndEditor/Index.html index fd89ad4..f1100c0 100644 --- a/Resources/Private/Templates/FrontEndEditor/Index.html +++ b/Resources/Private/Templates/FrontEndEditor/Index.html @@ -26,6 +26,9 @@ + + + @@ -46,6 +49,14 @@ class="btn btn-danger"/> + + 1 + 2 + 3 + 4 + 5 + ({tea.stars}) + diff --git a/Resources/Private/Templates/Rating/Filter.html b/Resources/Private/Templates/Rating/Filter.html new file mode 100644 index 0000000..7847c71 --- /dev/null +++ b/Resources/Private/Templates/Rating/Filter.html @@ -0,0 +1,41 @@ + + + + + +

+ +

+ 1 + 2 + 3 + 4 + 5 + + + + + + + + + + + + + + + +
+ + + +
+ {tea.uid} + + + {tea.title} + +
+
+ diff --git a/Resources/Private/Templates/Tea/Index.html b/Resources/Private/Templates/Tea/Index.html index 240466d..7847c71 100644 --- a/Resources/Private/Templates/Tea/Index.html +++ b/Resources/Private/Templates/Tea/Index.html @@ -6,7 +6,11 @@

- + 1 + 2 + 3 + 4 + 5 diff --git a/ext_localconf.php b/ext_localconf.php index 76fb8c7..bf0f0af 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -3,6 +3,7 @@ declare(strict_types=1); use TTN\Tea\Controller\FrontEndEditorController; +use TTN\Tea\Controller\RatingController; use TTN\Tea\Controller\TeaController; use TYPO3\CMS\Extbase\Utility\ExtensionUtility; @@ -17,6 +18,7 @@ ExtensionUtility::configurePlugin( // all actions [ TeaController::class => 'index', + RatingController::class => 'filter' ], // non-cacheable actions [ @@ -43,11 +45,13 @@ ExtensionUtility::configurePlugin( // all actions [ FrontEndEditorController::class => 'index, edit, update, create, new, delete', + RatingController::class => 'filter,rating' ], // non-cacheable actions [ // All actions need to be non-cacheable because they either contain dynamic data, // or because they are specific to the logged-in FE user (while FE content is cached by FE groups). FrontEndEditorController::class => 'index, edit, update, create, new, delete', + RatingController::class => 'rating' ] ); diff --git a/ext_tables.sql b/ext_tables.sql index d013de3..ef38281 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -3,6 +3,7 @@ CREATE TABLE tx_tea_domain_model_product_tea ( description varchar(2000) DEFAULT '' NOT NULL, image int(11) unsigned DEFAULT '0' NOT NULL, owner int(11) unsigned DEFAULT '0' NOT NULL, + stars int(11) unsigned DEFAULT NULL, KEY owner (owner) ); From e5e997cfde30039d2ae576a998c236c7a32fe4ca Mon Sep 17 00:00:00 2001 From: mdt Date: Tue, 7 May 2024 16:23:04 +0200 Subject: [PATCH 2/2] [TASK] Use rating controller and index controller in new Plugin (#893) --- Classes/Controller/RatingController.php | 16 +++---- Configuration/TCA/Overrides/tt_content.php | 8 ++++ Configuration/TypoScript/setup.typoscript | 24 +++++++++++ Resources/Private/Language/de.locallang.xlf | 4 ++ Resources/Private/Language/locallang.xlf | 7 ++++ .../Rating/Templates/Rating/Filter.html | 41 ++++++++++++++++++ .../Plugins/Rating/Templates/Tea/Index.html | 42 +++++++++++++++++++ .../Plugins/Rating/Templates/Tea/Show.html | 12 ++++++ Resources/Private/Templates/Tea/Index.html | 5 --- ext_localconf.php | 18 ++++++-- 10 files changed, 162 insertions(+), 15 deletions(-) create mode 100644 Resources/Private/Plugins/Rating/Templates/Rating/Filter.html create mode 100644 Resources/Private/Plugins/Rating/Templates/Tea/Index.html create mode 100644 Resources/Private/Plugins/Rating/Templates/Tea/Show.html diff --git a/Classes/Controller/RatingController.php b/Classes/Controller/RatingController.php index 0462649..7d539b0 100644 --- a/Classes/Controller/RatingController.php +++ b/Classes/Controller/RatingController.php @@ -2,17 +2,19 @@ namespace TTN\Tea\Controller; -use Psr\Http\Message\ResponseInterface; -use TTN\Tea\Domain\Model\Product\Tea; -use TTN\Tea\Domain\Repository\Product\TeaRepository; -use TYPO3\CMS\Core\Context\Context; -use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult; +use TTN\Tea\Domain\Model\Tea; +use TTN\Tea\Domain\Repository\TeaRepository; +use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; -class RatingController extends FrontEndEditorController +class RatingController extends ActionController { + + public function __construct(protected TeaRepository $teaRepository) + { + } + public function ratingAction(Tea $tea, int $stars) { - $this->checkIfUserIsOwner($tea); $tea->setStars($stars); $this->teaRepository->update($tea); diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index 7d35150..c4908f9 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -30,10 +30,18 @@ call_user_func( 'EXT:tea/Resources/Public/Icons/Extension.svg' ); + \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( + 'Tea', + 'TeaRating', + 'LLL:EXT:tea/Resources/Private/Language/locallang.xlf:plugin.tea_rating', + 'EXT:tea/Resources/Public/Icons/Extension.svg' + ); + // This removes the default controls from the plugin. $controlsToRemove = 'recursive,pages'; $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_teaindex'] = $controlsToRemove; $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_teashow'] = $controlsToRemove; $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_teafrontendeditor'] = $controlsToRemove; + $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_tearating'] = $controlsToRemove; } ); diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index 4de562a..2dc2c2b 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -21,3 +21,27 @@ plugin.tx_tea { singleViewPageUid = {$plugin.tx_tea.settings.singleViewPageUid} } } + +plugin.tx_tea_tearating { + view { + templateRootPaths { + 0 = EXT:tea/Resources/Private/Plugins/Rating/Templates/ + } + + partialRootPaths { + 0 = EXT:tea/Resources/Private/Plugins/Rating/Partials/ + } + + layoutRootPaths { + 0 = EXT:tea/Resources/Private/Plugins/Rating/Layouts/ + } + } + + persistence { + storagePid = {$plugin.tx_tea.persistence.storagePid} + } + + settings { + singleViewPageUid = {$plugin.tx_tea_tearating.settings.singleViewPageUid} + } +} diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index ec70e63..ec6bbfd 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -11,6 +11,10 @@ Tea single view Tee-Einzelansicht + + Tea Rating view + Tee-Bewertungsansicht + Tea front-end editor Frontend-Editor für Tee diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index a905a48..68cdad4 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -9,6 +9,9 @@ Tea single view + + Tea Rating view + Tea front-end editor @@ -66,6 +69,10 @@ Create new tea + + Filter by rating + + diff --git a/Resources/Private/Plugins/Rating/Templates/Rating/Filter.html b/Resources/Private/Plugins/Rating/Templates/Rating/Filter.html new file mode 100644 index 0000000..751fbda --- /dev/null +++ b/Resources/Private/Plugins/Rating/Templates/Rating/Filter.html @@ -0,0 +1,41 @@ + + + + + +

+ Rating Plugin: +

+ 1 + 2 + 3 + 4 + 5 +
+ + + + + + + + + + + + + + +
+ + + +
+ {tea.uid} + + + {tea.title} + +
+ + diff --git a/Resources/Private/Plugins/Rating/Templates/Tea/Index.html b/Resources/Private/Plugins/Rating/Templates/Tea/Index.html new file mode 100644 index 0000000..45eb436 --- /dev/null +++ b/Resources/Private/Plugins/Rating/Templates/Tea/Index.html @@ -0,0 +1,42 @@ + + + + + +

+ +

+ + 1 + 2 + 3 + 4 + 5 + + + + + + + + + + + + + + + +
+ + + +
+ {tea.uid} + + + {tea.title} + +
+
+ diff --git a/Resources/Private/Plugins/Rating/Templates/Tea/Show.html b/Resources/Private/Plugins/Rating/Templates/Tea/Show.html new file mode 100644 index 0000000..2e2ec33 --- /dev/null +++ b/Resources/Private/Plugins/Rating/Templates/Tea/Show.html @@ -0,0 +1,12 @@ + + + + + +

+ Rating Plugin: {tea.title} +

+ + {tea.description -> f:format.html()} +
+ diff --git a/Resources/Private/Templates/Tea/Index.html b/Resources/Private/Templates/Tea/Index.html index 7847c71..d8b6b8b 100644 --- a/Resources/Private/Templates/Tea/Index.html +++ b/Resources/Private/Templates/Tea/Index.html @@ -6,11 +6,6 @@

- 1 - 2 - 3 - 4 - 5 diff --git a/ext_localconf.php b/ext_localconf.php index bf0f0af..778efce 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -18,7 +18,6 @@ ExtensionUtility::configurePlugin( // all actions [ TeaController::class => 'index', - RatingController::class => 'filter' ], // non-cacheable actions [ @@ -45,13 +44,26 @@ ExtensionUtility::configurePlugin( // all actions [ FrontEndEditorController::class => 'index, edit, update, create, new, delete', - RatingController::class => 'filter,rating' ], // non-cacheable actions [ // All actions need to be non-cacheable because they either contain dynamic data, // or because they are specific to the logged-in FE user (while FE content is cached by FE groups). FrontEndEditorController::class => 'index, edit, update, create, new, delete', - RatingController::class => 'rating' ] ); + +// Combine TeaController and RatingController into a new Plugin +ExtensionUtility::configurePlugin( + 'Tea', + 'TeaRating', + [ + TeaController::class => 'index', + RatingController::class => 'filter,rating' + ], + [ + TeaController::class => 'index', + RatingController::class => 'rating,filter' + ] +); +