Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/reuse controller 893 #1300

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Classes/Controller/FrontEndEditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FrontEndEditorController extends ActionController
{
private Context $context;

private TeaRepository $teaRepository;
protected TeaRepository $teaRepository;

public function __construct(Context $context, TeaRepository $teaRepository)
{
Expand Down Expand Up @@ -63,7 +63,7 @@ public function editAction(Tea $tea): ResponseInterface
/**
* @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);
Expand Down
30 changes: 30 additions & 0 deletions Classes/Controller/RatingController.php
Original file line number Diff line number Diff line change
@@ -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)

Check failure on line 16 in Classes/Controller/RatingController.php

View workflow job for this annotation

GitHub Actions / Code quality checks (php:stan, 8.3)

Method TTN\Tea\Controller\RatingController::ratingAction() has no return type specified.

Check failure on line 16 in Classes/Controller/RatingController.php

View workflow job for this annotation

GitHub Actions / Code quality checks (php:stan, 8.3)

Out of 84 possible return types, only 82 - 97.6 % actually have it. Add more return types to get over 100 %
{
$tea->setStars($stars);
$this->teaRepository->update($tea);

return $this->redirect('index','FrontEndEditor');
}

public function filterAction(int $stars)

Check failure on line 24 in Classes/Controller/RatingController.php

View workflow job for this annotation

GitHub Actions / Code quality checks (php:stan, 8.3)

Method TTN\Tea\Controller\RatingController::filterAction() has no return type specified.

Check failure on line 24 in Classes/Controller/RatingController.php

View workflow job for this annotation

GitHub Actions / Code quality checks (php:stan, 8.3)

Out of 84 possible return types, only 82 - 97.6 % actually have it. Add more return types to get over 100 %
{
$this->view->assign('teas', $this->teaRepository->findByStars($stars));
return $this->htmlResponse();
}

}
24 changes: 24 additions & 0 deletions Classes/Domain/Model/Tea.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@
* @phpstan-var FileReference|LazyLoadingProxy|null
* @Extbase\ORM\Lazy
*/
protected $image;

Check failure on line 33 in Classes/Domain/Model/Tea.php

View workflow job for this annotation

GitHub Actions / Code quality checks (php:stan, 8.3)

Out of 24 possible property types, only 22 - 91.6 % actually have it. Add more property types to get over 95 %

/**
* @var int
*/
protected $stars = null;

Check failure on line 38 in Classes/Domain/Model/Tea.php

View workflow job for this annotation

GitHub Actions / Code quality checks (php:stan, 8.3)

Out of 24 possible property types, only 22 - 91.6 % actually have it. Add more property types to get over 95 %

// Note: We cannot use `@var` for the more specific type annotation here as this confuses the Extbase type mapper.

/**
Expand Down Expand Up @@ -90,4 +95,23 @@
{
$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;

Check failure on line 113 in Classes/Domain/Model/Tea.php

View workflow job for this annotation

GitHub Actions / Code quality checks (php:stan, 8.3)

Property TTN\Tea\Domain\Model\Tea::$stars (int) does not accept int|null.
}


}
8 changes: 8 additions & 0 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ static function (): void {
'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;
}
);
14 changes: 12 additions & 2 deletions Configuration/TCA/tx_tea_domain_model_tea.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
'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,',
],
Expand Down Expand Up @@ -203,6 +203,16 @@
'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,
]
],
],
];

Expand Down
24 changes: 24 additions & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
12 changes: 12 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -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>
13 changes: 13 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -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>
11 changes: 11 additions & 0 deletions Resources/Private/Partials/FrontEndEditor/Form.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
41 changes: 41 additions & 0 deletions Resources/Private/Plugins/Rating/Templates/Rating/Filter.html
Original file line number Diff line number Diff line change
@@ -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>
42 changes: 42 additions & 0 deletions Resources/Private/Plugins/Rating/Templates/Tea/Index.html
Original file line number Diff line number Diff line change
@@ -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>
12 changes: 12 additions & 0 deletions Resources/Private/Plugins/Rating/Templates/Tea/Show.html
Original file line number Diff line number Diff line change
@@ -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>
11 changes: 11 additions & 0 deletions Resources/Private/Templates/FrontEndEditor/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ <h2>
<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>
Expand All @@ -46,6 +49,14 @@ <h2>
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>
Expand Down
Loading
Loading