Skip to content
Snippets Groups Projects

[TASK] Rework pagination and make it easier to use

Merged Kevin Ditscheid requested to merge rework_Pagination into master
7 files
+ 266
247
Compare changes
  • Side-by-side
  • Inline
Files
7
<?php
namespace SGalinski\SgRoutes\Controller;
/***************************************************************
* Copyright notice
*
@@ -26,18 +24,24 @@ namespace SGalinski\SgRoutes\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
namespace SGalinski\SgRoutes\Controller;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use SGalinski\SgRoutes\Domain\Model\Category;
use SGalinski\SgRoutes\Domain\Model\Route;
use SGalinski\SgRoutes\Domain\Repository\CategoryRepository;
use SGalinski\SgRoutes\Domain\Repository\LogRepository;
use SGalinski\SgRoutes\Domain\Repository\RoutehitRepository;
use SGalinski\SgRoutes\Domain\Repository\RouteRepository;
use SGalinski\SgRoutes\Pagination\Pagination;
use SGalinski\SgRoutes\Service\LicenceCheckService;
use SGalinski\SgRoutes\Service\RoutingService;
use TYPO3\CMS\Backend\Clipboard\Clipboard;
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\Database\ConnectionPool;
@@ -49,6 +53,7 @@ use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
@@ -90,12 +95,12 @@ class RouteController extends ActionController {
/**
* DocHeaderComponent
* @var \TYPO3\CMS\Backend\Template\Components\DocHeaderComponent
* @var DocHeaderComponent
*/
private $docHeaderComponent;
/**
* @var \SGalinski\SgRoutes\Domain\Repository\RouteRepository
* @var RouteRepository
*/
private $routeRepository;
@@ -114,7 +119,7 @@ class RouteController extends ActionController {
}
/**
* @var \SGalinski\SgRoutes\Domain\Repository\CategoryRepository
* @var CategoryRepository
*/
private $categoryRepository;
@@ -128,7 +133,7 @@ class RouteController extends ActionController {
}
/**
* @var \SGalinski\SgRoutes\Domain\Repository\LogRepository
* @var LogRepository
*/
private $logRepository;
@@ -248,11 +253,12 @@ class RouteController extends ActionController {
* Shows all the data for the selected page browser page in the backend.
*
* @param array $filters
* @param int $currentPage
* @throws InvalidQueryException
* @throws UnexpectedValueException
* @throws InvalidArgumentException
*/
public function listAction($filters = NULL): ?\Psr\Http\Message\ResponseInterface {
public function listAction($filters = NULL, int $currentPage = 1): ?ResponseInterface {
if ($this->rootPageUid) {
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
@@ -261,16 +267,10 @@ class RouteController extends ActionController {
} else {
$backendUser->pushModuleData('tools_beuser/index.php/web_SgRoutesRoute_filters', $filters);
}
// Update Page in case we got a currentPage from Pagination
if ($this->request->hasArgument('currentPage')) {
$currentPage = (int) $this->request->getArgument('currentPage');
} else {
$currentPage = 1;
}
$routes = $this->routeRepository->findRoutes($this->rootPageUid, $filters);
$paginator = new \SGalinski\SgRoutes\Paginator\QueryResultPaginator($routes, $currentPage, 10);
$simplePagination = new SimplePagination($paginator);
$pagination = GeneralUtility::makeInstance(Pagination::class, $routes, $currentPage, 10);
$this->view->assign('pagination', $pagination);
$prevUid = 0;
$prevPrevUid = 0;
@@ -307,10 +307,6 @@ class RouteController extends ActionController {
$categoryOptions[$category->getUid()] = $category->getTitle();
}
$this->view->assign('paginator', $paginator);
$this->view->assign('pagination', $simplePagination);
$this->view->assign('currentPage', $currentPage);
$this->view->assign('routes', $routes);
$this->view->assign('sortingData', $sortingData);
$this->view->assign('categoryOptions', $categoryOptions);
$this->view->assign('filters', $filters);
@@ -363,12 +359,12 @@ class RouteController extends ActionController {
* Delete all Routes
*
* @param array $filters
* @return \Psr\Http\Message\ResponseInterface|null
* @return ResponseInterface|null
* @throws IllegalObjectTypeException
* @throws InvalidQueryException
* @throws StopActionException
*/
public function deleteAllAction(array $filters = []): ?\Psr\Http\Message\ResponseInterface {
public function deleteAllAction(array $filters = []): ?ResponseInterface {
/** @var ObjectStorage $routes */
$routes = $this->routeRepository->findRoutes($this->rootPageUid, $filters);
if ($routes && $routesCount = $routes->count()) {
@@ -389,10 +385,10 @@ class RouteController extends ActionController {
* Show htaccess Strings
*
* @param array $filters
* @return \Psr\Http\Message\ResponseInterface|null
* @return ResponseInterface|null
* @throws InvalidQueryException
*/
public function htaccessAction(array $filters = []): ?\Psr\Http\Message\ResponseInterface {
public function htaccessAction(array $filters = []): ?ResponseInterface {
/** @var array $routes */
$routes = $this->routeRepository->findRoutes($this->rootPageUid, $filters, TRUE);
$routingService = GeneralUtility::makeInstance(RoutingService::class);
@@ -406,26 +402,15 @@ class RouteController extends ActionController {
/**
* Shows all log data of the executed redirects.
*
* @param int $currentPage
* @throws UnexpectedValueException
* @throws InvalidArgumentException
*/
public function logAction(): ?\Psr\Http\Message\ResponseInterface {
public function logAction(int $currentPage = 1): ?ResponseInterface {
if ($this->rootPageUid) {
// Update Page in case we got a currentPage from Pagination
if ($this->request->hasArgument('currentPage')) {
$currentPage = (int) $this->request->getArgument('currentPage');
} else {
$currentPage = 1;
}
[$logs, $queryResult] = $this->logRepository->findAllByPid($this->rootPageUid);
$paginator = new \SGalinski\SgRoutes\Paginator\QueryResultRawPaginator($queryResult, $currentPage, 10);
$simplePagination = new SimplePagination($paginator);
$this->view->assign('paginator', $paginator);
$this->view->assign('pagination', $simplePagination);
$this->view->assign('logs', $logs);
$queryResult = $this->logRepository->findAllByPid($this->rootPageUid);
$pagination = GeneralUtility::makeInstance(Pagination::class, $queryResult, $currentPage, 10);
$this->view->assign('pagination', $pagination);
}
$this->view->assign('V11', TRUE);
@@ -552,10 +537,10 @@ class RouteController extends ActionController {
* @throws UnknownObjectException
* @throws StopActionException
*/
public function resetHitsAction(int $routeUid): ?\Psr\Http\Message\ResponseInterface {
public function resetHitsAction(int $routeUid): ?ResponseInterface {
$this->routeRepository->resetHitCountForRoute($routeUid);
return new \TYPO3\CMS\Extbase\Http\ForwardResponse(
return new ForwardResponse(
'list',
'Route',
'SgRoutes',
@@ -682,7 +667,7 @@ class RouteController extends ActionController {
*
* @throws StopActionException
*/
public function activateDemoModeAction(): ?\Psr\Http\Message\ResponseInterface {
public function activateDemoModeAction(): ?ResponseInterface {
if (LicenceCheckService::isInDemoMode() || !LicenceCheckService::isDemoModeAcceptable()) {
return $this->redirect('list');
}
@@ -695,9 +680,9 @@ class RouteController 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());
}
@@ -708,7 +693,7 @@ class RouteController 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);
}
Loading