Improve creation of the dbo object list
authorMarcel Werk <burntime@woltlab.com>
Thu, 19 Sep 2024 14:04:27 +0000 (16:04 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 12 Nov 2024 11:51:53 +0000 (12:51 +0100)
wcfsetup/install/files/lib/system/view/grid/DatabaseObjectListGridView.class.php
wcfsetup/install/files/lib/system/view/grid/UserRankGridView.class.php

index 4cba1e49fa6bbae0b6ff5090665a6ee43b4c9d46..2fb9027e9983a7379415901894514ea17606ae6a 100644 (file)
@@ -4,12 +4,9 @@ namespace wcf\system\view\grid;
 
 use wcf\data\DatabaseObject;
 use wcf\data\DatabaseObjectList;
-use wcf\system\exception\ParentClassException;
-use wcf\system\exception\SystemException;
 
 abstract class DatabaseObjectListGridView extends AbstractGridView
 {
-    protected string $objectListClassName;
     protected DatabaseObjectList $objectList;
     private int $objectCount;
 
@@ -38,15 +35,7 @@ abstract class DatabaseObjectListGridView extends AbstractGridView
 
     protected function initObjectList(): void
     {
-        if (!isset($this->objectListClassName)) {
-            throw new SystemException('Database object list class name not specified.');
-        }
-
-        if (!\is_subclass_of($this->objectListClassName, DatabaseObjectList::class)) {
-            throw new ParentClassException($this->objectListClassName, DatabaseObjectList::class);
-        }
-
-        $this->objectList = new $this->objectListClassName;
+        $this->objectList = $this->createObjectList();
         $this->objectList->sqlLimit = $this->getRowsPerPage();
         $this->objectList->sqlOffset = ($this->getPageNo() - 1) * $this->getRowsPerPage();
         if ($this->getSortField()) {
@@ -62,4 +51,6 @@ abstract class DatabaseObjectListGridView extends AbstractGridView
 
         return $this->objectList;
     }
+
+    protected abstract function createObjectList(): DatabaseObjectList;
 }
index 1389c7e5d644b9a49a6cdf0edb8cb5108228b9e9..892a495c1152dcfca9acbdbf45b9764e75ae6bb0 100644 (file)
@@ -3,6 +3,7 @@
 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\UserRank;
 use wcf\data\user\rank\UserRankList;
@@ -15,8 +16,6 @@ use wcf\util\StringUtil;
 
 final class UserRankGridView extends DatabaseObjectListGridView
 {
-    protected string $objectListClassName = UserRankList::class;
-
     #[\Override]
     protected function init(): void
     {
@@ -93,8 +92,15 @@ final class UserRankGridView extends DatabaseObjectListGridView
         $this->setSortField('rankTitle');
     }
 
+    #[\Override]
     public function isAccessible(): bool
     {
         return \MODULE_USER_RANK && WCF::getSession()->getPermission('admin.user.rank.canManageRank');
     }
+
+    #[\Override]
+    protected function createObjectList(): DatabaseObjectList
+    {
+        return new UserRankList();
+    }
 }