From 5e022dddde3ba9dd6408f25fbbbdc09ca7932941 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 20 Sep 2024 15:34:18 +0200 Subject: [PATCH] Handle I18n sorting --- .../lib/system/view/grid/AbstractGridView.class.php | 11 +++++++++++ .../view/grid/DatabaseObjectListGridView.class.php | 7 ++++++- .../lib/system/view/grid/GridViewColumn.class.php | 13 +++++++++++++ .../lib/system/view/grid/UserRankGridView.class.php | 5 +++-- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php b/wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php index 9e23dbba0e..c03223c5f6 100644 --- a/wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php +++ b/wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php @@ -43,6 +43,17 @@ abstract class AbstractGridView return $this->columns; } + public function getColumn(string $id): ?GridViewColumn + { + foreach ($this->getColumns() as $column) { + if ($column->getID() === $id) { + return $column; + } + } + + return null; + } + public function render(): string { return WCF::getTPL()->fetch('shared_gridView', 'wcf', ['view' => $this], true); diff --git a/wcfsetup/install/files/lib/system/view/grid/DatabaseObjectListGridView.class.php b/wcfsetup/install/files/lib/system/view/grid/DatabaseObjectListGridView.class.php index 2fb9027e99..1d8fb364e4 100644 --- a/wcfsetup/install/files/lib/system/view/grid/DatabaseObjectListGridView.class.php +++ b/wcfsetup/install/files/lib/system/view/grid/DatabaseObjectListGridView.class.php @@ -39,7 +39,12 @@ abstract class DatabaseObjectListGridView extends AbstractGridView $this->objectList->sqlLimit = $this->getRowsPerPage(); $this->objectList->sqlOffset = ($this->getPageNo() - 1) * $this->getRowsPerPage(); if ($this->getSortField()) { - $this->objectList->sqlOrderBy = $this->getSortField() . ' ' . $this->getSortOrder(); + $column = $this->getColumn($this->getSortField()); + if ($column && $column->getSortById()) { + $this->objectList->sqlOrderBy = $column->getSortById() . ' ' . $this->getSortOrder(); + } else { + $this->objectList->sqlOrderBy = $this->getSortField() . ' ' . $this->getSortOrder(); + } } } diff --git a/wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php b/wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php index bd0fb3ca6f..2200deabc0 100644 --- a/wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php +++ b/wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php @@ -15,6 +15,7 @@ final class GridViewColumn private string $label = ''; private static DefaultColumnRenderer $defaultRenderer; private bool $sortable = false; + private string $sortById = ''; private function __construct(private readonly string $id) {} @@ -78,6 +79,13 @@ final class GridViewColumn return $this; } + public function sortById(string $id): static + { + $this->sortById = $id; + + return $this; + } + /** * @return IColumnRenderer[] */ @@ -101,6 +109,11 @@ final class GridViewColumn return $this->sortable; } + public function getSortById(): string + { + return $this->sortById; + } + private static function getDefaultRenderer(): DefaultColumnRenderer { if (!isset(self::$defaultRenderer)) { diff --git a/wcfsetup/install/files/lib/system/view/grid/UserRankGridView.class.php b/wcfsetup/install/files/lib/system/view/grid/UserRankGridView.class.php index 892a495c11..3b90e362a4 100644 --- a/wcfsetup/install/files/lib/system/view/grid/UserRankGridView.class.php +++ b/wcfsetup/install/files/lib/system/view/grid/UserRankGridView.class.php @@ -5,8 +5,8 @@ namespace wcf\system\view\grid; use wcf\acp\form\UserRankEditForm; use wcf\data\DatabaseObjectList; use wcf\data\user\group\UserGroup; +use wcf\data\user\rank\I18nUserRankList; use wcf\data\user\rank\UserRank; -use wcf\data\user\rank\UserRankList; use wcf\system\view\grid\renderer\DefaultColumnRenderer; use wcf\system\view\grid\renderer\LinkColumnRenderer; use wcf\system\view\grid\renderer\NumberColumnRenderer; @@ -27,6 +27,7 @@ final class UserRankGridView extends DatabaseObjectListGridView GridViewColumn::for('rankTitle') ->label('wcf.acp.user.rank.title') ->sortable() + ->sortById('rankTitleI18n') ->renderer([ new class extends TitleColumnRenderer { public function render(mixed $value, mixed $context = null): string @@ -101,6 +102,6 @@ final class UserRankGridView extends DatabaseObjectListGridView #[\Override] protected function createObjectList(): DatabaseObjectList { - return new UserRankList(); + return new I18nUserRankList(); } } -- 2.20.1