Improved sorting in user grop dropdown
authorMarcel Werk <burntime@woltlab.com>
Mon, 15 Apr 2019 09:44:19 +0000 (11:44 +0200)
committerMarcel Werk <burntime@woltlab.com>
Mon, 15 Apr 2019 09:44:19 +0000 (11:44 +0200)
wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php
wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php
wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php
wcfsetup/install/files/lib/data/user/group/UserGroup.class.php

index 8faefff4b69ddba20e62109a8bd2b81d99096eb2..ebd0c31862fc5e27372ed1db467a63b7f5a37b86 100755 (executable)
@@ -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,
index 0bc5c656916d918ef165eb1fa975b18b328e8873..1bc5921f0b392570c3401e029322abd042b76e62 100644 (file)
@@ -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]);
        }
        
        /**
index 85d2e0b42c0e8a3eccea5743bf506f6415c36efb..0d53c3a36e8803a543f5a95192e5ecb07e1f52dc 100755 (executable)
@@ -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]])
index abf5f314c6644a45b693921c01a226fead8740dc..4d50d2092726b751e99c5c0a08293fa08766ad46 100644 (file)
@@ -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.