diff --git a/Classes/Controller/ListByCategoryController.php b/Classes/Controller/ListByCategoryController.php index 48a1997b8cc37cef9408e96b3d5719f76aa9cc5e..f962dfd36f09075cd94ff0f558be3fa0750dd886 100644 --- a/Classes/Controller/ListByCategoryController.php +++ b/Classes/Controller/ListByCategoryController.php @@ -93,7 +93,14 @@ class ListByCategoryController extends AbstractController { $categories = []; foreach ($categoryUids as $categoryUid) { - $categories[$categoryUid] = $this->categoryRepository->findByUid($categoryUid); + $category = $this->categoryRepository->findByUid($categoryUid); + $categories[$categoryUid] = $category; + if ($category->_getProperty('_languageUid')>0) { + $originalLangCategory = $this->categoryRepository->findOriginalLanguageById($category->getUid()); + if ($originalLangCategory) { + $categoriesById[$originalLangCategory->getUid()] = $originalLangCategory; + } + } } $startTime = (int) $this->settings['starttime']; diff --git a/Classes/Controller/OverviewController.php b/Classes/Controller/OverviewController.php index 12c71ffc841ab5cb8e658c497b4063d6cc418d56..aedc5c41b0db72e591324b860b2db9244f168fdc 100644 --- a/Classes/Controller/OverviewController.php +++ b/Classes/Controller/OverviewController.php @@ -172,6 +172,13 @@ class OverviewController extends AbstractController { $categoryId = $category->getUid(); $categoryIds[] = $category->getUid(); $categoriesById[$categoryId] = $category; + if ($category->_getProperty('_languageUid')>0) { + $originalLangCategory = $this->categoryRepository->findOriginalLanguageById($category->getUid()); + if ($originalLangCategory) { + $categoryIds[] = $originalLangCategory->getUid(); + $categoriesById[$originalLangCategory->getUid()] = $originalLangCategory; + } + } $tagIds = NULL; if ($newsFilter['tag']) { @@ -476,9 +483,15 @@ class OverviewController extends AbstractController { /** @var QueryResult $categories */ foreach ($categories as $category) { /** @var $category Category */ - $categoryId = $category->getUid(); - $categoryIds[] = $categoryId; - $categoriesById[$categoryId] = $category; + $categoriesById[$category->getUid()] = $category; + $categoryIds[] = $category->getUid(); + if ($category->_getProperty('_languageUid')>0) { + $originalLangCategory = $this->categoryRepository->findOriginalLanguageById($category->getUid()); + if ($originalLangCategory) { + $categoryIds[] = $originalLangCategory->getUid(); + $categoriesById[$originalLangCategory->getUid()] = $originalLangCategory; + } + } } // filter by category and tag if selected in the filter diff --git a/Classes/Domain/Repository/CategoryRepository.php b/Classes/Domain/Repository/CategoryRepository.php index 41af146fd92f8704209b0b93166f8e066b9187a3..f93a4326f6b80975f361f966b0e3b6e96cd78d2e 100644 --- a/Classes/Domain/Repository/CategoryRepository.php +++ b/Classes/Domain/Repository/CategoryRepository.php @@ -2,32 +2,60 @@ namespace SGalinski\SgNews\Domain\Repository; - /*************************************************************** - * Copyright notice - * - * (c) sgalinski Internet Services (https://www.sgalinski.de) - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ +/*************************************************************** + * Copyright notice + * + * (c) sgalinski Internet Services (https://www.sgalinski.de) + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ + +use SGalinski\SgNews\Domain\Model\Category; +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; /** * Category Repository */ class CategoryRepository extends AbstractRepository { + /** + * Find the original language category record + * + * @param int $uid + * @return Category|null + */ + public function findOriginalLanguageById(int $uid): ?Category { + $dataMapper = $this->objectManager->get(DataMapper::class); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); + $row = $queryBuilder->select('default.*') + ->from('pages', 'translation') + ->leftJoin('translation', 'pages', 'default', 'translation.l10n_parent=default.uid') + ->where( + $queryBuilder->expr()->eq('translation.uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + ) + ->setMaxResults(1) + ->execute()->fetch(); + if ($row) { + return current($dataMapper->map($this->objectType, [$row])); + } else { + return NULL; + } + } }