Skip to content
Snippets Groups Projects
Commit 29658e49 authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[FEATURE] refactor configuration fetch; respect TS settings; provide

flexform config for all plugins
parent 1da95561
No related branches found
No related tags found
1 merge request!7[FEATURE] make sorting more configurable
......@@ -28,6 +28,7 @@ namespace SGalinski\SgNews\Controller;
use SGalinski\SgNews\Domain\Model\Category;
use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Service\ConfigurationService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -60,11 +61,15 @@ class LatestController extends AbstractController {
* @return void
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
public function indexAction(array $newsMetaData = [], $offset = 0) {
$limit = ((int) $this->settings['limit']);
$limit = ($limit < 1 ? 1 : $limit);
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$sortBy = $configurationService->getConfiguration('sortBy', $this->settings);
$categoryUids = GeneralUtility::intExplode(',', $this->settings['categories'], TRUE);
$tagUids = GeneralUtility::intExplode(',', $this->settings['tags'], TRUE);
if ((int) $GLOBALS['TSFE']->page['doktype'] === 117 && !count($categoryUids)) {
......@@ -74,7 +79,7 @@ class LatestController extends AbstractController {
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$latestNewsEntries = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories(
$limit, FALSE, $categoryUids, $offset, TRUE, $this->settings['sortBy'], $tagUids, $startTime, $endTime
$limit, FALSE, $categoryUids, $offset, TRUE, $sortBy, $tagUids, $startTime, $endTime
);
$categories = [];
......@@ -102,7 +107,7 @@ class LatestController extends AbstractController {
if (count($newsMetaData) < $limit) {
$offset += $limit;
$maxCount = $this->newsRepository->getCountOfLastUpdatedOrHighlightedNewsByCategories(
FALSE, $categoryUids, TRUE, $this->settings['sortBy'], $tagUids, $startTime, $endTime
FALSE, $categoryUids, TRUE, $sortBy, $tagUids, $startTime, $endTime
);
if ($offset < $maxCount) {
$this->indexAction($newsMetaData, $offset);
......
......@@ -27,8 +27,10 @@ namespace SGalinski\SgNews\Controller;
***************************************************************/
use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Service\ConfigurationService;
use SGalinski\SgNews\Service\HeaderMetaDataService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
/**
* Controller that handles the list rendering of a single category
......@@ -72,6 +74,7 @@ class ListByCategoryController extends AbstractController {
* @return void
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
public function indexAction(array $newsMetaData = [], $currentPageBrowserPage = 0) {
$filterByCategories = FALSE;
......@@ -104,9 +107,14 @@ class ListByCategoryController extends AbstractController {
$headerSet = FALSE;
$offset = $this->calculatePaginationOffset($currentPageBrowserPage, $newsPerPage);
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$sortBy = $configurationService->getConfiguration('sortBy', $this->settings);
$sortDirection = $configurationService->getConfiguration('sortDirection', $this->settings);
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryUids, $newsPerPage, $offset, $this->settings['sortBy'], $tagUids, $startTime, $endTime, $this->settings['sortDirection']
$categoryUids, $newsPerPage, $offset, $sortBy, $tagUids, $startTime, $endTime, $sortDirection
)->toArray();
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
$data = $this->getMetaDataForNews($newsEntry, $categories[$newsEntry->getPid()]);
......
......@@ -29,6 +29,7 @@ namespace SGalinski\SgNews\Controller;
use SGalinski\SgNews\Domain\Model\Category;
use SGalinski\SgNews\Domain\Model\Tag;
use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Service\ConfigurationService;
use SGalinski\SgNews\Service\HeaderMetaDataService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Query;
......@@ -78,6 +79,7 @@ class OverviewController extends AbstractController {
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
public function overviewAction(array $newsFilter = [], $currentPageBrowserPage = 0) {
switch ((int) $this->settings['groupBy']) {
......@@ -138,6 +140,7 @@ class OverviewController extends AbstractController {
* @return void
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
protected function overviewWithCategories(
array $newsByCategory = [], array $allNews = [], array $newsFilter = [], $currentPageBrowserPage = 0
......@@ -157,6 +160,10 @@ class OverviewController extends AbstractController {
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$sortBy = $configurationService->getConfiguration('sortBy', $this->settings);
$sortDirection = $configurationService->getConfiguration('sortDirection', $this->settings);
$categoryIds = [];
$categoriesById = [];
$newsMetaData = [];
......@@ -171,7 +178,7 @@ class OverviewController extends AbstractController {
$tagIds = [(int) $newsFilter['tag']];
}
$news = $this->newsRepository->findAllSortedNewsByCategories(
[$categoryId], $newsLimitPerCategory, $offset, $this->settings['sortBy'], $tagIds, $startTime, $endTime
[$categoryId], $newsLimitPerCategory, $offset, $sortBy, $tagIds, $startTime, $endTime, $sortDirection
);
$newsMetaData[$categoryId] = [];
foreach ($news as $newsEntry) {
......@@ -218,7 +225,7 @@ class OverviewController extends AbstractController {
$tagIds = [(int) $newsFilter['tag']];
}
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsLimitPerCategory, $offset, $this->settings['sortBy'], $tagIds, $startTime, $endTime
$categoryIds, $newsLimitPerCategory, $offset, $sortBy, $tagIds, $startTime, $endTime, $sortDirection
);
foreach ($news as $newsEntry) {
......@@ -279,6 +286,7 @@ class OverviewController extends AbstractController {
* @return void
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
protected function overviewWithTags(
array $newsByTag = [], array $allNews = [], array $newsFilter = [], $currentPageBrowserPage = 0
......@@ -292,6 +300,10 @@ class OverviewController extends AbstractController {
$tagPid = $GLOBALS['TSFE']->id;
}
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$sortBy = $configurationService->getConfiguration('sortBy', $this->settings);
$sortDirection = $configurationService->getConfiguration('sortDirection', $this->settings);
$categoryIds = NULL;
if ($newsFilter['category']) {
$categoryIds = [(int) $newsFilter['category']];
......@@ -317,7 +329,7 @@ class OverviewController extends AbstractController {
$tagsById[$tagId] = $tag;
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsLimitPerTag, $offset, $this->settings['sortBy'], [$tagId], $startTime, $endTime
$categoryIds, $newsLimitPerTag, $offset, $sortBy, [$tagId], $startTime, $endTime, $sortDirection
);
$newsMetaData[$tagId] = [];
foreach ($news as $newsEntry) {
......@@ -362,7 +374,7 @@ class OverviewController extends AbstractController {
// Get all news by tags.
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsLimitPerTag, $offset, $this->settings['sortBy'], $tagIds, $startTime, $endTime
$categoryIds, $newsLimitPerTag, $offset, $sortBy, $tagIds, $startTime, $endTime, $sortDirection
);
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
......@@ -435,6 +447,7 @@ class OverviewController extends AbstractController {
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
protected function overviewWithoutCategoriesAction(
array $newsMetaData = [], array $newsFilter = NULL, $currentPageBrowserPage = 0
......@@ -445,6 +458,10 @@ class OverviewController extends AbstractController {
$this->view->assign('selectedTag', $selectedTag);
$this->view->assign('selectedCategory', $selectedCategory);
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$sortBy = $configurationService->getConfiguration('sortBy', $this->settings);
$sortDirection = $configurationService->getConfiguration('sortDirection', $this->settings);
$newsPerPage = (int) $this->settings['newsLimit'];
$offset = $this->calculatePaginationOffset($currentPageBrowserPage, $newsPerPage);
......@@ -496,7 +513,7 @@ class OverviewController extends AbstractController {
}
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsPerPage, $offset, $this->settings['sortBy'], $tagIds, $startTime, $endTime
$categoryIds, $newsPerPage, $offset, $sortBy, $tagIds, $startTime, $endTime, $sortDirection
);
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
......
......@@ -115,8 +115,8 @@ class NewsRepository extends AbstractRepository {
$query->setOrderings(
[
'sorting' => $order,
'lastUpdated' => $order,
'crdate' => $order,
'lastUpdated' => QueryInterface::ORDER_DESCENDING,
'crdate' => QueryInterface::ORDER_DESCENDING,
]
);
}
......
<?php
namespace SGalinski\SgNews\Service;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
/**
* This service provides helper function for dealing with plugin configuration
*/
class ConfigurationService implements SingletonInterface {
/**
* @var array
*/
protected $tsConfig;
/**
* Returns the desired config value either from TypoScript settings or flexform config
* If the user set 'System default' in the flexform, the value will be fetched from TS
*
* @param string $key
* @param array $settings
* @throws InvalidConfigurationTypeException
* @return string
*/
public function getConfiguration($key, $settings): string {
if (!$this->tsConfig) {
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$this->tsConfig = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
}
if ($settings[$key] === 'typoscript') {
return $this->tsConfig['plugin.']['tx_sgnews.']['settings.'][$key];
}
return $settings[$key];
}
}
......@@ -79,6 +79,29 @@
</config>
</TCEforms>
</settings.endtime>
<settings.sortBy>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.sortBy</label>
<config>
<type>select</type>
<items>
<numIndex index="0">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.systemDefault</numIndex>
<numIndex index="1">typoscript</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.dateOfPublication</numIndex>
<numIndex index="1">date</numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.orderInPageTree</numIndex>
<numIndex index="1">positionInTree</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.sortBy>
</el>
</ROOT>
</main>
......
......@@ -87,10 +87,14 @@
<type>select</type>
<items>
<numIndex index="0">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.systemDefault</numIndex>
<numIndex index="1">typoscript</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.dateOfPublication</numIndex>
<numIndex index="1">date</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="2">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.orderInPageTree</numIndex>
<numIndex index="1">positionInTree</numIndex>
</numIndex>
......@@ -106,10 +110,14 @@
<type>select</type>
<items>
<numIndex index="0">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.systemDefault</numIndex>
<numIndex index="1">typoscript</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.desc</numIndex>
<numIndex index="1">DESC</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="2">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.asc</numIndex>
<numIndex index="1">ASC</numIndex>
</numIndex>
......
......@@ -82,6 +82,50 @@
</config>
</TCEforms>
</settings.endtime>
<settings.sortBy>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.sortBy</label>
<config>
<type>select</type>
<items>
<numIndex index="0">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.systemDefault</numIndex>
<numIndex index="1">typoscript</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.dateOfPublication</numIndex>
<numIndex index="1">date</numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.orderInPageTree</numIndex>
<numIndex index="1">positionInTree</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.sortBy>
<settings.sortDirection>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.sortOrder</label>
<config>
<type>select</type>
<items>
<numIndex index="0">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.systemDefault</numIndex>
<numIndex index="1">typoscript</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.desc</numIndex>
<numIndex index="1">DESC</numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.listByCategory.flexFrom.asc</numIndex>
<numIndex index="1">ASC</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.sortDirection>
</el>
</ROOT>
</main>
......
......@@ -89,6 +89,10 @@
<source><![CDATA[Sort order]]></source>
<target><![CDATA[Sortierreihenfolge]]></target>
</trans-unit>
<trans-unit id="plugin.listByCategory.flexFrom.systemDefault" approved="yes">
<source><![CDATA[System default]]></source>
<target><![CDATA[Systemstandard]]></target>
</trans-unit>
<trans-unit id="plugin.overview.flexForm.categories" approved="yes">
<source><![CDATA[Categories (No Selection = all)]]></source>
<target><![CDATA[Kategorien (Keine Auswahl = alle)]]></target>
......
......@@ -69,6 +69,9 @@
<trans-unit id="plugin.listByCategory.flexFrom.sortOrder">
<source><![CDATA[Sort order]]></source>
</trans-unit>
<trans-unit id="plugin.listByCategory.flexFrom.systemDefault">
<source><![CDATA[System default]]></source>
</trans-unit>
<trans-unit id="plugin.overview.flexForm.categories">
<source><![CDATA[Categories (No Selection = all)]]></source>
</trans-unit>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment