mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-24 04:56:13 +01:00
This commit is contained in:
Marko Deutscher 2024-11-07 01:02:40 -05:00 committed by GitHub
commit 38432a58b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 307 additions and 5 deletions

View file

@ -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);

View file

@ -0,0 +1,30 @@
<?php
namespace TTN\Tea\Controller;
use TTN\Tea\Domain\Model\Tea;
use TTN\Tea\Domain\Repository\TeaRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
class RatingController extends ActionController
{
public function __construct(protected TeaRepository $teaRepository)
{
}
public function ratingAction(Tea $tea, int $stars)
{
$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();
}
}

View file

@ -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;
}
}

View file

@ -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;
}
);

View file

@ -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,
]
],
],
];

View file

@ -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}
}
}

View file

@ -11,6 +11,10 @@
<source>Tea single view</source>
<target>Tee-Einzelansicht</target>
</trans-unit>
<trans-unit id="plugin.tea_rating" resname="plugin.tea_rating">
<source>Tea Rating view</source>
<target>Tee-Bewertungsansicht</target>
</trans-unit>
<trans-unit id="plugin.tea_frontend_editor" resname="plugin.tea_frontend_editor" approved="yes">
<source>Tea front-end editor</source>
<target>Frontend-Editor für Tee</target>
@ -27,6 +31,10 @@
<source>Title</source>
<target>Titel</target>
</trans-unit>
<trans-unit id="plugin.tea.property.stars">
<source>Stars</source>
<target>Sterne</target>
</trans-unit>
<trans-unit id="plugin.frontEndEditor.index.heading" resname="plugin.frontEndEditor.index.heading" approved="yes">
<source>My teas</source>
<target>Meine Tees</target>
@ -55,6 +63,10 @@
<source>Actions</source>
<target>Aktionen</target>
</trans-unit>
<trans-unit id="plugin.frontEndEditor.action.rating">
<source>Rating</source>
<target>Bewertung</target>
</trans-unit>
<trans-unit id="plugin.frontEndEditor.action.edit" resname="plugin.frontEndEditor.action.edit" approved="yes">
<source>Edit</source>
<target>Bearbeiten</target>

View file

@ -35,6 +35,10 @@
<source>Visible</source>
<target>Sichtbar</target>
</trans-unit>
<trans-unit id="tx_tea_domain_model_product_tea.stars">
<source>Stars</source>
<target>Sterne</target>
</trans-unit>
</body>
</file>
</xliff>

View file

@ -9,6 +9,9 @@
<trans-unit id="plugin.tea_show" resname="plugin.tea_show">
<source>Tea single view</source>
</trans-unit>
<trans-unit id="plugin.tea_rating" resname="plugin.tea_rating">
<source>Tea Rating view</source>
</trans-unit>
<trans-unit id="plugin.tea_frontend_editor" resname="plugin.tea_frontend_editor">
<source>Tea front-end editor</source>
</trans-unit>
@ -36,12 +39,18 @@
<trans-unit id="plugin.frontEndEditor.property.title" resname="plugin.frontEndEditor.property.title">
<source>Title</source>
</trans-unit>
<trans-unit id="plugin.frontEndEditor.property.stars">
<source>Stars</source>
</trans-unit>
<trans-unit id="plugin.frontEndEditor.edit.heading" resname="plugin.frontEndEditor.edit.heading">
<source>Edit tea</source>
</trans-unit>
<trans-unit id="plugin.frontEndEditor.action.actions" resname="plugin.frontEndEditor.action.actions">
<source>Actions</source>
</trans-unit>
<trans-unit id="plugin.frontEndEditor.action.rating">
<source>Rating</source>
</trans-unit>
<trans-unit id="plugin.frontEndEditor.action.edit" resname="plugin.frontEndEditor.action.edit">
<source>Edit</source>
</trans-unit>
@ -60,6 +69,10 @@
<trans-unit id="plugin.frontEndEditor.new.heading" resname="plugin.frontEndEditor.new.heading">
<source>Create new tea</source>
</trans-unit>
<trans-unit id="plugin.tea.filter.rating" resname="plugin.tea.filter.rating">
<source>Filter by rating</source>
</trans-unit>
</body>
</file>
</xliff>

View file

@ -27,6 +27,9 @@
<trans-unit id="tx_tea_domain_model_tea.hidden" resname="tx_tea_domain_model_tea.hidden">
<source>Visible</source>
</trans-unit>
<trans-unit id="tx_tea_domain_model_product_tea.stars">
<source>Stars</source>
</trans-unit>
</body>
</file>
</xliff>

View file

