From 866061dbc010d798130e84067f825961185f681a Mon Sep 17 00:00:00 2001 From: Benjamin Serfhos Date: Thu, 13 Aug 2020 11:20:51 +0200 Subject: [PATCH] [FEATURE] Allow ordering of displayed columns in redirects overview Releases: master Resolves: #91890 Change-Id: I64d7a355ca4e88b4f73c4cb46fce60ca7b0605c6 --- ...1890-ColumnOrderingInRedirectsOverview.rst | 15 ++++++ .../redirects/Classes/Repository/Demand.php | 50 +++++++++++++++++-- .../Classes/Repository/RedirectRepository.php | 2 +- .../Templates/Management/Overview.html | 21 ++++++-- 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/Classes/Repository/Demand.php b/Classes/Repository/Demand.php index 0492704dfc..d3ce92e00d 100644 --- a/Classes/Repository/Demand.php +++ b/Classes/Repository/Demand.php @@ -16,6 +16,7 @@ namespace TYPO3\CMS\Redirects\Repository; */ use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Extbase\Persistence\QueryInterface; /** * Demand Object for filtering redirects in the backend module @@ -23,6 +24,18 @@ use Psr\Http\Message\ServerRequestInterface; */ class Demand { + public const DEFAULT_ORDERING = 'source_path'; + + /** + * @var string + */ + protected $orderField; + + /** + * @var string + */ + protected $orderDirection; + /** * @var string */ @@ -56,14 +69,25 @@ class Demand /** * Demand constructor. * @param int $page + * @param string $orderField + * @param string $orderDirection * @param string $sourceHost * @param string $sourcePath * @param string $target * @param int $statusCode */ - public function __construct(int $page = 1, string $sourceHost = '', string $sourcePath = '', string $target = '', int $statusCode = 0) - { + public function __construct( + int $page = 1, + string $orderField = self::DEFAULT_ORDERING, + string $orderDirection = QueryInterface::ORDER_ASCENDING, + string $sourceHost = '', + string $sourcePath = '', + string $target = '', + int $statusCode = 0 + ) { $this->page = $page; + $this->orderField = $orderField; + $this->orderDirection = $orderDirection; $this->sourceHost = $sourceHost; $this->sourcePath = $sourcePath; $this->target = $target; @@ -79,15 +103,33 @@ class Demand public static function createFromRequest(ServerRequestInterface $request): Demand { $page = (int)($request->getQueryParams()['page'] ?? $request->getParsedBody()['page'] ?? 1); + $orderField = $request->getQueryParams()['orderField'] ?? self::DEFAULT_ORDERING; + $orderDirection = $request->getQueryParams()['orderDirection'] ?? QueryInterface::ORDER_ASCENDING; $demand = $request->getQueryParams()['demand'] ?? $request->getParsedBody()['demand']; if (empty($demand)) { - return new self($page); + return new self($page, $orderField, $orderDirection); } $sourceHost = $demand['source_host'] ?? ''; $sourcePath = $demand['source_path'] ?? ''; $statusCode = (int)($demand['target_statuscode'] ?? 0); $target = $demand['target'] ?? ''; - return new self($page, $sourceHost, $sourcePath, $target, $statusCode); + return new self($page, $orderField, $orderDirection, $sourceHost, $sourcePath, $target, $statusCode); + } + + /** + * @return string + */ + public function getOrderField(): string + { + return $this->orderField; + } + + /** + * @return string + */ + public function getOrderDirection(): string + { + return $this->orderDirection; } /** diff --git a/Classes/Repository/RedirectRepository.php b/Classes/Repository/RedirectRepository.php index 3a8b82931b..6ad61630e9 100644 --- a/Classes/Repository/RedirectRepository.php +++ b/Classes/Repository/RedirectRepository.php @@ -75,7 +75,7 @@ class RedirectRepository ->select('*') ->from('sys_redirect') ->orderBy('source_host') - ->addOrderBy('source_path'); + ->addOrderBy($this->demand->getOrderField(), $this->demand->getOrderDirection()); $constraints = []; if ($this->demand->hasSourceHost()) { diff --git a/Resources/Private/Templates/Management/Overview.html b/Resources/Private/Templates/Management/Overview.html index 507eade94b..3961f6fc8d 100644 --- a/Resources/Private/Templates/Management/Overview.html +++ b/Resources/Private/Templates/Management/Overview.html @@ -49,11 +49,11 @@ - + - # - + + @@ -149,6 +149,21 @@ + + + + + + + + + + + + +