Introduced SortablePage::$validSortFields
authorMatthias Schmidt <gravatronics@live.com>
Thu, 28 Jul 2011 12:45:29 +0000 (14:45 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 28 Jul 2011 12:45:29 +0000 (14:45 +0200)
With the new property SortablePage::$validSortFields many classes don't
need to overwrite SortablePage::validateSortField(), the valid sort
fields just need to be added to the SortablePage::$validSortFields
array. It also makes it easier for plugins to add new valid sort fields.

wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php
wcfsetup/install/files/lib/acp/page/ACPSessionLogPage.class.php
wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php
wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php
wcfsetup/install/files/lib/acp/page/PackageListPage.class.php
wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php
wcfsetup/install/files/lib/acp/page/UpdateServerListPage.class.php
wcfsetup/install/files/lib/acp/page/UserGroupListPage.class.php
wcfsetup/install/files/lib/acp/page/UserListPage.class.php
wcfsetup/install/files/lib/page/SortablePage.class.php

index f18871efe28babcec633aa3c4c64d0df95f77747..2947dd45bed938e826bc16bcb7b98901714e5f05 100755 (executable)
@@ -35,6 +35,11 @@ class ACPSessionLogListPage extends SortablePage {
         */
        public $defaultSortOrder = 'DESC';
        
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('sessionLogID', 'username', 'ipAddress', 'userAgent', 'time', 'lastActivityTime', 'accesses');
+       
        /**
         * @see wcf\page\MultipleLinkPage::$objectListClassName
         */
@@ -49,24 +54,6 @@ class ACPSessionLogListPage extends SortablePage {
                parent::readObjects();
        }
        
-       /**
-        * @see wcf\page\SortablePage::validateSortField()
-        */
-       public function validateSortField() {
-               parent::validateSortField();
-               
-               switch ($this->sortField) {
-                       case 'sessionLogID':
-                       case 'username':
-                       case 'ipAddress':
-                       case 'userAgent':
-                       case 'time':
-                       case 'lastActivityTime':
-                       case 'accesses': break;
-                       default: $this->sortField = $this->defaultSortField;
-               }
-       }
-       
        /**
         * @see wcf\page\IPage::assignVariables()
         */
index 96997e7a2a354735357c7eb355f6195f2df6696c..9e668ce9b483a457feb5f478aeef6958dd93c618 100755 (executable)
@@ -32,6 +32,11 @@ class ACPSessionLogPage extends SortablePage {
         */
        public $defaultSortField = 'time';
        
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('sessionAccessLogID', 'ipAddress', 'time', 'requestURI', 'requestMethod', 'className', 'packageName');
+       
        /**
         * session log id
         * @var integer
@@ -81,24 +86,6 @@ class ACPSessionLogPage extends SortablePage {
                parent::readObjects();
        }
        
-       /**
-        * @see wcf\page\SortablePage::validateSortField()
-        */
-       public function validateSortField() {
-               parent::validateSortField();
-               
-               switch ($this->sortField) {
-                       case 'sessionAccessLogID':
-                       case 'ipAddress':
-                       case 'time':
-                       case 'requestURI':
-                       case 'requestMethod':
-                       case 'className':
-                       case 'packageName': break;
-                       default: $this->sortField = $this->defaultSortField;
-               }
-       }
-       
        /**
         * @see wcf\page\IPage::assignVariables()
         */
index 18072b59847b7341a9eca949b5700b3fc30ce34b..fedb95ddb46a3b2f0a77d5674565681d525e5176 100755 (executable)
@@ -31,6 +31,11 @@ class CronjobListPage extends SortablePage {
         */
        public $defaultSortField = 'description';
        
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('description', 'cronjobID', 'nextExec', 'startMinute', 'startHour', 'startDom', 'startMonth', 'startDow');
+       
        /**
         * @see wcf\page\MultipleLinkPage::$objectListClassName
         */     
@@ -57,25 +62,6 @@ class CronjobListPage extends SortablePage {
                ));
        }
        
-       /**
-        * @see wcf\page\SortablePage::validateSortField()
-        */
-       public function validateSortField() {
-               parent::validateSortField();
-               
-               switch ($this->sortField) {
-                       case 'description':
-                       case 'cronjobID':
-                       case 'nextExec':
-                       case 'startMinute':
-                       case 'startHour':
-                       case 'startDom':
-                       case 'startMonth':
-                       case 'startDow': break;
-                       default: $this->sortField = $this->defaultSortField;
-               }
-       }
-       
        /**
         * @see wcf\page\IPage::show()
         */
index a95cc05904d877f9c2441f01ac9269eb55f4d687..47edfcadcf511fa15f5b30070558ad16cbc9de8c 100755 (executable)
@@ -40,6 +40,11 @@ class CronjobLogListPage extends SortablePage {
         * @see wcf\page\SortablePage::$defaultSortOrder
         */
        public $defaultSortOrder = 'DESC';
+
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('cronjobID', 'classPath', 'description', 'execTime', 'success');
        
        /**
         * @see wcf\page\MultipleLinkPage::$objectListClassName
@@ -77,22 +82,6 @@ class CronjobLogListPage extends SortablePage {
                ));
        }
        
-       /**
-        * @see wcf\page\SortablePage::validateSortField()
-        */
-       public function validateSortField() {
-               parent::validateSortField();
-               
-               switch ($this->sortField) {
-                       case 'cronjobID':
-                       case 'classPath':
-                       case 'description':
-                       case 'execTime':
-                       case 'success': break;
-                       default: $this->sortField = $this->defaultSortField;
-               }
-       }
-       
        /**
         * @see wcf\page\IPage::show()
         */
index a5c2a24d40df3321fa8fd767660dcddc0b6db813..39062d439394d482820569b1273f884ef97de197 100755 (executable)
@@ -41,6 +41,11 @@ class PackageListPage extends SortablePage {
         */
        public $defaultSortOrder = 'DESC';
        
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('packageID', 'package', 'packageDir', 'packageName', 'instanceNo', 'packageDescription', 'packageVersion', 'packageDate', 'packageURL', 'parentPackageID', 'isUnique', 'standalone', 'author', 'authorURL', 'installDate', 'updateDate');
+       
        /**
         * @see wcf\page\MultipleLinkPage::$objectListClassName
         */     
@@ -73,31 +78,4 @@ class PackageListPage extends SortablePage {
                
                parent::show();
        }
-       
-       /**
-        * @see wcf\page\SortablePage::validateSortField()
-        */
-       public function validateSortField() {
-               parent::validateSortField();
-               
-               switch ($this->sortField) {
-                       case 'packageID':
-                       case 'package':
-                       case 'packageDir':
-                       case 'packageName':
-                       case 'instanceNo':
-                       case 'packageDescription':
-                       case 'packageVersion':
-                       case 'packageDate':
-                       case 'packageURL':
-                       case 'parentPackageID':
-                       case 'isUnique':
-                       case 'standalone':
-                       case 'author':
-                       case 'authorURL':
-                       case 'installDate':
-                       case 'updateDate': break;
-                       default: $this->sortField = $this->defaultSortField;
-               }
-       }
 }
index ef4db2063f733e9a928bc9f6e9e371e67d80b9f6..b30e457c00ec98bf761d1e018b17007f7b2ea23f 100755 (executable)
@@ -34,6 +34,11 @@ class PackageUpdateSearchResultPage extends SortablePage {
         */
        public $defaultSortField = 'packageName';
        
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('package', 'packageName', 'author');
+       
        /**
         * id of the package update search
         * @var integer
@@ -105,20 +110,6 @@ class PackageUpdateSearchResultPage extends SortablePage {
                return $row['count'];
        }
        
-       /**
-        * @see wcf\page\SortablePage::validateSortField()
-        */
-       public function validateSortField() {
-               parent::validateSortField();
-               
-               switch ($this->sortField) {
-                       case 'package':
-                       case 'packageName':
-                       case 'author': break;
-                       default: $this->sortField = $this->defaultSortField;
-               }
-       }
-       
        /**
         * Gets a list of packages.
         */
index 1fdb8be7a8c57741c5bee65f0e918fb855747a01..f2f76e8e35669ad93828a917424362db96ee5d45 100755 (executable)
@@ -30,6 +30,11 @@ class UpdateServerListPage extends SortablePage {
         */
        public $defaultSortField = 'serverURL';
        
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('packageUpdateServerID', 'serverURL', 'status', 'errorMessage', 'lastUpdateTime', 'packages');
+       
        /**
         * @see wcf\page\MultipleLinkPage::$objectListClassName
         */     
@@ -80,21 +85,4 @@ class UpdateServerListPage extends SortablePage {
                
                parent::show();
        }
-       
-       /**
-        * @see wcf\page\SortablePage::validateSortField()
-        */
-       public function validateSortField() {
-               parent::validateSortField();
-               
-               switch ($this->sortField) {
-                       case 'packageUpdateServerID':
-                       case 'serverURL':
-                       case 'status':
-                       case 'errorMessage':
-                       case 'lastUpdateTime':
-                       case 'packages': break;
-                       default: $this->sortField = $this->defaultSortField;
-               }
-       }
 }
index 2a1d19bb84ed97785b663a391e7e88e6b68a1629..128f69751c90e19403e1f3a6aaf6066e8b9a9ba4 100755 (executable)
@@ -30,6 +30,11 @@ class UserGroupListPage extends SortablePage {
         */
        public $defaultSortField = 'groupName';
        
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('groupID', 'groupName', 'groupType', 'members');
+       
        /**
         * @see wcf\page\MultipleLinkPage::$objectListClassName
         */     
@@ -53,21 +58,6 @@ class UserGroupListPage extends SortablePage {
                }
        }
        
-       /**
-        * @see wcf\page\SortablePage::validateSortField()
-        */
-       public function validateSortField() {
-               parent::validateSortField();
-               
-               switch ($this->sortField) {
-                       case 'groupID':
-                       case 'groupName':
-                       case 'groupType':
-                       case 'members': break;
-                       default: $this->sortField = $this->defaultSortField;
-               }
-       }
-       
        /**
         * @see wcf\page\MultipleLinkPage::initObjectList()
         */     
index 3b82442f0b2db530cac1a38c80ddcbc29113cea1..b79e06bd8c900e3df98d7c8fe65da2489bf60f0e 100755 (executable)
@@ -42,6 +42,11 @@ class UserListPage extends SortablePage {
         */
        public $defaultSortField = 'username';
        
+       /**
+        * @see wcf\page\SortablePage::$validSortFields
+        */
+       public $validSortFields = array('email', 'userID', 'registrationDate', 'username');
+       
        /**
         * id of a user search
         * @var integer
@@ -85,18 +90,10 @@ class UserListPage extends SortablePage {
         * @see wcf\page\SortablePage::validateSortField()
         */
        public function validateSortField() {
-               parent::validateSortField();
+               // add options to valid sort fields
+               $this->validSortFields = array_merge($this->validSortFields, array_keys($this->options));
                
-               switch ($this->sortField) {
-                       case 'email':
-                       case 'userID':
-                       case 'registrationDate':
-                       case 'username': break;
-                       default: 
-                               if (!isset($this->options[$this->sortField])) {
-                                       $this->sortField = $this->defaultSortField;
-                               }
-               }
+               parent::validateSortField();
        }
        
        /**
index 8fc8cba78ea08e1f2b54894482fc8a88e352feec..c9c09f4a104d81eefd4a4eb432a1aca6bf35ac79 100644 (file)
@@ -39,6 +39,12 @@ abstract class SortablePage extends MultipleLinkPage {
         */
        public $defaultSortOrder = 'ASC';
        
+       /**
+        * list of valid sort fields
+        * @var array<string>
+        */
+       public $validSortFields = array();
+       
        /**
         * @see wcf\page\IPage::readParameters()
         */
@@ -66,6 +72,10 @@ abstract class SortablePage extends MultipleLinkPage {
        public function validateSortField() {
                // call validateSortField event
                EventHandler::getInstance()->fireAction($this, 'validateSortField');
+               
+               if (!in_array($this->sortField, $this->validSortFields)) {
+                       $this->sortField = $this->defaultSortField;
+               }
        }
        
        /**