@ -25,6 +25,17 @@
<f:render partial="FrontEndEditor/ValidationResult" arguments="{property: 'description'}"/>
</div>
</div>
<div class="row mb-3">
<label for="{idPrefix}-stars" class="col-sm-2 col-form-label">
<f:translate key="{propertyLabelPrefix}.stars"/>
</label>
<div class="col-sm-10">
<f:form.textfield property="stars" id="{idPrefix}-stars" maxlength="5"
class="form-control" errorClass="is-invalid" required="required"/>
<f:render partial="FrontEndEditor/ValidationResult" arguments="{property: 'stars'}"/>
</div>
</div>
</fieldset>
<div class="d-flex justify-content-end mt-3 mb-3">

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="main">
<h2>
Rating Plugin: <f:translate key="plugin.tea.heading"/>
</h2>
<f:link.action action="filter" controller="Rating" arguments="{stars:1}">1</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:2}">2</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:3}">3</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:4}">4</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:5}">5</f:link.action>
<table class="table">
<thead>
<tr>
<th>
<f:translate key="plugin.tea.property.uid"/>
</th>
<th>
<f:translate key="plugin.tea.property.title"/>
</th>
</tr>
</thead>
<tbody>
<f:for each="{teas}" as="tea">
<tr>
<td>
{tea.uid}
</td>
<td>
<f:link.action action="show" arguments="{tea: tea}" pageUid="{settings.singleViewPageUid}">
{tea.title}
</f:link.action>
</td>
</tr>
</f:for>
</tbody>
</table>
</f:section>
</html>

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="main">
<h2>
<f:translate key="plugin.tea.heading"/>
</h2>
<f:translate key="plugin.tea.filter.rating"/>
<f:link.action action="filter" controller="Rating" arguments="{stars:1}">1</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:2}">2</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:3}">3</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:4}">4</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:5}">5</f:link.action>
<table class="table">
<thead>
<tr>
<th>
<f:translate key="plugin.tea.property.uid"/>
</th>
<th>
<f:translate key="plugin.tea.property.title"/>
</th>
</tr>
</thead>
<tbody>
<f:for each="{teas}" as="tea">
<tr>
<td>
{tea.uid}
</td>
<td>
<f:link.action pluginName="tearaing" action="show" arguments="{tea: tea}" pageUid="{settings.singleViewPageUid}">
{tea.title}
</f:link.action>
</td>
</tr>
</f:for>
</tbody>
</table>
</f:section>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="main">
<h2>
Rating Plugin: {tea.title}
</h2>
{tea.description -> f:format.html()}
</f:section>
</html>

View file

@ -26,6 +26,9 @@
<th scope="col" colspan="2">
<f:translate key="plugin.frontEndEditor.action.actions"/>
</th>
<th scope="col" colspan="2">
<f:translate key="plugin.frontEndEditor.action.rating"/>
</th>
</tr>
<f:for each="{teas}" as="tea">
<tr>
@ -46,6 +49,14 @@
class="btn btn-danger"/>
</f:form>
</td>
<td>
<f:link.action action="rating" controller="Rating" arguments="{tea:tea,stars:1}">1</f:link.action>
<f:link.action action="rating" controller="Rating" arguments="{tea:tea,stars:2}">2</f:link.action>
<f:link.action action="rating" controller="Rating" arguments="{tea:tea,stars:3}">3</f:link.action>
<f:link.action action="rating" controller="Rating" arguments="{tea:tea,stars:4}">4</f:link.action>
<f:link.action action="rating" controller="Rating" arguments="{tea:tea,stars:5}">5</f:link.action>
({tea.stars})
</td>
</tr>
</f:for>
</table>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="main">
<h2>
<f:translate key="plugin.tea.heading"/>
</h2>
<f:link.action action="filter" controller="Rating" arguments="{stars:1}">1</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:2}">2</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:3}">3</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:4}">4</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:5}">5</f:link.action>
<table class="table">
<thead>
<tr>
<th>
<f:translate key="plugin.tea.property.uid"/>
</th>
<th>
<f:translate key="plugin.tea.property.title"/>
</th>
</tr>
</thead>
<tbody>
<f:for each="{teas}" as="tea">
<tr>
<td>
{tea.uid}
</td>
<td>
<f:link.action action="show" arguments="{tea: tea}" pageUid="{settings.singleViewPageUid}">
{tea.title}
</f:link.action>
</td>
</tr>
</f:for>
</tbody>
</table>
</f:section>
</html>

View file

@ -6,7 +6,6 @@
<h2>
<f:translate key="plugin.tea.heading"/>
</h2>
<table class="table">
<thead>
<tr>

View file

@ -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'
]
);

View file

@ -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)
);