Project

General

Profile

Feature #91890 ยป redirects-ordering.patch

Patch file for TYPO3 9.5.20 - Benjamin Serfhos, 2020-08-14 14:37

View differences:

Classes/Repository/Demand.php
*/
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
/**
* Demand Object for filtering redirects in the backend module
......
*/
class Demand
{
public const DEFAULT_ORDERING = 'source_path';
/**
* @var string
*/
protected $orderField;
/**
* @var string
*/
protected $orderDirection;
/**
* @var string
*/
......
/**
* 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;
......
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;
}
/**
Classes/Repository/RedirectRepository.php
->select('*')
->from('sys_redirect')
->orderBy('source_host')
->addOrderBy('source_path');
->addOrderBy($this->demand->getOrderField(), $this->demand->getOrderDirection());
$constraints = [];
if ($this->demand->hasSourceHost()) {
Resources/Private/Templates/Management/Overview.html
<thead>
<tr>
<th><f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:source_host"/></th>
<th><f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:source_path"/></th>
<th><f:render section="listHeaderSorting" arguments="{field: 'source_path', label: 'source_path', demand: demand}"/></th>
<th><f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:destination"/></th>
<f:if condition="{showHitCounter}">
<th># <f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:hits"/></th>
<th><f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:hit_last"/></th>
<th><f:render section="listHeaderSorting" arguments="{field: 'hitcount', label: 'hits', demand: demand}"/></th>
<th><f:render section="listHeaderSorting" arguments="{field: 'lasthiton', label: 'hit_last', demand: demand}"/></th>
</f:if>
<th></th>
</tr>
......
<f:render partial="Pagination" arguments="{_all}" />
</f:section>
<f:section name="listHeaderSorting">
<f:if condition="{demand.orderField} == {field} && {demand.orderDirection} == 'ASC'">
<f:then>
<a href="{f:be.uri(route:'site_redirects', parameters: '{action: \'overview\', orderField: field, orderDirection: \'DESC\'}')}"
><f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:{label}"/></a>
<core:icon identifier="status-status-sorting-desc"/>
</f:then>
<f:else>
<a href="{f:be.uri(route:'site_redirects', parameters: '{action: \'overview\', orderField: field, orderDirection: \'ASC\'}')}"
><f:translate key="LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:{label}"/></a>
<core:icon identifier="status-status-sorting-asc"/>
</f:else>
</f:if>
</f:section>
<f:section name="filter">
<form action="{f:be.uri(route:'site_redirects', parameters: '{action: \'overview\'}')}"
method="post"
    (1-1/1)