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