summaryrefslogtreecommitdiffstats
path: root/settings/ajax/grouplist.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-04-17 18:13:35 +0200
committerArthur Schiwon <blizzz@owncloud.com>2014-06-02 12:53:56 +0200
commit3e411c82a537b5ee0663f1d3a516cdfa93ee4581 (patch)
tree1ff21b23fc528252c7f17a98af889be398b7edcd /settings/ajax/grouplist.php
parentd87347e64ef90b89b1ff2b2221514b6fe1c57086 (diff)
downloadnextcloud-server-3e411c82a537b5ee0663f1d3a516cdfa93ee4581.tar.gz
nextcloud-server-3e411c82a537b5ee0663f1d3a516cdfa93ee4581.zip
unify and consolidate group fetching method for initial template fill and ajax request
Diffstat (limited to 'settings/ajax/grouplist.php')
-rw-r--r--settings/ajax/grouplist.php81
1 files changed, 46 insertions, 35 deletions
diff --git a/settings/ajax/grouplist.php b/settings/ajax/grouplist.php
index 1041d7374e7..ba36dd65bf9 100644
--- a/settings/ajax/grouplist.php
+++ b/settings/ajax/grouplist.php
@@ -30,46 +30,57 @@ if (isset($_GET['pattern']) && !empty($_GET['pattern'])) {
$groups = array();
$adminGroups = array();
$groupManager = \OC_Group::getManager();
+$isAdmin = OC_User::isAdminUser(OC_User::getUser());
+
+//we pass isAdmin as true, because OC_SubAdmin has no search feature,
+//groups will be filtered out later
+$groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), true, $groupManager);
+$groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT);
+list($adminGroup, $groups) = $groupsInfo->get($pattern);
$accessiblegroups = $groupManager->search($pattern);
-if (!OC_User::isAdminUser(OC_User::getUser())) {
+if(!$isAdmin) {
$subadminGroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
- $accessiblegroups = array_intersect($accessiblegroups, $subadminGroups);
-}
-
-$sortGroupsIndex = 0;
-$sortGroupsKeys = array();
-$sortAdminGroupsIndex = 0;
-$sortAdminGroupsKeys = array();
-
-foreach($accessiblegroups as $group) {
- $gid = $group->getGID();
- $usersInGroup = OC_Group::usersInGroup($gid, '');
- if (!OC_User::isAdminUser($gid)) {
- $groups[] = array(
- 'id' => str_replace(' ','', $gid ),
- 'name' => $gid,
- 'usercount' => count($usersInGroup),
- );
- $sortGroupsKeys[$sortGroupsIndex] = count($usersInGroup);
- $sortGroupsIndex++;
- } else {
- $adminGroup[] = array(
- 'id' => str_replace(' ','', $gid ),
- 'name' => $gid,
- 'usercount' => count($usersInGroup)
- );
- $sortAdminGroupsKeys[$sortAdminGroupsIndex] = count($usersInGroup);
- $sortAdminGroupsIndex++;
- }
+ $accessiblegroups = array_intersect($groups, $subadminGroups);
}
-if(!empty($groups)) {
- array_multisort($sortGroupsKeys, SORT_DESC, $groups);
-}
-if(!empty($adminGroup)) {
- array_multisort($sortAdminGroupsKeys, SORT_DESC, $adminGroup);
-}
+// $sortGroupsIndex = 0;
+// $sortGroupsKeys = array();
+// $sortAdminGroupsIndex = 0;
+// $sortAdminGroupsKeys = array();
+//
+// foreach($accessiblegroups as $group) {
+// $gid = $group->getGID();
+// $group = $groupManager->get($gid);
+// if(!$group) {
+// continue;
+// }
+// $usersInGroup = $group->count();
+// if (!OC_User::isAdminUser($gid)) {
+// $groups[] = array(
+// 'id' => str_replace(' ','', $gid ),
+// 'name' => $gid,
+// 'usercount' => $usersInGroup,
+// );
+// $sortGroupsKeys[$sortGroupsIndex] = $usersInGroup;
+// $sortGroupsIndex++;
+// } else {
+// $adminGroup[] = array(
+// 'id' => str_replace(' ','', $gid ),
+// 'name' => $gid,
+// 'usercount' => $usersInGroup
+// );
+// $sortAdminGroupsKeys[$sortAdminGroupsIndex] = $usersInGroup;
+// $sortAdminGroupsIndex++;
+// }
+// }
+//
+// if(!empty($groups)) {
+// array_multisort($sortGroupsKeys, SORT_DESC, $groups);
+// }
+// if(!empty($adminGroup)) {
+// array_multisort($sortAdminGroupsKeys, SORT_DESC, $adminGroup);
+// }
OC_JSON::success(
array('data' => array('adminGroups' => $adminGroups, 'groups' => $groups)));