Skip to content
Snippets Groups Projects
Verified Commit f25c9acf authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[BUGFIX] Fix bugs with fetching the related news

parent 346a0ac5
No related branches found
No related tags found
1 merge request!44[BUGFIX] Fix bugs with fetching the related news
......@@ -536,29 +536,40 @@ class NewsRepository extends AbstractRepository {
$constraints[] = $qb->expr()->eq('pid', $news->getPid());
}
if ($limit > 0) {
$qb->setMaxResults($limit);
}
// here we fetch the lastUpdated of the $limit amount of news with newer lastUpdated dates
$result = $qb->select('lastUpdated')
->from('pages')
->from('pages', 'pages')
->where(
$qb->expr()->eq('doktype', $qb->createNamedParameter(News::DOK_TYPE_NEWS, Connection::PARAM_INT)),
$qb->expr()->gt('lastUpdated', $news->getLastUpdated()->getTimestamp()),
$qb->expr()->andX(...$constraints)
)
->setMaxResults($limit)
$qb->expr()->gt('lastUpdated', $news->getLastUpdated()->getTimestamp())
)->andWhere(...$constraints)
->orderBy('lastUpdated', 'desc')
->execute();
$newest = $result->fetchOne();
// Here we fetch the lastUpdated of the $limit amount of news with older lastUpdated dates
$result = $qb->orderBy('lastUpdated', 'asc')->execute();
$result = $qb->where(
$qb->expr()->eq('doktype', $qb->createNamedParameter(News::DOK_TYPE_NEWS, Connection::PARAM_INT)),
$qb->expr()->lt('lastUpdated', $news->getLastUpdated()->getTimestamp())
)->andWhere(...$constraints)
->orderBy('lastUpdated', 'asc')
->execute();
$oldest = $result->fetchOne();
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
$query->setOrderings([
'crdate' => QueryInterface::ORDER_DESCENDING
'lastUpdated' => QueryInterface::ORDER_DESCENDING
]);
$constraints = [];
$constraints = [
$query->logicalNot(
$query->equals('uid', $news->getUid())
)
];
if ($newest) {
$constraints[] = $query->lessThanOrEqual('lastUpdated', $newest);
}
......
......@@ -47,7 +47,7 @@ class RelatedViewHelper extends AbstractViewHelper {
$templateVariableContainer = $renderingContext->getVariableProvider();
$news = $arguments['news'];
$newsRepository = GeneralUtility::makeInstance(NewsRepository::class);
$related = $newsRepository->findRelated($news);
$related = $newsRepository->findRelated($news, (int) $arguments['limit']);
if (isset($arguments['iteration'])) {
$iterationData = [
'index' => 0,
......
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