diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php index 2e5efc704021bee4a3ad7ddc877ab878af4dded0..da22512afa94dcfbb814d367e60057fa08fe959e 100644 --- a/Classes/Controller/AbstractController.php +++ b/Classes/Controller/AbstractController.php @@ -187,5 +187,3 @@ abstract class AbstractController extends ActionController { ]; } } - -?> diff --git a/Classes/Controller/LatestController.php b/Classes/Controller/LatestController.php index 1cd7fda2fd1e5946649e5326f8ffadc420632bc1..4a8ad8e84b1905a1b33cdd074853d43e3e9b0ce3 100644 --- a/Classes/Controller/LatestController.php +++ b/Classes/Controller/LatestController.php @@ -61,7 +61,7 @@ class LatestController extends AbstractController { } $latestNewsEntries = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories( - $limit, FALSE, $categoryUids, 0, TRUE + $limit, FALSE, $categoryUids, 0, TRUE, $this->settings['sortBy'] ); $newsMetaData = []; diff --git a/Classes/Controller/ListByCategoryController.php b/Classes/Controller/ListByCategoryController.php index 98f43db270ac71c899ec4b27bae9203b3b8d7b57..c7ff9e60746a74cd820144564599e356a4089fa4 100644 --- a/Classes/Controller/ListByCategoryController.php +++ b/Classes/Controller/ListByCategoryController.php @@ -26,8 +26,8 @@ namespace SGalinski\SgNews\Controller; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use SGalinski\SgNews\Service\HeaderMetaDataService; use SGalinski\SgNews\Domain\Model\News; +use SGalinski\SgNews\Service\HeaderMetaDataService; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -81,7 +81,9 @@ class ListByCategoryController extends AbstractController { $newsMetaData = []; $headerSet = FALSE; - $news = $this->newsRepository->findAllSortedNewsByCategories($categoryUids, $newsPerPage, $offset)->toArray(); + $news = $this->newsRepository->findAllSortedNewsByCategories( + $categoryUids, $newsPerPage, $offset, $this->settings['sortBy'] + )->toArray(); foreach ($news as $newsEntry) { /** @var News $newsEntry */ $data = $this->getMetaDataForNews($newsEntry, $categories[$newsEntry->getPid()]); @@ -103,5 +105,3 @@ class ListByCategoryController extends AbstractController { $this->view->assign('categories', $categories); } } - -?> diff --git a/Classes/Controller/NewsFeedController.php b/Classes/Controller/NewsFeedController.php index 47bf50b17134aea7e6d0a35b0662c25477e319ff..1c130c418f08b0e0cf301f97759e5ffaf90ea9a8 100644 --- a/Classes/Controller/NewsFeedController.php +++ b/Classes/Controller/NewsFeedController.php @@ -2,29 +2,29 @@ namespace SGalinski\SgNews\Controller; -/*************************************************************** - * 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! + ***************************************************************/ /** * Controller that handles the news feed rendering @@ -46,5 +46,3 @@ class NewsFeedController extends AbstractController { $this->view->assign('news', $news); } } - -?> diff --git a/Classes/Controller/OverviewController.php b/Classes/Controller/OverviewController.php index 3fd10ca013560fcc37c825543a3d28b575417149..e0a277531b7c4a065de132c9177f7be7a703e053 100644 --- a/Classes/Controller/OverviewController.php +++ b/Classes/Controller/OverviewController.php @@ -69,7 +69,9 @@ class OverviewController extends AbstractController { protected function highlightBestFitNews(array $categoryIds = NULL) { /** @var News $highlightedNews */ $highlightedNews = $this->newsRepository - ->findLastUpdatedOrHighlightedNewsByCategories(1, FALSE, $categoryIds)->getFirst(); + ->findLastUpdatedOrHighlightedNewsByCategories( + 1, FALSE, $categoryIds, 0, FALSE, $this->settings['sortBy'] + )->getFirst(); if (!$highlightedNews) { return; } @@ -119,7 +121,9 @@ class OverviewController extends AbstractController { $categoryIds[] = $category->getUid(); $categoriesById[$categoryId] = $category; - $news = $this->newsRepository->findAllSortedNewsByCategories([$categoryId], $newsLimitPerCategory, $offset); + $news = $this->newsRepository->findAllSortedNewsByCategories( + [$categoryId], $newsLimitPerCategory, $offset, $this->settings['sortBy'] + ); foreach ($news as $newsEntry) { /** @var News $newsEntry */ $categoryId = $newsEntry->getPid(); @@ -141,7 +145,9 @@ class OverviewController extends AbstractController { } $allNews = []; - $news = $this->newsRepository->findAllSortedNewsByCategories($categoryIds, $newsLimitPerCategory, $offset); + $news = $this->newsRepository->findAllSortedNewsByCategories( + $categoryIds, $newsLimitPerCategory, $offset, $this->settings['sortBy'] + ); foreach ($news as $newsEntry) { /** @var News $newsEntry */ $categoryId = $newsEntry->getPid(); @@ -200,7 +206,9 @@ class OverviewController extends AbstractController { } $newsMetaData = []; - $news = $this->newsRepository->findAllSortedNewsByCategories($categoryIds, $newsPerPage, $offset); + $news = $this->newsRepository->findAllSortedNewsByCategories( + $categoryIds, $newsPerPage, $offset, $this->settings['sortBy'] + ); foreach ($news as $newsEntry) { /** @var News $newsEntry */ $data = $this->getMetaDataForNews($newsEntry, $categoriesById[$newsEntry->getPid()]); diff --git a/Classes/Controller/PageBrowserController.php b/Classes/Controller/PageBrowserController.php index 83df43c3b52a0d549556e4ef8a8de74e5e6be918..5f3371c6affd3a7cbf973caf54445e36ba58cdee 100644 --- a/Classes/Controller/PageBrowserController.php +++ b/Classes/Controller/PageBrowserController.php @@ -143,5 +143,3 @@ class PageBrowserController extends ActionController { return $this->uriBuilder->reset()->setUseCacheHash(FALSE)->uriFor('index', ['currentPage' => $page,]); } } - -?> diff --git a/Classes/Controller/SingleViewController.php b/Classes/Controller/SingleViewController.php index 1e89a6171d4eac8496b4595ea2e954a41a0388bb..fb748fa4f11ad01519b6467e66b9a6098aebd21e 100644 --- a/Classes/Controller/SingleViewController.php +++ b/Classes/Controller/SingleViewController.php @@ -26,11 +26,9 @@ namespace SGalinski\SgNews\Controller; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use SGalinski\SgNews\Service\HeaderMetaDataService; use SGalinski\SgNews\Domain\Model\Category; use SGalinski\SgNews\Domain\Model\News; -use TYPO3\CMS\Core\Page\PageRenderer; -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; +use SGalinski\SgNews\Service\HeaderMetaDataService; /** * Controller that handles the news single view page @@ -73,24 +71,18 @@ class SingleViewController extends AbstractController { return; } - $similarNewsMetaData = []; - $similarNews = $this->newsRepository->findRandomNews(3, $news); - foreach ($similarNews as $similarNewsEntry) { - /** @var News $similarNewsEntry */ - /** @var Category $category */ - $category = $this->categoryRepository->findByUid($similarNewsEntry->getPid()); - if (!$category) { - continue; - } - - $similarNewsMetaData[] = $this->getMetaDataForNews($similarNewsEntry, $category); - } - - /** @var $typoScriptController TypoScriptFrontendController */ - $typoScriptController = $GLOBALS['TSFE']; - - /** @var PageRenderer $pageRenderer */ - $pageRenderer = $typoScriptController->getPageRenderer(); +// $similarNewsMetaData = []; +// $similarNews = $this->newsRepository->findRandomNews(3, $news); +// foreach ($similarNews as $similarNewsEntry) { +// /** @var News $similarNewsEntry */ +// /** @var Category $category */ +// $category = $this->categoryRepository->findByUid($similarNewsEntry->getPid()); +// if (!$category) { +// continue; +// } +// +// $similarNewsMetaData[] = $this->getMetaDataForNews($similarNewsEntry, $category); +// } $newsAuthor = $news->getAuthorFrontendUser(); $newsMetaData = $this->getMetaDataForNews($news, $newsCategory); @@ -100,16 +92,19 @@ class SingleViewController extends AbstractController { HeaderMetaDataService::addOgImageToHeader($newsMetaData['teaserImage']); } + $previousNews = $this->newsRepository->findPreviousNewsEntryFromCurrentNews($news, $this->settings['sortBy']) + ->getFirst(); + $nextNews = $this->newsRepository->findNextNewsEntryFromCurrentNews($news, $this->settings['sortBy']) + ->getFirst(); + $this->view->assignMultiple( [ 'newsMetaData' => $newsMetaData, - 'similarNewsMetaData' => $similarNewsMetaData, - 'previousNews' => $this->newsRepository->findPreviousNewsEntryFromCurrentNews($news)->getFirst(), - 'nextNews' => $this->newsRepository->findNextNewsEntryFromCurrentNews($news)->getFirst(), +// 'similarNewsMetaData' => $similarNewsMetaData, + 'previousNews' => $previousNews, + 'nextNews' => $nextNews, 'newsAuthor' => $newsAuthor, ] ); } } - -?> diff --git a/Classes/Domain/Model/Category.php b/Classes/Domain/Model/Category.php index f30ad323a66c120f9f5e760ae0e62d763ea48e3b..5ab70c4d313b2228a834618b20831f6ad961723b 100644 --- a/Classes/Domain/Model/Category.php +++ b/Classes/Domain/Model/Category.php @@ -2,34 +2,32 @@ namespace SGalinski\SgNews\Domain\Model; -/*************************************************************** - * 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! + ***************************************************************/ /** * Category */ class Category extends CategoryAndNews { } - -?> diff --git a/Classes/Domain/Model/CategoryAndNews.php b/Classes/Domain/Model/CategoryAndNews.php index e14b0710a028a082537bbdc950f329b546865d72..d4d4f032e5104287030091c71500d7134acb46fc 100644 --- a/Classes/Domain/Model/CategoryAndNews.php +++ b/Classes/Domain/Model/CategoryAndNews.php @@ -227,5 +227,3 @@ abstract class CategoryAndNews extends AbstractEntity { $this->sorting = (int) $sorting; } } - -?> diff --git a/Classes/Domain/Model/News.php b/Classes/Domain/Model/News.php index 6d54485279404cd3cab30612c6169bfd0ab97f40..51c56a49c7ce958801d45e5b226ff7bc4617478f 100644 --- a/Classes/Domain/Model/News.php +++ b/Classes/Domain/Model/News.php @@ -240,5 +240,3 @@ class News extends CategoryAndNews { return $this->authorFrontendUser; } } - -?> diff --git a/Classes/Domain/Repository/CategoryRepository.php b/Classes/Domain/Repository/CategoryRepository.php index 4680cf34c73b33ec129164c25de37d2db04162a3..41af146fd92f8704209b0b93166f8e066b9187a3 100644 --- a/Classes/Domain/Repository/CategoryRepository.php +++ b/Classes/Domain/Repository/CategoryRepository.php @@ -2,34 +2,32 @@ 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! + ***************************************************************/ /** * Category Repository */ class CategoryRepository extends AbstractRepository { } - -?> diff --git a/Classes/Domain/Repository/NewsRepository.php b/Classes/Domain/Repository/NewsRepository.php index 1fdbf4e31a8afabcaa0ffb4d2b6f3c92a12e6881..eb435566bb1b038368aaf15d79e0affaeade07ea 100644 --- a/Classes/Domain/Repository/NewsRepository.php +++ b/Classes/Domain/Repository/NewsRepository.php @@ -41,9 +41,10 @@ class NewsRepository extends AbstractRepository { * @param array $categoryIds NULL, if the category filter isn't applied, otherwise an array with the categories uid. * @param int $limit * @param int $offset + * @param string $sortBy date or positionInTree * @return QueryResultInterface */ - public function findAllSortedNewsByCategories($categoryIds = NULL, $limit = 0, $offset = 0) { + public function findAllSortedNewsByCategories($categoryIds = NULL, $limit = 0, $offset = 0, $sortBy = 'date') { $query = $this->createQuery(); $categoryConstraint = []; @@ -63,12 +64,23 @@ class NewsRepository extends AbstractRepository { $query->setOffset($offset); } - $query->setOrderings( - [ - 'lastUpdated' => QueryInterface::ORDER_DESCENDING, - 'crdate' => QueryInterface::ORDER_DESCENDING, - ] - ); + if ($sortBy === 'date') { + $query->setOrderings( + [ + 'lastUpdated' => QueryInterface::ORDER_DESCENDING, + 'crdate' => QueryInterface::ORDER_DESCENDING, + ] + ); + } else { + $query->setOrderings( + [ + 'sorting' => QueryInterface::ORDER_ASCENDING, + 'lastUpdated' => QueryInterface::ORDER_DESCENDING, + 'crdate' => QueryInterface::ORDER_DESCENDING, + ] + ); + } + return $query->execute(); } @@ -97,10 +109,12 @@ class NewsRepository extends AbstractRepository { * @param array $categoryIds NULL, if the category filter isn't applied, otherwise an array with the categories uid. * @param int $offset * @param bool $hideNeverHighlightedNews + * @param string $sortBy date or positionInTree * @return QueryResult */ public function findLastUpdatedOrHighlightedNewsByCategories( - $limit = 1, $onlyHighlighted = FALSE, array $categoryIds = NULL, $offset = 0, $hideNeverHighlightedNews = FALSE + $limit = 1, $onlyHighlighted = FALSE, array $categoryIds = NULL, + $offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date' ) { $query = $this->createQuery(); $constraints = NULL; @@ -116,13 +130,24 @@ class NewsRepository extends AbstractRepository { $constraints[] = $query->equals('tx_sgnews_never_highlighted', 0); } - $query->setOrderings( - [ - 'tx_sgnews_highlighted' => QueryInterface::ORDER_DESCENDING, - 'lastUpdated' => QueryInterface::ORDER_DESCENDING, - 'crdate' => QueryInterface::ORDER_DESCENDING, - ] - ); + if ($sortBy === 'date') { + $query->setOrderings( + [ + 'tx_sgnews_highlighted' => QueryInterface::ORDER_DESCENDING, + 'lastUpdated' => QueryInterface::ORDER_DESCENDING, + 'crdate' => QueryInterface::ORDER_DESCENDING, + ] + ); + } else { + $query->setOrderings( + [ + 'tx_sgnews_highlighted' => QueryInterface::ORDER_DESCENDING, + 'sorting' => QueryInterface::ORDER_ASCENDING, + 'lastUpdated' => QueryInterface::ORDER_DESCENDING, + 'crdate' => QueryInterface::ORDER_DESCENDING, + ] + ); + } if ($constraints !== NULL) { $constraints = $query->logicalAnd($constraints); @@ -139,39 +164,46 @@ class NewsRepository extends AbstractRepository { return $query->matching($constraints)->execute(); } - /** - * Method returns the random News of the given amount. - * - * @param int $limit - * @param News $excludeNews - * @return QueryResult - */ - public function findRandomNews($limit = 0, News $excludeNews = NULL) { - $query = $this->createQuery(); - $excludeClause = ($excludeNews ? 'AND uid != ' . $excludeNews->getUid() : ''); - $statement = 'SELECT * FROM pages WHERE doktype = 116 ' . $excludeClause . - $this->getEnableFieldsStatement('pages') . ' ORDER BY RAND()'; - - if ($limit > 0) { - $statement .= ' LIMIT ' . $limit; - } - - /** @noinspection PhpUndefinedMethodInspection */ - return $query->statement($statement)->execute(); - } +// /** +// * Method returns the random News of the given amount. +// * +// * @param int $limit +// * @param News $excludeNews +// * @return QueryResult +// */ +// public function findRandomNews($limit = 0, News $excludeNews = NULL) { +// $query = $this->createQuery(); +// $excludeClause = ($excludeNews ? 'AND uid != ' . $excludeNews->getUid() : ''); +// $statement = 'SELECT * FROM pages WHERE doktype = 116 ' . $excludeClause . +// $this->getEnableFieldsStatement('pages') . ' ORDER BY RAND()'; +// +// if ($limit > 0) { +// $statement .= ' LIMIT ' . $limit; +// } +// +// /** @noinspection PhpUndefinedMethodInspection */ +// return $query->statement($statement)->execute(); +// } /** * Method returns the next News of the given news. * * @param News $news + * @param string $sortBy date or positionInTree * @return QueryResult */ - public function findNextNewsEntryFromCurrentNews(News $news) { + public function findNextNewsEntryFromCurrentNews(News $news, $sortBy = 'date') { $query = $this->createQuery(); + if ($sortBy === 'date') { + $orderBy = 'ORDER BY lastUpdated DESC, crdate DESC'; + } else { + $orderBy = 'ORDER BY sorting ASC, lastUpdated DESC, crdate DESC'; + } + $statement = 'SELECT * FROM pages WHERE uid = (SELECT MIN(uid) FROM pages WHERE pid = ' . $news->getPid() . ' AND uid > ' . $news->getUid() . - $this->getEnableFieldsStatement('pages') . ' ORDER BY lastUpdated DESC, crdate DESC)' . + $this->getEnableFieldsStatement('pages') . ' ' . $orderBy . ')' . $this->getEnableFieldsStatement('pages'); /** @noinspection PhpUndefinedMethodInspection */ @@ -182,19 +214,24 @@ class NewsRepository extends AbstractRepository { * Method returns the previous News of the given news. * * @param News $news + * @param string $sortBy date or positionInTree * @return QueryResult */ - public function findPreviousNewsEntryFromCurrentNews(News $news) { + public function findPreviousNewsEntryFromCurrentNews(News $news, $sortBy = 'date') { $query = $this->createQuery(); + if ($sortBy === 'date') { + $orderBy = 'ORDER BY lastUpdated DESC, crdate DESC'; + } else { + $orderBy = 'ORDER BY sorting ASC, lastUpdated DESC, crdate DESC'; + } + $statement = 'SELECT * FROM pages WHERE uid = (SELECT MAX(uid) FROM pages WHERE pid = ' . $news->getPid() . ' AND uid < ' . $news->getUid() . - $this->getEnableFieldsStatement('pages') . ' ORDER BY lastUpdated DESC, crdate DESC)' . + $this->getEnableFieldsStatement('pages') . ' ' . $orderBy . ')' . $this->getEnableFieldsStatement('pages'); /** @noinspection PhpUndefinedMethodInspection */ return $query->statement($statement)->execute(); } } - -?> diff --git a/Configuration/TypoScript/Frontend/setup.txt b/Configuration/TypoScript/Frontend/setup.txt index 5d219fdd87de6f5573a19b4295b0bf6f2b067d43..e4ccb4f85e139ae0c5da52b1843e4ab62a46bdc5 100644 --- a/Configuration/TypoScript/Frontend/setup.txt +++ b/Configuration/TypoScript/Frontend/setup.txt @@ -55,9 +55,17 @@ plugin.tx_sgnews { } settings { + # Name of your site - required for the news.xml siteName = + + # Your rootpage id - required for the news.xml to retrieve the base path rootpageId = 1 + + # News limit (can be usually set also inside the flexforms) newsLimitPerPage = {$plugin.tx_sgnews.settings.newsLimitPerPage} + + # How to sort the news in general (date, positionInTree) + sortBy = date } features {