From: Matthias Schmidt Date: Thu, 28 Jul 2011 12:45:29 +0000 (+0200) Subject: Introduced SortablePage::$validSortFields X-Git-Tag: 2.0.0_Beta_1~1930^2~10^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e34164d26d3f9ef0b4b8f52e68573bffb992f052;p=GitHub%2FWoltLab%2FWCF.git Introduced SortablePage::$validSortFields 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. --- diff --git a/wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php b/wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php index f18871efe2..2947dd45be 100755 --- a/wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/ACPSessionLogListPage.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/acp/page/ACPSessionLogPage.class.php b/wcfsetup/install/files/lib/acp/page/ACPSessionLogPage.class.php index 96997e7a2a..9e668ce9b4 100755 --- a/wcfsetup/install/files/lib/acp/page/ACPSessionLogPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/ACPSessionLogPage.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php b/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php index 18072b5984..fedb95ddb4 100755 --- a/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php b/wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php index a95cc05904..47edfcadcf 100755 --- a/wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/acp/page/PackageListPage.class.php b/wcfsetup/install/files/lib/acp/page/PackageListPage.class.php index a5c2a24d40..39062d4393 100755 --- a/wcfsetup/install/files/lib/acp/page/PackageListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/PackageListPage.class.php @@ -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; - } - } } diff --git a/wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php b/wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php index ef4db2063f..b30e457c00 100755 --- a/wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php @@ -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. */ diff --git a/wcfsetup/install/files/lib/acp/page/UpdateServerListPage.class.php b/wcfsetup/install/files/lib/acp/page/UpdateServerListPage.class.php index 1fdb8be7a8..f2f76e8e35 100755 --- a/wcfsetup/install/files/lib/acp/page/UpdateServerListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UpdateServerListPage.class.php @@ -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; - } - } } diff --git a/wcfsetup/install/files/lib/acp/page/UserGroupListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserGroupListPage.class.php index 2a1d19bb84..128f69751c 100755 --- a/wcfsetup/install/files/lib/acp/page/UserGroupListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserGroupListPage.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php index 3b82442f0b..b79e06bd8c 100755 --- a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php @@ -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(); } /** diff --git a/wcfsetup/install/files/lib/page/SortablePage.class.php b/wcfsetup/install/files/lib/page/SortablePage.class.php index 8fc8cba78e..c9c09f4a10 100644 --- a/wcfsetup/install/files/lib/page/SortablePage.class.php +++ b/wcfsetup/install/files/lib/page/SortablePage.class.php @@ -39,6 +39,12 @@ abstract class SortablePage extends MultipleLinkPage { */ public $defaultSortOrder = 'ASC'; + /** + * list of valid sort fields + * @var array + */ + 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; + } } /**