I18nHandler::getInstance()->register('title');
// get available user groups
- $this->availableUserGroups = UserGroup::getAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS]);
+ $this->availableUserGroups = UserGroup::getSortedAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS]);
if (!count(PaymentMethodHandler::getInstance()->getPaymentMethods())) {
throw new NamedUserException(WCF::getLanguage()->get('wcf.acp.paidSubscription.error.noPaymentMethods'));
* Get a list of available groups.
*/
protected function readGroups() {
- $this->groups = UserGroup::getAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS]);
+ $this->groups = UserGroup::getSortedAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS]);
}
}
* @inheritDoc
*/
public function readData() {
- $this->userGroups = UserGroup::getGroupsByType([], [
+ $this->userGroups = UserGroup::getSortedGroupsByType([], [
UserGroup::EVERYONE,
UserGroup::GUESTS,
UserGroup::OWNER,
}
}
- uasort($this->userGroups, function(UserGroup $groupA, UserGroup $groupB) {
- return strcmp($groupA->getName(), $groupB->getName());
- });
-
$this->conditions = UserGroupAssignmentHandler::getInstance()->getGroupedObjectTypes();
parent::readData();
}
// read accessible groups
- $this->groups = UserGroup::getAccessibleGroups();
+ $this->groups = UserGroup::getSortedAccessibleGroups();
if ($this->userGroupOption->usersOnly) {
$guestGroup = UserGroup::getGroupByType(UserGroup::GUESTS);
if (isset($this->groups[$guestGroup->groupID])) {
throw new IllegalLinkException();
}
- $this->groups = UserGroup::getGroupsByType([UserGroup::OTHER]);
+ $this->groups = UserGroup::getSortedGroupsByType([UserGroup::OTHER]);
$this->groups = array_filter($this->groups, function (UserGroup $group) {
return $group->isAdminGroup();
});
if (empty($this->groups)) {
// fallback for broken installations without an admin group
- $this->groups = UserGroup::getGroupsByType([UserGroup::OTHER]);
+ $this->groups = UserGroup::getSortedGroupsByType([UserGroup::OTHER]);
}
-
- uasort($this->groups, function(UserGroup $a, UserGroup $b) {
- return $a->getName() <=> $b->getName();
- });
}
/**
$this->userList->readObjects();
}
- $this->groups = UserGroup::getAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE]);
+ $this->groups = UserGroup::getSortedAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE]);
}
/**
'customCssClassName' => $this->customCssClassName,
'groupID' => $this->groupID,
'rankTitle' => $this->rankTitle,
- 'availableGroups' => UserGroup::getGroupsByType([], [UserGroup::GUESTS, UserGroup::EVERYONE]),
+ 'availableGroups' => UserGroup::getSortedGroupsByType([], [UserGroup::GUESTS, UserGroup::EVERYONE]),
'requiredPoints' => $this->requiredPoints,
'rankImage' => $this->rankImage,
'repeatImage' => $this->repeatImage,
return $groups;
}
+ /**
+ * Returns a sorted list of groups filtered by given type.
+ *
+ * @param integer[] $types
+ * @param integer[] $invalidGroupTypes
+ * @return UserGroup[]
+ * @since 5.3
+ */
+ public static function getSortedGroupsByType(array $types = [], array $invalidGroupTypes = []) {
+ $userGroups = self::getGroupsByType($types, $invalidGroupTypes);
+
+ self::sortGroups($userGroups);
+
+ return $userGroups;
+ }
+
/**
* Returns unique group by given type. Only works for the default user groups.
*
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());
- });
+ self::sortGroups($userGroups);
return $userGroups;
}
return self::$ownerGroup ? self::$ownerGroup->groupID : null;
}
+
+ /**
+ * Sorts the given user groups alphabetically.
+ *
+ * @param UserGroup[] $userGroups
+ * @since 5.3
+ */
+ public static function sortGroups(array &$userGroups) {
+ uasort($userGroups, function(UserGroup $groupA, UserGroup $groupB) {
+ return strcasecmp($groupA->getName(), $groupB->getName());
+ });
+ }
}
public function __construct(DatabaseObject $object) {
parent::__construct($object);
- $this->availableUserGroups = UserGroup::getAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::OWNER, UserGroup::USERS]);
-
- uasort($this->availableUserGroups, function(UserGroup $groupA, UserGroup $groupB) {
- return strcmp($groupA->getName(), $groupB->getName());
- });
+ $this->availableUserGroups = UserGroup::getSortedAccessibleGroups([], [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::OWNER, UserGroup::USERS]);
}
/**
$invalidGroupTypes[] = UserGroup::GUESTS;
}
- $this->userGroups = UserGroup::getAccessibleGroups([], $invalidGroupTypes);
-
- uasort($this->userGroups, function(UserGroup $groupA, UserGroup $groupB) {
- return strcmp($groupA->getName(), $groupB->getName());
- });
+ $this->userGroups = UserGroup::getSortedAccessibleGroups([], $invalidGroupTypes);
}
return $this->userGroups;
$selectedGroups = explode(',', $value);
// get all groups
- $groups = UserGroup::getGroupsByType();
-
- usort($groups, function(UserGroup $groupA, UserGroup $groupB) {
- return strcasecmp($groupA->getName(), $groupB->getName());
- });
+ $groups = UserGroup::getSortedGroupsByType();
// generate html
$html = '';