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

[TASK] Add a limit and ordering to automatic related news

parent 2ac0611e
No related branches found
No related tags found
1 merge request!41[TASK] Add related news by tag or category
......@@ -203,7 +203,7 @@ class News extends CategoryAndNews {
$settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
if ($settings['automaticRelatedNews'] && !$this->_isNew() && $this->relatedNews->count() === 0) {
$newsRepository = GeneralUtility::makeInstance(NewsRepository::class);
$this->relatedNews = $newsRepository->findRelated($this);
$this->relatedNews = $newsRepository->findRelated($this, $settings['limitRelatedNews']);
}
return $this->relatedNews;
......
......@@ -510,11 +510,15 @@ class NewsRepository extends AbstractRepository {
* This method finds news related by Tag or Category to the given news record
*
* @param News $news The news to find related news to
* @param int $limit Limit the amount of related news
* @return QueryResultInterface
*/
public function findRelated(News $news) {
public function findRelated(News $news, int $limit = 0) {
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
$query->setOrderings([
'crdate' => QueryInterface::ORDER_DESCENDING
]);
$contains = [];
$tags = $news->getTags();
if ($tags->count() > 0) {
......@@ -528,6 +532,10 @@ class NewsRepository extends AbstractRepository {
$query->matching(
$contains
);
if ($limit > 0) {
$query->setLimit($limit);
}
return $query->execute();
}
}
......@@ -22,5 +22,8 @@ plugin.tx_sgnews {
# Enable fetching of related news by tag or category, if related news are not set manually
automaticRelatedNews = 1
# Set a limit for fetched related news (for no limit, set to 0)
limitRelatedNews = 5
}
}
......@@ -112,6 +112,9 @@ plugin.tx_sgnews {
# Enable fetching of related news by tag or category, if related news are not set manually
automaticRelatedNews = {$plugin.tx_sgnews.settings.automaticRelatedNews}
# Set a limit for fetched related news (for no limit, set to 0)
limitRelatedNews = {$plugin.tx_sgnews.settings.limitRelatedNews}
}
features {
......
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