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