From 5f48b20d7b6ab1627f08823d140c6f6dadd2e322 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 6 Jul 2021 09:12:34 +0200 Subject: [PATCH] Support sorting users in `UserOnlineListBoxController` (#4372) Close #4182 --- .../box/UserOnlineListBoxController.class.php | 26 +++++++++++++++++++ wcfsetup/install/lang/de.xml | 3 +++ wcfsetup/install/lang/en.xml | 3 +++ 3 files changed, 32 insertions(+) diff --git a/wcfsetup/install/files/lib/system/box/UserOnlineListBoxController.class.php b/wcfsetup/install/files/lib/system/box/UserOnlineListBoxController.class.php index 03f61bf2ec..677a4c5cd5 100644 --- a/wcfsetup/install/files/lib/system/box/UserOnlineListBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/UserOnlineListBoxController.class.php @@ -30,18 +30,38 @@ class UserOnlineListBoxController extends AbstractDatabaseObjectListBoxControlle */ protected $conditionDefinition = 'com.woltlab.wcf.box.userOnlineList.condition'; + /** + * @inheritDoc + */ + public $defaultSortField = USERS_ONLINE_DEFAULT_SORT_FIELD; + + /** + * @inheritDoc + */ + public $defaultSortOrder = USERS_ONLINE_DEFAULT_SORT_ORDER; + /** * enables the display of the user online record * @var bool */ public $showRecord = true; + /** + * @inheritDoc + */ + protected $sortFieldLanguageItemPrefix = 'wcf.user.usersOnline.sortField'; + /** * phrase that is used for the box title * @var string|null */ public $title; + /** + * @inheritDoc + */ + public $validSortFields = ['username', 'lastActivityTime', 'requestURI']; + /** * @inheritDoc */ @@ -65,6 +85,12 @@ class UserOnlineListBoxController extends AbstractDatabaseObjectListBoxControlle { EventHandler::getInstance()->fireAction($this, 'readObjects'); + if ($this->sortOrder && $this->sortField === 'lastActivityTime') { + $alias = $this->objectList->getDatabaseTableAlias(); + $this->objectList->sqlOrderBy = "session.{$this->sortField} {$this->sortOrder}, " + . ($alias ? $alias . "." : "") . "{$this->objectList->getDatabaseTableIndexName()} {$this->sortOrder}"; + } + $this->objectList->readStats(); if ($this->showRecord) { $this->objectList->checkRecord(); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index dd50f8c730..51bc5b9996 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -5105,6 +5105,9 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}. + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 3a739d372f..59c6153fe4 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -5102,6 +5102,9 @@ You also received a list of emergency codes to use when your second factor becom + + + -- 2.20.1