From: Marcel Werk Date: Mon, 15 Apr 2019 09:44:19 +0000 (+0200) Subject: Improved sorting in user grop dropdown X-Git-Tag: 5.2.0_Alpha_1~141 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ee05a3cbf30816a99cef8177ba7fec58d3c9cfa0;p=GitHub%2FWoltLab%2FWCF.git Improved sorting in user grop dropdown --- diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php index 8faefff4b6..ebd0c31862 100755 --- a/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php @@ -120,7 +120,7 @@ class UserGroupEditForm extends UserGroupAddForm { 'groupID' => $this->group->groupID, 'group' => $this->group, 'action' => 'edit', - 'availableUserGroups' => UserGroup::getAccessibleGroups(), + 'availableUserGroups' => UserGroup::getSortedAccessibleGroups(), 'groupIsEveryone' => $this->group->groupType == UserGroup::EVERYONE, 'groupIsGuest' => $this->group->groupType == UserGroup::GUESTS, 'groupIsUsers' => $this->group->groupType == UserGroup::USERS, diff --git a/wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php b/wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php index 0bc5c65691..1bc5921f0b 100644 --- a/wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php @@ -26,21 +26,10 @@ abstract class UserOptionListForm extends AbstractOptionListForm { /** * Returns a list of all available user groups. * - * @return array + * @return UserGroup[] */ protected function getAvailableGroups() { - $userGroups = UserGroup::getAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS]); - - // work-around for PHP 5.3.3 randomly failing in uasort() - foreach ($userGroups as $userGroup) { - $userGroup->getName(); - } - - uasort($userGroups, function(UserGroup $groupA, UserGroup $groupB) { - return strcasecmp($groupA->getName(), $groupB->getName()); - }); - - return $userGroups; + return UserGroup::getSortedAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS]); } /** diff --git a/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php b/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php index 85d2e0b42c..0d53c3a36e 100755 --- a/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php @@ -222,14 +222,8 @@ class UserSearchForm extends UserOptionListForm { // manually inject user group data for listing of group members if ($this->groupID && $objectType->objectType == 'com.woltlab.wcf.userGroup') { + $userGroups = UserGroup::getSortedAccessibleGroups([], [UserGroup::EVERYONE, UserGroup::GUESTS]); /** @var UserGroupCondition $processor */ - - $userGroups = UserGroup::getAccessibleGroups([], [UserGroup::EVERYONE, UserGroup::GUESTS]); - - uasort($userGroups, function(UserGroup $groupA, UserGroup $groupB) { - return strcmp($groupA->getName(), $groupB->getName()); - }); - $processor->setUserGroups($userGroups); $processor->setData(new Condition(null, [ 'conditionData' => serialize(['groupIDs' => [$this->groupID]]) diff --git a/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php b/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php index abf5f314c6..4d50d20927 100644 --- a/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php +++ b/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php @@ -238,6 +238,24 @@ class UserGroup extends DatabaseObject implements ITitledObject { return $groups; } + /** + * Returns a sorted list of accessible groups. + * + * @param integer[] $groupTypes + * @param integer[] $invalidGroupTypes + * @return UserGroup[] + * @since 5.2 + */ + public static function getSortedAccessibleGroups(array $groupTypes = [], array $invalidGroupTypes = []) { + $userGroups = self::getAccessibleGroups($groupTypes, $invalidGroupTypes); + + uasort($userGroups, function(UserGroup $groupA, UserGroup $groupB) { + return strcasecmp($groupA->getName(), $groupB->getName()); + }); + + return $userGroups; + } + /** * Returns true if the current group is an admin-group. * Every group that may access EVERY group is an admin-group.