Skip to content
Snippets Groups Projects
Commit 4bc2da8a authored by Michael Kessler's avatar Michael Kessler
Browse files

[BUGFIX] Fix NewsByAuthors crashing when multiple authors are given

parent b401960d
No related branches found
No related tags found
1 merge request!26[BUGFIX] Fix NewsByAuthors crashing when multiple authors are given
......@@ -79,25 +79,28 @@ class NewsByAuthorController extends AbstractController {
$categories = $newsMetaData = [];
$categoryRepository = $this->objectManager->get(CategoryRepository::class);
$excludedNewsIds = GeneralUtility::intExplode(',', $this->settings['excludedNews']);
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
if (in_array($newsEntry->getUid(), $excludedNewsIds, TRUE)) {
continue;
}
$categoryId = $newsEntry->getPid();
if (!isset($categories[$categoryId])) {
$category = $categoryRepository->findByUid($categoryId);
if (!$category) {
foreach ($news as $newsResult) {
foreach ($newsResult as $newsEntry) {
/** @var News $newsEntry */
if (in_array($newsEntry->getUid(), $excludedNewsIds, TRUE)) {
continue;
}
$categories[$categoryId] = $category;
}
$categoryId = $newsEntry->getPid();
if (!isset($categories[$categoryId])) {
$category = $categoryRepository->findByUid($categoryId);
if (!$category) {
continue;
}
$newsMetaData[] = $this->getMetaDataForNews($newsEntry, $categories[$categoryId]);
$categories[$categoryId] = $category;
}
$newsMetaData[] = $this->getMetaDataForNews($newsEntry, $categories[$categoryId]);
}
}
$this->view->assign('newsMetaData', $newsMetaData);
$this->view->assign('authors', $authors);
}
......
......@@ -40,17 +40,32 @@ class NewsRepository extends AbstractRepository {
* Finds all news by the given authors.
*
* @param array $authorIds
*
* @return QueryResultInterface|NULL
* @return array Contains only TYPO3\CMS\Extbase\Persistence\Generic\QueryResult items
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function findAllByNewsAuthor(array $authorIds): ?QueryResultInterface {
public function findAllByNewsAuthor(array $authorIds): ?array {
if (count($authorIds) <= 0) {
return NULL;
}
$result = [];
foreach ($authorIds as $authorId) {
$result[] = $this->findNewsByAuthor($authorId);
}
return $result;
}
/**
* Find all news by the given author
*
* @param int $authorId
* @return QueryResultInterface|null
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function findNewsByAuthor(int $authorId): ?QueryResultInterface {
$query = $this->createQuery();
$query->matching($query->contains('newsAuthor', $authorIds));
$query->matching($query->contains('newsAuthor', $authorId));
return $query->execute();
}
......
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