diff --git a/Classes/Controller/FrontEndEditorController.php b/Classes/Controller/FrontEndEditorController.php index 8b2c50c..1d568ca 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) { @@ -63,7 +63,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..7d539b0 --- /dev/null +++ b/Classes/Controller/RatingController.php @@ -0,0 +1,30 @@ +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/Tea.php b/Classes/Domain/Model/Tea.php index 7ce31a0..a1867fa 100644 --- a/Classes/Domain/Model/Tea.php +++ b/Classes/Domain/Model/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/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index 74531e3..b3008b1 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -32,10 +32,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/TCA/tx_tea_domain_model_tea.php b/Configuration/TCA/tx_tea_domain_model_tea.php index f1b6b6c..0aa3c0a 100644 --- a/Configuration/TCA/tx_tea_domain_model_tea.php +++ b/Configuration/TCA/tx_tea_domain_model_tea.php @@ -29,8 +29,8 @@ $tca = [ '1' => [ 'showitem' => '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, - title, description, image, owner, - --div--;LLL:EXT:tea/Resources/Private/Language/locallang_db.xlf:tx_tea_domain_model_tea.tabs.access, + 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,', ], @@ -206,6 +206,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/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 d7a0e67..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 @@ -27,6 +31,10 @@ Title Titel + + Stars + Sterne + My teas Meine Tees @@ -55,6 +63,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 c05d691..dc58c8a 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 d27c779..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 @@ -36,12 +39,18 @@ Title + + Stars + Edit tea Actions + + Rating + Edit @@ -60,6 +69,10 @@ Create new tea + + Filter by rating + + diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index f04d084..03125e7 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/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/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..d8b6b8b 100644 --- a/Resources/Private/Templates/Tea/Index.html +++ b/Resources/Private/Templates/Tea/Index.html @@ -6,7 +6,6 @@

- diff --git a/ext_localconf.php b/ext_localconf.php index 76fb8c7..778efce 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; @@ -51,3 +52,18 @@ ExtensionUtility::configurePlugin( FrontEndEditorController::class => 'index, edit, update, create, new, delete', ] ); + +// 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' + ] +); + diff --git a/ext_tables.sql b/ext_tables.sql index 6021d71..0cc0263 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -3,6 +3,7 @@ CREATE TABLE tx_tea_domain_model_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) );