From efd6a5120571dd0962f74847b8bb56aaa27a727b Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid <kevin.ditscheid@sgalinski.de> Date: Thu, 13 Oct 2022 23:24:41 +0200 Subject: [PATCH] [TASK] Rework pagination and make it easier to use --- Classes/Controller/BackendController.php | 41 ++-- Classes/Pagination/Pagination.php | 205 ++++++++++++++++++ Classes/Paginator/QueryBuilderPaginator.php | 105 --------- Classes/Utility/BackendNewsUtility.php | 109 +++++++--- .../Private/Partials/Backend/Pagination.html | 58 ++--- .../Private/Templates/Backend/Index.html | 6 +- 6 files changed, 332 insertions(+), 192 deletions(-) create mode 100644 Classes/Pagination/Pagination.php delete mode 100644 Classes/Paginator/QueryBuilderPaginator.php diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 74843de..38b57d2 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -1,7 +1,5 @@ <?php -namespace SGalinski\SgNews\Controller; - /*************************************************************** * Copyright notice * @@ -26,20 +24,27 @@ namespace SGalinski\SgNews\Controller; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +namespace SGalinski\SgNews\Controller; + +use Psr\Http\Message\ResponseInterface; +use SGalinski\SgNews\Pagination\Pagination; use SGalinski\SgNews\Paginator\QueryBuilderPaginator; use SGalinski\SgNews\Utility\BackendNewsUtility; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent; use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Pagination\SimplePagination; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; +use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; /** @@ -108,7 +113,7 @@ class BackendController extends ActionController { $backendUser = $GLOBALS['BE_USER']; $this->pageInfo = BackendUtility::readPageAccess($this->pageUid, $backendUser->getPagePermsClause(1)); if ($this->pageInfo) { - if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { + if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class); } else { $this->getDocHeaderComponent(); @@ -145,10 +150,11 @@ class BackendController extends ActionController { /** * @param array|null $filters - * @return \Psr\Http\Message\ResponseInterface|null - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException + * @param int $currentPage + * @return ResponseInterface|null + * @throws InvalidQueryException */ - public function indexAction(array $filters = NULL): ?\Psr\Http\Message\ResponseInterface { + public function indexAction(array $filters = NULL, int $currentPage = 1): ?ResponseInterface { $showNewsList = FALSE; if ( ($this->pageUid && $this->pageUid === $this->rootPageUid) || @@ -169,16 +175,11 @@ class BackendController extends ActionController { $filters['categories'] = [$this->pageUid]; } $tags = BackendNewsUtility::getTagsForPage($this->pageUid, $this->language); - [$news, $newsQueryBuilder] = BackendNewsUtility::getNewsByFilters($this->rootPageUid, $filters, $this->language); - - $paginator = new QueryBuilderPaginator($newsQueryBuilder); - $pagination = new SimplePagination($paginator); - - $this->view->assign('paginator', $paginator); + $newsQueryBuilder = BackendNewsUtility::getNewsByFilters($this->rootPageUid, $filters, $this->language); + $pagination = GeneralUtility::makeInstance(Pagination::class, $newsQueryBuilder, $currentPage, 10); $this->view->assign('pagination', $pagination); $this->view->assign('tags', $tags); - $this->view->assign('news', $news); $this->view->assign('filters', $filters); $showNewsList = TRUE; } else { @@ -187,13 +188,13 @@ class BackendController extends ActionController { } $this->view->assign('showNewsList', $showNewsList); - if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { + if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $this->view->assign('V11', FALSE); return NULL; - } else { - $this->view->assign('V11', TRUE); - return $this->createBackendResponse(); } + + $this->view->assign('V11', TRUE); + return $this->createBackendResponse(); } /** @@ -268,9 +269,9 @@ class BackendController extends ActionController { /** * Use the ModuleTemplateResponse to create a response object for the backend * - * @return \Psr\Http\Message\ResponseInterface + * @return ResponseInterface */ - protected function createBackendResponse(): \Psr\Http\Message\ResponseInterface { + protected function createBackendResponse(): ResponseInterface { return $this->htmlResponse($this->view->render()); } @@ -281,7 +282,7 @@ class BackendController extends ActionController { protected function getModuleTemplate() { if ($this->moduleTemplate === NULL) { $moduleTemplateFactory = GeneralUtility::makeInstance( - \TYPO3\CMS\Backend\Template\ModuleTemplateFactory::class + ModuleTemplateFactory::class ); $this->moduleTemplate = $moduleTemplateFactory->create($this->request); } diff --git a/Classes/Pagination/Pagination.php b/Classes/Pagination/Pagination.php new file mode 100644 index 0000000..a1f160c --- /dev/null +++ b/Classes/Pagination/Pagination.php @@ -0,0 +1,205 @@ +<?php +/* + * 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 2 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! + */ + +namespace SGalinski\SgNews\Pagination; + +use TYPO3\CMS\Core\Database\Query\QueryBuilder; + +/** + * This class is a representation of the pagination + * It contains functionality for handling the + */ +class Pagination { + /** + * @var QueryBuilder + */ + private $queryBuilder; + /** + * @var int + */ + private $currentPage; + /** + * @var int + */ + private $limit; + /** + * @var int + */ + private $nextPage; + /** + * @var int + */ + private $previousPage; + /** + * @var int + */ + private $lastPage; + /** + * @var int + */ + private $firstPage; + /** + * @var int + */ + private $startItem; + /** + * @var int + */ + private $endItem; + /** + * @var int + */ + private $totalItems; + /** + * @var array + */ + private $items; + + public function __construct(QueryBuilder $queryBuilder, int $currentPage, int $limit) { + $this->queryBuilder = $queryBuilder; + $this->currentPage = $currentPage; + $this->limit = $limit; + $this->initialize(); + } + + public function initialize() { + $this->firstPage = 1; + $this->totalItems = $this->fetchTotalItemCount(); + $this->lastPage = ceil($this->totalItems / $this->limit); + // correct current page if out of bounds + $this->currentPage = $this->currentPage < 1 ? 1 : min($this->currentPage, $this->lastPage); + $this->nextPage = $this->currentPage >= $this->lastPage ? $this->lastPage : $this->currentPage + 1; + $this->previousPage = $this->currentPage <= 1 ? 1 : $this->currentPage - 1; + $this->startItem = ($this->currentPage - 1) * $this->limit + 1; + // correct startItem if out of bounds + $this->startItem = max($this->startItem, 1); + $this->endItem = ($this->currentPage - 1) * $this->limit + $this->limit; + // correct endItem if out of bounds + $this->endItem = min($this->endItem, $this->totalItems); + $this->items = $this->fetchItems(); + } + + /** + * Reconfigure the query builder to fetch the total count of items + * + * @return int + * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Driver\Exception + */ + private function fetchTotalItemCount(): int { + $workingQueryBuilder = clone $this->queryBuilder; + $count = $workingQueryBuilder->select('uid') + ->setMaxResults(9999999) + ->setFirstResult(0) + ->execute() + ->rowCount(); + return $count ?? 0; + } + + /** + * Reconfigure the queryBuilder to fetch the items for the configured currentPage + * + * @return array + * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Driver\Exception + */ + private function fetchItems(): array { + $workingQueryBuilder = clone $this->queryBuilder; + $items = $workingQueryBuilder->setMaxResults($this->limit) + ->setFirstResult($this->startItem - 1) + ->execute() + ->fetchAllAssociative(); + return $items ?? []; + } + + /** + * @return int + */ + public function getCurrentPage(): int { + return $this->currentPage; + } + + /** + * @return int + */ + public function getLimit(): int { + return $this->limit; + } + + /** + * @return mixed + */ + public function getNextPage() { + return $this->nextPage; + } + + /** + * @return mixed + */ + public function getPreviousPage() { + return $this->previousPage; + } + + /** + * @return mixed + */ + public function getLastPage() { + return $this->lastPage; + } + + /** + * @return mixed + */ + public function getFirstPage() { + return $this->firstPage; + } + + /** + * @return mixed + */ + public function getStartItem() { + return $this->startItem; + } + + /** + * @return mixed + */ + public function getEndItem() { + return $this->endItem; + } + + /** + * @return mixed + */ + public function getTotalItems() { + return $this->totalItems; + } + + /** + * @return array + */ + public function getItems(): array { + return $this->items; + } +} diff --git a/Classes/Paginator/QueryBuilderPaginator.php b/Classes/Paginator/QueryBuilderPaginator.php deleted file mode 100644 index ca3c87c..0000000 --- a/Classes/Paginator/QueryBuilderPaginator.php +++ /dev/null @@ -1,105 +0,0 @@ -<?php - -declare(strict_types=1); - -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - -namespace SGalinski\SgNews\Paginator; - -use TYPO3\CMS\Core\Pagination\AbstractPaginator; -use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; - -/** - * Copied QueryResult Paginator for us to get a raw result returned, - * just like the old Controller used to use, also alot of BE ViewHelpers want an array - */ -final class QueryBuilderPaginator extends AbstractPaginator { - /** - * @var \TYPO3\CMS\Core\Database\Query\QueryBuilder - */ - private $queryBuilder; - - /** - * @var array - */ - private $paginatedQueryResult; - - /** - * @var int - */ - protected $totalItems = 0; - - public function __construct( - \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder, - int $currentPageNumber = 1, - int $itemsPerPage = 10 - ) { - $this->queryBuilder = $queryBuilder; - $this->setCurrentPageNumber($currentPageNumber); - $this->setItemsPerPage($itemsPerPage); - - $this->updateInternalState(); - } - - /** - * @return iterable|QueryResultInterface - */ - public function getPaginatedItems(): iterable { - return $this->paginatedQueryResult; - } - - protected function updatePaginatedItems(int $limit, int $offset): void { - $this->paginatedQueryResult = $this->queryBuilder - ->setMaxResults($limit) - ->setFirstResult($offset) - ->execute()->fetchAll(); - } - - protected function getTotalAmountOfItems(): int { - $countBuilder = clone $this->queryBuilder; - try { - $totalItems = $countBuilder - ->setMaxResults(99999) - ->setFirstResult(0) - ->count('uid') - ->execute()->fetchOne(); - } catch (\Exception $e) { - $totalItems = $countBuilder - ->setMaxResults(99999) - ->setFirstResult(0) - ->count('p.uid') - ->execute()->fetchOne(); - } - $this->setTotalItems($totalItems ?: 0); - return $totalItems ?: 0; - } - - protected function getAmountOfItemsOnCurrentPage(): int { - return count($this->paginatedQueryResult); - } - - /** - * @return int - */ - public function getTotalItems(): int { - return $this->totalItems; - } - - /** - * @param int $totalItems - */ - public function setTotalItems(int $totalItems): void { - $this->totalItems = $totalItems; - } -} diff --git a/Classes/Utility/BackendNewsUtility.php b/Classes/Utility/BackendNewsUtility.php index 22eaa3a..53e9156 100644 --- a/Classes/Utility/BackendNewsUtility.php +++ b/Classes/Utility/BackendNewsUtility.php @@ -1,7 +1,5 @@ <?php -namespace SGalinski\SgNews\Utility; - /*************************************************************** * Copyright notice * @@ -26,6 +24,9 @@ namespace SGalinski\SgNews\Utility; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +namespace SGalinski\SgNews\Utility; + +use InvalidArgumentException; use SGalinski\SgNews\Domain\Model\News; use SGalinski\SgNews\Domain\Model\Tag; use SGalinski\SgNews\Domain\Repository\NewsRepository; @@ -34,6 +35,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Database\Query\QueryHelper; use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; @@ -42,7 +44,9 @@ use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider; use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider; use TYPO3\CMS\Core\Imaging\IconRegistry; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; use TYPO3\CMS\Extbase\Persistence\QueryInterface; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -84,7 +88,7 @@ class BackendNewsUtility { * Get an array of alternative pages for the BE Module view * * @return array - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public static function getAlternativePageOptions(): array { $options = []; @@ -152,7 +156,7 @@ class BackendNewsUtility { * * @param int $siteRootUid * @return array - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public static function getCategoriesForSiteRoot($siteRootUid): array { $siteRootUid = (int) $siteRootUid; @@ -171,11 +175,17 @@ class BackendNewsUtility { ->from('pages') ->where( $queryBuilder->expr()->andX( - $queryBuilder->expr()->eq('doktype', $queryBuilder->createNamedParameter(self::CATEGORY_DOKTYPE, \PDO::PARAM_INT)), - $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter(explode(',', $childPids), Connection::PARAM_INT_ARRAY)) + $queryBuilder->expr()->eq( + 'doktype', + $queryBuilder->createNamedParameter(self::CATEGORY_DOKTYPE, \PDO::PARAM_INT) + ), + $queryBuilder->expr()->in( + 'uid', + $queryBuilder->createNamedParameter(explode(',', $childPids), Connection::PARAM_INT_ARRAY) + ) ) ) - ->execute()->fetchAll(); + ->execute()->fetchAllAssociative(); $categories = []; foreach ($result as $page) { $categoryPageInfo = BackendUtility::readPageAccess( @@ -196,8 +206,8 @@ class BackendNewsUtility { * @param int $pageUid * @param int $languageUid * @return array - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException - * @throws \InvalidArgumentException + * @throws InvalidQueryException + * @throws InvalidArgumentException */ public static function getTagsForPage($pageUid, $languageUid = 0): array { $temporaryTSFEInstance = FALSE; @@ -216,7 +226,7 @@ class BackendNewsUtility { $querySettings = $query->getQuerySettings(); $querySettings->setLanguageUid($languageUid); $querySettings->setLanguageOverlayMode(TRUE); - if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { + if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $querySettings->setLanguageMode('content_fallback'); } @@ -254,8 +264,8 @@ class BackendNewsUtility { * @param int $newsItemUid * @param int $languageUid * @return array - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException - * @throws \InvalidArgumentException + * @throws InvalidQueryException + * @throws InvalidArgumentException */ public static function getTagsForNewsItem($newsItemUid, $languageUid = 0): array { $temporaryTSFEInstance = FALSE; @@ -274,7 +284,7 @@ class BackendNewsUtility { $querySettings = $query->getQuerySettings(); $querySettings->setLanguageUid($languageUid); $querySettings->setLanguageOverlayMode(TRUE); - if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { + if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $querySettings->setLanguageMode('content_fallback'); } $query->setQuerySettings($querySettings); @@ -304,15 +314,14 @@ class BackendNewsUtility { * @param int $rootPageUid * @param array $filters * @param int $languageUid - * @return array - * @throws \InvalidArgumentException + * @return QueryBuilder|null + * @throws InvalidArgumentException */ - public static function getNewsByFilters($rootPageUid = 0, array $filters = [], $languageUid = 0, $limit = 0): array { - $out = []; + public static function getNewsByFilters($rootPageUid = 0, array $filters = [], $languageUid = 0, $limit = 0): ?QueryBuilder { $rootPageUid = (int) $rootPageUid; $languageUid = (int) $languageUid; if (!$rootPageUid) { - return $out; + return NULL; } $categories = []; @@ -336,7 +345,7 @@ class BackendNewsUtility { } if (!count($categories)) { - return $out; + return NULL; } $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class); @@ -356,7 +365,7 @@ class BackendNewsUtility { } if (!count($allowedUids)) { - return $out; + return NULL; } $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); @@ -379,8 +388,14 @@ class BackendNewsUtility { )->from('pages', 'p') ->where( $queryBuilder->expr()->andX( - $queryBuilder->expr()->in('p.uid', $queryBuilder->createNamedParameter($allowedUids, Connection::PARAM_INT_ARRAY)), - $queryBuilder->expr()->eq('p.doktype', $queryBuilder->createNamedParameter(self::NEWS_DOKTYPE, \PDO::PARAM_INT)) + $queryBuilder->expr()->in( + 'p.uid', + $queryBuilder->createNamedParameter($allowedUids, Connection::PARAM_INT_ARRAY) + ), + $queryBuilder->expr()->eq( + 'p.doktype', + $queryBuilder->createNamedParameter(self::NEWS_DOKTYPE, \PDO::PARAM_INT) + ) ) ) ->groupBy('p.uid') @@ -391,8 +406,14 @@ class BackendNewsUtility { 'pages', 'translation', $queryBuilder->expr()->andX( - $queryBuilder->expr()->eq('translation.l10n_parent', 'p.uid'), - $queryBuilder->expr()->eq('translation.sys_language_uid', $queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq( + 'translation.l10n_parent', + 'p.uid' + ), + $queryBuilder->expr()->eq( + 'translation.sys_language_uid', + $queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT) + ) ) ); } @@ -403,10 +424,22 @@ class BackendNewsUtility { 'sys_category_record_mm', 'tag', $queryBuilder->expr()->andX( - $queryBuilder->expr()->eq('tag.tablenames', $queryBuilder->createNamedParameter('pages')), - $queryBuilder->expr()->eq('tag.fieldname', $queryBuilder->createNamedParameter('tx_sgnews_tags')), - $queryBuilder->expr()->eq('tag.uid_foreign', 'p.uid'), - $queryBuilder->expr()->in('tag.uid_local', $queryBuilder->createNamedParameter(\array_unique($filters['tags']), Connection::PARAM_INT_ARRAY)) + $queryBuilder->expr()->eq( + 'tag.tablenames', + $queryBuilder->createNamedParameter('pages') + ), + $queryBuilder->expr()->eq( + 'tag.fieldname', + $queryBuilder->createNamedParameter('tx_sgnews_tags') + ), + $queryBuilder->expr()->eq( + 'tag.uid_foreign', + 'p.uid' + ), + $queryBuilder->expr()->in( + 'tag.uid_local', + $queryBuilder->createNamedParameter(\array_unique($filters['tags']), Connection::PARAM_INT_ARRAY) + ) ) ); } @@ -433,7 +466,7 @@ class BackendNewsUtility { $authorQueryBuilder->expr()->like('author.name', $authorSearchParameter), $authorQueryBuilder->expr()->like('author.email', $authorSearchParameter) ) - )->execute()->fetchAll(); + )->execute()->fetchAllAssociative(); if (count($authors) > 0) { foreach (array_column($authors, 'uid') as $authorUid) { @@ -451,7 +484,7 @@ class BackendNewsUtility { $queryBuilder->setMaxResults($limit); } - return [$queryBuilder->execute()->fetchAll(), $queryBuilder]; + return $queryBuilder; } /** @@ -459,7 +492,7 @@ class BackendNewsUtility { * * @param int $pageUid * @return array - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public static function getAvailableLanguages($pageUid = 0): array { $pageUid = (int) $pageUid; @@ -478,11 +511,12 @@ class BackendNewsUtility { $languages = [ 0 => ['title' => $defaultLanguage, 'flag' => $defaultLanguageFlag] ]; - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language'); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_language'); $languageRows = $queryBuilder->select('uid', 'title', 'flag') ->from('sys_language') ->orderBy('sorting') - ->execute()->fetchAll(); + ->execute()->fetchAllAssociative(); if ($languageRows) { /** @var BackendUserAuthentication $backendUser */ $backendUser = $GLOBALS['BE_USER']; @@ -525,8 +559,11 @@ class BackendNewsUtility { $useDeleteClause = TRUE ) { if (is_array($GLOBALS['TCA'][$theTable])) { - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($theTable); - $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class)); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable($theTable); + $queryBuilder->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class)); ; if ($useDeleteClause) { $queryBuilder->getRestrictions() @@ -567,7 +604,7 @@ class BackendNewsUtility { } } - return $queryBuilder->execute()->fetchAll(); + return $queryBuilder->execute()->fetchAllAssociative(); } return NULL; diff --git a/Resources/Private/Partials/Backend/Pagination.html b/Resources/Private/Partials/Backend/Pagination.html index 242dff9..3e40a6c 100644 --- a/Resources/Private/Partials/Backend/Pagination.html +++ b/Resources/Private/Partials/Backend/Pagination.html @@ -3,15 +3,19 @@ <nav class="pagination-wrap"> <ul class="pagination pagination-block"> - <f:if condition="{pagination.previousPageNumber} && {pagination.previousPageNumber} >= {pagination.firstPageNumber}"> + <f:if condition="{pagination.previousPage} && {pagination.previousPage} >= {pagination.firstPage}"> <f:then> <li class="page-item"> - <a href="{f:uri.action(action:actionName, arguments:{currentPage: 1})}" title="{f:translate(key:'widget.pagination.first')}" class="page-link"> + <a href="{f:uri.action(action: 'index', arguments: {currentPage: 1})}" + title="{f:translate(key:'widget.pagination.first')}" + class="page-link"> <core:icon identifier="actions-view-paging-first" /> </a> </li> <li class="page-item"> - <a href="{f:uri.action(action:actionName, arguments:{currentPage: pagination.previousPageNumber})}" title="{f:translate(key:'widget.pagination.previous')}" class="page-link"> + <a href="{f:uri.action(action: 'index', arguments: {currentPage: pagination.previousPage})}" + title="{f:translate(key:'widget.pagination.previous')}" + class="page-link"> <core:icon identifier="actions-view-paging-previous" /> </a> </li> @@ -31,52 +35,48 @@ </f:if> <li class="page-item"> <span class="page-link"> - <f:if condition="{recordsLabel}"> - <f:then> - {recordsLabel} - </f:then> - <f:else> - <f:translate key="widget.pagination.records" /> - </f:else> - </f:if> - {pagination.startRecordNumber} - {pagination.endRecordNumber} / {paginator.totalItems} + <f:translate key="widget.pagination.records" /> + {pagination.startItem} - {pagination.endItem} / {pagination.totalItems} </span> </li> <li class="page-item"> <span class="page-link"> <f:translate key="widget.pagination.page" /> - <form id="paginator-form-{position}" onsubmit="goToPage{position}(this); return false;" style="display:inline;"> + <form id="paginator-form" onsubmit="goToPage(this); return false;" style="display:inline;"> <script type="text/javascript"> - function goToPage{position}(formObject) { + function goToPage(formObject) { var page = formObject.elements['paginator-target-page'].value; - var url = '{f:uri.action(action:actionName, arguments:{currentPage: 987654321}) -> f:format.raw()}'; + var url = '{f:uri.action(action: 'index', arguments:{currentPage: 987654321}) -> f:format.raw()}'; - if (page > {pagination.lastPageNumber}) { - page = {pagination.lastPageNumber}; - } - else - if (page < 1) { - page = 1; - } url = url.replace('987654321', page); self.location.href = url; } </script> - <f:form.textfield id="paginator-{position}" name="paginator-target-page" additionalAttributes="{min: '1'}" class="form-control input-sm paginator-input" size="5" value="{currentPage}" type="number" /> + <f:form.textfield id="paginator" + name="paginator-target-page" + additionalAttributes="{min: '1'}" + class="form-control input-sm paginator-input" + size="5" + value="{pagination.currentPage}" + type="number" /> </form> - / {pagination.lastPageNumber} + / {pagination.lastPage} </span> </li> - <f:if condition="{pagination.nextPageNumber} && {pagination.nextPageNumber} <= {pagination.lastPageNumber}"> + <f:if condition="{pagination.nextPage} && {pagination.nextPage} <= {pagination.lastPage}"> <f:then> <li class="page-item"> - <a class="page-link" href="{f:uri.action(action:actionName, arguments:{currentPage: pagination.nextPageNumber})}" title="{f:translate(key:'widget.pagination.next')}"> + <a class="page-link" + href="{f:uri.action(action: 'index', arguments: {currentPage: pagination.nextPage})}" + title="{f:translate(key:'widget.pagination.next')}"> <core:icon identifier="actions-view-paging-next" /> </a> </li> <li class="page-item"> - <a class="page-link" href="{f:uri.action(action:actionName, arguments:{currentPage: pagination.lastPageNumber})}" title="{f:translate(key:'widget.pagination.last')}"> + <a class="page-link" + href="{f:uri.action(action: 'index', arguments: {currentPage: pagination.lastPage})}" + title="{f:translate(key:'widget.pagination.last')}"> <core:icon identifier="actions-view-paging-last" /> </a> </li> @@ -95,7 +95,9 @@ </f:else> </f:if> <li class="page-item"> - <a class="page-link" href="{f:uri.action(action:actionName, arguments:{currentPage: currentPage})}" title="{f:translate(key:'widget.pagination.refresh')}"> + <a class="page-link" + href="{f:uri.action(action: 'index', arguments: {currentPage: pagination.currentPage})}" + title="{f:translate(key:'widget.pagination.refresh')}"> <core:icon identifier="actions-refresh" /> </a> </li> diff --git a/Resources/Private/Templates/Backend/Index.html b/Resources/Private/Templates/Backend/Index.html index 8943f55..440d39c 100644 --- a/Resources/Private/Templates/Backend/Index.html +++ b/Resources/Private/Templates/Backend/Index.html @@ -41,19 +41,19 @@ </f:if> </div> - <f:if condition="{news}"> + <f:if condition="{pagination.totalItems} > 0"> <div class="panel panel-default recordlist"> <div class="table-fit"> <table data-table="pages" class="table table-striped table-hover"> <thead> <tr> <td class="bg-light" colspan="3"> - <f:render partial="Backend/Pagination" arguments="{pagination: pagination, paginator: paginator, actionName: 'index', currentPage: currentPage}"/> + <f:render partial="Backend/Pagination" arguments="{pagination: pagination}"/> </td> </tr> </thead> <tbody> - <f:for each="{paginator.paginatedItems}" as="singleNews"> + <f:for each="{pagination.items}" as="singleNews"> <tr data-uid="{singleNews.uid}"> <td nowrap="nowrap" class="col-icon"> <f:format.raw> -- GitLab