Allow filtering of the user rank grid view
authorMarcel Werk <burntime@woltlab.com>
Thu, 7 Nov 2024 12:37:55 +0000 (13:37 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 12 Nov 2024 11:53:43 +0000 (12:53 +0100)
wcfsetup/install/files/lib/system/view/grid/UserRankGridView.class.php

index 5d1a12d05d7279350dbde6d0e5ad8b2050ede3d3..73bd4872532b1c7862fe7dc5fbb045e7923ad304 100644 (file)
@@ -11,6 +11,8 @@ use wcf\event\gridView\UserRankGridViewInitialized;
 use wcf\event\IPsr14Event;
 use wcf\system\view\grid\action\DeleteAction;
 use wcf\system\view\grid\action\EditAction;
+use wcf\system\view\grid\filter\I18nTextFilter;
+use wcf\system\view\grid\filter\SelectFilter;
 use wcf\system\view\grid\renderer\DefaultColumnRenderer;
 use wcf\system\view\grid\renderer\NumberColumnRenderer;
 use wcf\system\view\grid\renderer\TitleColumnRenderer;
@@ -30,6 +32,7 @@ final class UserRankGridView extends DatabaseObjectListGridView
                 ->label('wcf.acp.user.rank.title')
                 ->sortable()
                 ->sortById('rankTitleI18n')
+                ->filter(new I18nTextFilter())
                 ->renderer([
                     new class extends TitleColumnRenderer {
                         public function render(mixed $value, mixed $context = null): string
@@ -58,6 +61,7 @@ final class UserRankGridView extends DatabaseObjectListGridView
             GridViewColumn::for('groupID')
                 ->label('wcf.user.group')
                 ->sortable()
+                ->filter(new SelectFilter($this->getAvailableUserGroups()))
                 ->renderer([
                     new class extends DefaultColumnRenderer {
                         public function render(mixed $value, mixed $context = null): string
@@ -116,4 +120,14 @@ final class UserRankGridView extends DatabaseObjectListGridView
     {
         return new UserRankGridViewInitialized($this);
     }
+
+    private function getAvailableUserGroups(): array
+    {
+        $groups = [];
+        foreach (UserGroup::getSortedGroupsByType([], [UserGroup::GUESTS, UserGroup::EVERYONE]) as $group) {
+            $groups[$group->groupID] = $group->getName();
+        }
+
+        return $groups;
+    }
 }