Skip to content
Snippets Groups Projects
Commit 862327a7 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

Merge branch 'feature_date-filterset-for-FE-plugins' into 'master'

[TASK] Added date filtersets for all FE plugins

See merge request !3
parents 0a74bca8 140c1cd3
No related branches found
No related tags found
1 merge request!3[TASK] Added date filtersets for all FE plugins
......@@ -70,8 +70,10 @@ class LatestController extends AbstractController {
$categoryUids = [$GLOBALS['TSFE']->id];
}
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$latestNewsEntries = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories(
$limit, FALSE, $categoryUids, $offset, TRUE, $this->settings['sortBy'], $tagUids
$limit, FALSE, $categoryUids, $offset, TRUE, $this->settings['sortBy'], $tagUids, $startTime, $endTime
);
$categories = [];
......@@ -99,7 +101,7 @@ class LatestController extends AbstractController {
if (count($newsMetaData) < $limit) {
$offset += $limit;
$maxCount = $this->newsRepository->getCountOfLastUpdatedOrHighlightedNewsByCategories(
FALSE, $categoryUids, TRUE, $this->settings['sortBy'], $tagUids
FALSE, $categoryUids, TRUE, $this->settings['sortBy'], $tagUids, $startTime, $endTime
);
if ($offset < $maxCount) {
$this->indexAction($newsMetaData, $offset);
......
......@@ -79,18 +79,21 @@ class ListByCategoryController extends AbstractController {
$categories[$categoryUid] = $this->categoryRepository->findByUid($categoryUid);
}
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$offset = 0;
$newsPerPage = (int) $this->settings['newsLimitPerPage'];
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
if ($currentPageBrowserPage && $newsPerPage) {
$offset = $currentPageBrowserPage * $newsPerPage;
}
$newsCount = $this->newsRepository->newsCountByCategories($categoryUids, $tagUids);
$newsCount = $this->newsRepository->newsCountByCategories($categoryUids, $tagUids, $startTime, $endTime);
$numberOfPages = ($newsPerPage <= 0 ? 0 : ceil($newsCount / $newsPerPage));
$headerSet = FALSE;
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryUids, $newsPerPage, $offset, $this->settings['sortBy'], $tagUids
$categoryUids, $newsPerPage, $offset, $this->settings['sortBy'], $tagUids, $startTime, $endTime
)->toArray();
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
......
......@@ -42,10 +42,15 @@ class NewsFeedController extends AbstractController {
* Renders the news feed
*
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function indexAction() {
$categories = GeneralUtility::intExplode(',', $this->settings['showCategories'], TRUE);
$news = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories(10, FALSE, $categories);
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$news = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories(
10, FALSE, $categories, 0, FALSE, 'date', NULL, $startTime, $endTime
);
$this->view->assign('news', $news);
}
}
......@@ -85,10 +85,13 @@ class OverviewController extends AbstractController {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
protected function highlightBestFitNews(array $categoryIds = NULL, array $tagIds = NULL) {
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
/** @var News $highlightedNews */
$highlightedNews = $this->newsRepository
->findLastUpdatedOrHighlightedNewsByCategories(
1, FALSE, $categoryIds, 0, FALSE, $this->settings['sortBy'], $tagIds
1, FALSE, $categoryIds, 0, FALSE, $this->settings['sortBy'], $tagIds, $startTime, $endTime
)->getFirst();
if (!$highlightedNews) {
return;
......@@ -133,6 +136,9 @@ class OverviewController extends AbstractController {
$categories = $this->categoryRepository->findAll();
}
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$categoryIds = [];
$categoriesById = [];
$newsMetaData = [];
......@@ -143,8 +149,9 @@ class OverviewController extends AbstractController {
$categoriesById[$categoryId] = $category;
$news = $this->newsRepository->findAllSortedNewsByCategories(
[$categoryId], $newsLimitPerCategory, $offset, $this->settings['sortBy']
[$categoryId], $newsLimitPerCategory, $offset, $this->settings['sortBy'], NULL, $startTime, $endTime
);
$newsMetaData[$categoryId] = [];
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
$categoryId = $newsEntry->getPid();
......@@ -162,7 +169,7 @@ class OverviewController extends AbstractController {
$maxNewsPerCategory = 0;
foreach ($categoriesById as $categoryId => $category) {
/** @var $category Category */
if (isset($newsByTag[$categoryId])) {
if (isset($newsByCategory[$categoryId])) {
/** @var $category Category */
$newsByCategory[$categoryId]['newsMetaData'] =
array_merge($newsByCategory[$categoryId]['newsMetaData'], $newsMetaData[$categoryId]);
......@@ -175,12 +182,13 @@ class OverviewController extends AbstractController {
];
}
$maxNewsPerCategory = max($newsByCategory, count($newsByTag[$categoryId]['newsMetaData']));
$maxNewsPerCategory = max($maxNewsPerCategory, count($newsByCategory[$categoryId]['newsMetaData']));
}
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsLimitPerCategory, $offset, $this->settings['sortBy']
$categoryIds, $newsLimitPerCategory, $offset, $this->settings['sortBy'], NULL, $startTime, $endTime
);
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
$categoryId = $newsEntry->getPid();
......@@ -196,7 +204,7 @@ class OverviewController extends AbstractController {
$this->highlightBestFitNews($categoryIds);
$newsCount = $this->newsRepository->newsCountByCategories($categoryIds);
$newsCount = $this->newsRepository->newsCountByCategories($categoryIds, NULL, $startTime, $endTime);
$numberOfPages = ($newsLimitPerCategory <= 0 ? 0 : ceil($newsCount / $newsLimitPerCategory));
// Redo this function, until one variable get the amount of newsLimitPerTag. Reduces the amount of ajax calls. Needed because of languagevisibility.
if ($maxNewsPerCategory < $newsLimitPerCategory && count($allNews) < $newsLimitPerCategory) {
......@@ -243,6 +251,9 @@ class OverviewController extends AbstractController {
$tags = $this->tagRepository->findAll();
}
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$tagIds = [];
$tagsById = [];
$categoriesById = [];
......@@ -254,8 +265,9 @@ class OverviewController extends AbstractController {
$tagsById[$tagId] = $tag;
$news = $this->newsRepository->findAllSortedNewsByCategories(
NULL, $newsLimitPerTag, $offset, $this->settings['sortBy'], [$tagId]
NULL, $newsLimitPerTag, $offset, $this->settings['sortBy'], [$tagId], $startTime, $endTime
);
$newsMetaData[$tagId] = [];
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
$categoryId = $newsEntry->getPid();
......@@ -281,11 +293,9 @@ class OverviewController extends AbstractController {
}
if (isset($newsByTag[$tagId])) {
/** @var $category Category */
$newsByTag[$tagId]['newsMetaData'] =
array_merge($newsByTag[$tagId]['newsMetaData'], $newsMetaData[$tagId]);
} else {
/** @var $category Category */
$newsByTag[$tagId] = [
'record' => $tag,
'recordId' => $tagId,
......@@ -298,7 +308,7 @@ class OverviewController extends AbstractController {
}
$news = $this->newsRepository->findAllSortedNewsByCategories(
NULL, $newsLimitPerTag, $offset, $this->settings['sortBy'], $tagIds
NULL, $newsLimitPerTag, $offset, $this->settings['sortBy'], $tagIds, $startTime, $endTime
);
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
......@@ -318,7 +328,7 @@ class OverviewController extends AbstractController {
$this->highlightBestFitNews([], $tagIds);
$newsCount = $this->newsRepository->newsCountByCategories([], $tagIds);
$newsCount = $this->newsRepository->newsCountByCategories([], $tagIds, $startTime, $endTime);
$numberOfPages = ($newsLimitPerTag <= 0 ? 0 : ceil($newsCount / $newsLimitPerTag));
// Redo this function, until one variable get the amount of newsLimitPerTag. Reduces the amount of ajax calls. Needed because of languagevisibility.
if ($maxNewsPerTag < $newsLimitPerTag && count($allNews) < $newsLimitPerTag) {
......@@ -351,6 +361,9 @@ class OverviewController extends AbstractController {
$offset = ($currentPageBrowserPage * $newsPerPage) - 1;
}
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
if ($this->settings['onlyNewsWithinThisPageSection']) {
/** @noinspection PhpUndefinedMethodInspection */
$categories = $this->categoryRepository->findByPid($GLOBALS['TSFE']->id);
......@@ -365,9 +378,9 @@ class OverviewController extends AbstractController {
$categoriesById[$categoryId] = $category;
}
$newsCount = $this->newsRepository->newsCountByCategories($categoryIds);
$newsCount = $this->newsRepository->newsCountByCategories($categoryIds, NULL, $startTime, $endTime);
} else {
$newsCount = $this->newsRepository->countAll();
$newsCount = $this->newsRepository->countAll($startTime, $endTime);
$categoryIds = NULL;
$categoriesById = [];
......@@ -379,7 +392,7 @@ class OverviewController extends AbstractController {
}
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsPerPage, $offset, $this->settings['sortBy']
$categoryIds, $newsPerPage, $offset, $this->settings['sortBy'], NULL, $startTime, $endTime
);
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
......
......@@ -90,8 +90,8 @@ class PageBrowserController extends ActionController {
$this->numberOfPages = (int) $this->settings['numberOfPages'];
$this->pagesBefore = (int) $this->settings['pagesBefore'];
$this->pagesAfter = (int) $this->settings['pagesAfter'];
$this->enableMorePages = ($this->settings['enableMorePages'] == TRUE);
$this->enableLessPages = ($this->settings['enableLessPages'] == TRUE);
$this->enableMorePages = (bool) $this->settings['enableMorePages'];
$this->enableLessPages = (bool) $this->settings['enableLessPages'];
}
/**
......
......@@ -43,11 +43,14 @@ class NewsRepository extends AbstractRepository {
* @param int $offset
* @param string $sortBy date or positionInTree
* @param array $tagIds NULL, if the tag filter isn't applied, otherwise an array with the tag uids.
* @param int $startTime unix timestamp of the lower limit of the news results date
* @param int $endTime unix timestamp of the upper limit of the news results date
* @return QueryResultInterface
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function findAllSortedNewsByCategories(
array $categoryIds = NULL, $limit = 0, $offset = 0, $sortBy = 'date', array $tagIds = NULL
array $categoryIds = NULL, $limit = 0, $offset = 0, $sortBy = 'date', array $tagIds = NULL,
$startTime = 0, $endTime = 0
) {
$query = $this->createQuery();
......@@ -70,6 +73,18 @@ class NewsRepository extends AbstractRepository {
}
}
$startTime = (int) $startTime;
if ($startTime) {
$startTimeObject = \DateTime::createFromFormat('U', (string) $startTime);
$constraints[] = $query->greaterThanOrEqual('lastUpdated', $startTimeObject);
}
$endTime = (int) $endTime;
if ($endTime) {
$endTimeObject = \DateTime::createFromFormat('U', (string) $endTime);
$constraints[] = $query->lessThanOrEqual('lastUpdated', $endTimeObject);
}
if (count($constraints)) {
$query->matching($query->logicalAnd($constraints));
}
......@@ -107,10 +122,14 @@ class NewsRepository extends AbstractRepository {
*
* @param array $categoryIds NULL, if the category filter isn't applied, otherwise an array with the categories uid.
* @param array $tagIds NULL, if the tag filter isn't applied, otherwise an array with the tag uids.
* @param int $startTime unix timestamp of the lower limit of the news results date
* @param int $endTime unix timestamp of the upper limit of the news results date
* @return int
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function newsCountByCategories(array $categoryIds = NULL, array $tagIds = NULL) {
public function newsCountByCategories(
array $categoryIds = NULL, array $tagIds = NULL, $startTime = 0, $endTime = 0
) {
$query = $this->createQuery();
$constraints = [];
......@@ -133,8 +152,22 @@ class NewsRepository extends AbstractRepository {
}
}
$startTime = (int) $startTime;
if ($startTime) {
$startTimeObject = \DateTime::createFromFormat('U', (string) $startTime);
$constraints[] = $query->greaterThanOrEqual('lastUpdated', $startTimeObject);
}
$endTime = (int) $endTime;
if ($endTime) {
$endTimeObject = \DateTime::createFromFormat('U', (string) $endTime);
$constraints[] = $query->lessThanOrEqual('lastUpdated', $endTimeObject);
}
if (count($constraints) > 1) {
$query->matching($query->logicalAnd($constraints));
} elseif (count($constraints) === 1) {
$query->matching($constraints[0]);
}
return $query->count();
}
......@@ -149,15 +182,19 @@ class NewsRepository extends AbstractRepository {
* @param bool $hideNeverHighlightedNews
* @param string $sortBy date or positionInTree
* @param array $tagIds NULL, if the tag filter isn't applied, otherwise an array with the tag uids.
* @param int $startTime unix timestamp of the lower limit of the news results date
* @param int $endTime unix timestamp of the upper limit of the news results date
* @return QueryResultInterface
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function findLastUpdatedOrHighlightedNewsByCategories(
$limit = 1, $onlyHighlighted = FALSE, array $categoryIds = NULL,
$offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date', array $tagIds = NULL
$offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date', array $tagIds = NULL,
$startTime = 0, $endTime = 0
) {
return $this->getQueryForLastUpdatedOrHighlightedNewsByCategories(
$limit, $onlyHighlighted, $categoryIds, $offset, $hideNeverHighlightedNews, $sortBy, $tagIds
$limit, $onlyHighlighted, $categoryIds, $offset, $hideNeverHighlightedNews, $sortBy, $tagIds,
$startTime, $endTime
)->execute();
}
......@@ -166,19 +203,20 @@ class NewsRepository extends AbstractRepository {
*
* @param bool $onlyHighlighted
* @param array $categoryIds NULL, if the category filter isn't applied, otherwise an array with the categories uid.
* @param int $offset
* @param bool $hideNeverHighlightedNews
* @param string $sortBy date or positionInTree
* @param array $tagIds NULL, if the tag filter isn't applied, otherwise an array with the tag uids.
* @param int $startTime unix timestamp of the lower limit of the news results date
* @param int $endTime unix timestamp of the upper limit of the news results date
* @return int
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function getCountOfLastUpdatedOrHighlightedNewsByCategories(
$onlyHighlighted = FALSE, array $categoryIds = NULL, $hideNeverHighlightedNews = FALSE, $sortBy = 'date',
array $tagIds = NULL
array $tagIds = NULL, $startTime = 0, $endTime = 0
) {
return $this->getQueryForLastUpdatedOrHighlightedNewsByCategories(
0, $onlyHighlighted, $categoryIds, 0, $hideNeverHighlightedNews, $sortBy, $tagIds
0, $onlyHighlighted, $categoryIds, 0, $hideNeverHighlightedNews, $sortBy, $tagIds, $startTime, $endTime
)->count();
}
......@@ -192,12 +230,15 @@ class NewsRepository extends AbstractRepository {
* @param bool $hideNeverHighlightedNews
* @param string $sortBy date or positionInTree
* @param array $tagIds NULL, if the tag filter isn't applied, otherwise an array with the tag uids.
* @param int $startTime unix timestamp of the lower limit of the news results date
* @param int $endTime unix timestamp of the upper limit of the news results date
* @return QueryInterface
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
protected function getQueryForLastUpdatedOrHighlightedNewsByCategories(
$limit = 1, $onlyHighlighted = FALSE, array $categoryIds = NULL,
$offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date', array $tagIds = NULL
$offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date', array $tagIds = NULL,
$startTime = 0, $endTime = 0
) {
$query = $this->createQuery();
$constraints = NULL;
......@@ -227,6 +268,18 @@ class NewsRepository extends AbstractRepository {
$constraints[] = $query->equals('tx_sgnews_never_highlighted', 0);
}
$startTime = (int) $startTime;
if ($startTime) {
$startTimeObject = \DateTime::createFromFormat('U', (string) $startTime);
$constraints[] = $query->greaterThanOrEqual('lastUpdated', $startTimeObject);
}
$endTime = (int) $endTime;
if ($endTime) {
$endTimeObject = \DateTime::createFromFormat('U', (string) $endTime);
$constraints[] = $query->lessThanOrEqual('lastUpdated', $endTimeObject);
}
if ($sortBy === 'date') {
$query->setOrderings(
[
......@@ -331,4 +384,74 @@ class NewsRepository extends AbstractRepository {
/** @noinspection PhpUndefinedMethodInspection */
return $query->statement($statement)->execute();
}
/**
* Returns all news.
*
* @param int $startTime unix timestamp of the lower limit of the news results date
* @param int $endTime unix timestamp of the upper limit of the news results date
* @return QueryResultInterface|array
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @api
*/
public function findAll($startTime = 0, $endTime = 0)
{
$query = $this->createQuery();
$constraints = [];
$startTime = (int) $startTime;
if ($startTime) {
$startTimeObject = \DateTime::createFromFormat('U', (string) $startTime);
$constraints[] = $query->greaterThanOrEqual('lastUpdated', $startTimeObject);
}
$endTime = (int) $endTime;
if ($endTime) {
$endTimeObject = \DateTime::createFromFormat('U', (string) $endTime);
$constraints[] = $query->lessThanOrEqual('lastUpdated', $endTimeObject);
}
if (count($constraints) > 1) {
$query->matching($query->logicalAnd($constraints));
} elseif (count($constraints) === 1) {
$query->matching($constraints[0]);
}
return $query->execute();
}
/**
* Returns the total number of news.
*
* @param int $startTime unix timestamp of the lower limit of the news results date
* @param int $endTime unix timestamp of the upper limit of the news results date
* @return int The news count
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @api
*/
public function countAll($startTime = 0, $endTime = 0)
{
$query = $this->createQuery();
$constraints = [];
$startTime = (int) $startTime;
if ($startTime) {
$startTimeObject = \DateTime::createFromFormat('U', (string) $startTime);
$constraints[] = $query->greaterThanOrEqual('lastUpdated', $startTimeObject);
}
$endTime = (int) $endTime;
if ($endTime) {
$endTimeObject = \DateTime::createFromFormat('U', (string) $endTime);
$constraints[] = $query->lessThanOrEqual('lastUpdated', $endTimeObject);
}
if (count($constraints) > 1) {
$query->matching($query->logicalAnd($constraints));
} elseif (count($constraints) === 1) {
$query->matching($constraints[0]);
}
return $query->count();
}
}
......@@ -58,6 +58,28 @@
</config>
</TCEforms>
</settings.tags>
<settings.starttime>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.starttime</label>
<config>
<type>input</type>
<size>12</size>
<eval>datetime</eval>
</config>
</TCEforms>
</settings.starttime>
<settings.endtime>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.endtime</label>
<config>
<type>input</type>
<size>12</size>
<eval>datetime</eval>
</config>
</TCEforms>
</settings.endtime>
</el>
</ROOT>
</main>
......
......@@ -58,6 +58,28 @@
</config>
</TCEforms>
</settings.tags>
<settings.starttime>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.starttime</label>
<config>
<type>input</type>
<size>12</size>
<eval>datetime</eval>
</config>
</TCEforms>
</settings.starttime>
<settings.endtime>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.endtime</label>
<config>
<type>input</type>
<size>12</size>
<eval>datetime</eval>
</config>
</TCEforms>
</settings.endtime>
</el>
</ROOT>
</main>
......
......@@ -53,6 +53,26 @@
</config>
</TCEforms>
</settings.onlyNewsWithinThisPageSection>
<settings.starttime>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.starttime</label>
<config>
<type>input</type>
<size>12</size>
<eval>datetime</eval>
</config>
</TCEforms>
</settings.starttime>
<settings.endtime>
<TCEforms>
<label>LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.endtime</label>
<config>
<type>input</type>
<size>12</size>
<eval>datetime</eval>
</config>
</TCEforms>
</settings.endtime>
</el>
</ROOT>
</main>
......
......@@ -101,6 +101,14 @@
<source>Tags, if none is selected, then all will be displayed</source>
<target>Tags, wenn keine ausgewählt wird, dann werden alle angezeigt</target>
</trans-unit>
<trans-unit id="plugin.overview.flexForm.starttime">
<source>Show news from</source>
<target>Zeige News ab</target>
</trans-unit>
<trans-unit id="plugin.overview.flexForm.endtime">
<source>Show news until</source>
<target>Zeige News bis</target>
</trans-unit>
</body>
</file>
</xliff>
......@@ -78,6 +78,12 @@
<trans-unit id="plugin.overview.flexForm.listByCategory.tags">
<source>Tags, if none is selected, then all will be displayed</source>
</trans-unit>
<trans-unit id="plugin.overview.flexForm.starttime">
<source>Show news from</source>
</trans-unit>
<trans-unit id="plugin.overview.flexForm.endtime">
<source>Show news until</source>
</trans-unit>
</body>
</file>
</xliff>
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