diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-04-17 20:13:35 +0400 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-06-02 14:53:56 +0400 |
commit | 3e411c82a537b5ee0663f1d3a516cdfa93ee4581 (patch) | |
tree | 1ff21b23fc528252c7f17a98af889be398b7edcd | |
parent | d87347e64ef90b89b1ff2b2221514b6fe1c57086 (diff) |
unify and consolidate group fetching method for initial template fill and ajax request
-rw-r--r-- | settings/ajax/grouplist.php | 81 | ||||
-rw-r--r-- | settings/templates/users/part.grouplist.php | 6 | ||||
-rw-r--r-- | settings/users.php | 50 |
3 files changed, 56 insertions, 81 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))); diff --git a/settings/templates/users/part.grouplist.php b/settings/templates/users/part.grouplist.php index 0d5fef7775c..5b9d23e43ad 100644 --- a/settings/templates/users/part.grouplist.php +++ b/settings/templates/users/part.grouplist.php @@ -28,21 +28,21 @@ <li data-gid="admin"> <a href="#"><?php p($l->t('Admins')); ?></a> <span class="utils"> - <span class="usercount"><?php if($adminGroup['useringroup'] > 0) { p($adminGroup['useringroup']); } ?></span> + <span class="usercount"><?php if($adminGroup['usercount'] > 0) { p($adminGroup['usercount']); } ?></span> </span> </li> <?php endforeach; ?> <!--List of Groups--> <?php foreach($_["groups"] as $group): ?> - <li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p($group['useringroup']) ?>"> + <li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p($group['usercount']) ?>"> <a href="#"> <span><?php p($group['name']); ?></span> <img class="svg action rename" src="<?php p(image_path('core', 'actions/rename.svg'))?>" original-title="<?php p($l->t('Edit'))?>" alt="<?php p($l->t("change group name"))?>" title="<?php p($l->t("change group name"))?>" /> </a> <span class="utils"> - <span class="usercount"><?php if($group['useringroup'] > 0) { p($group['useringroup']); } ?></span> + <span class="usercount"><?php if($group['usercount'] > 0) { p($group['usercount']); } ?></span> <a href="#" class="action delete" original-title="<?php p($l->t('Delete'))?>"> <img src="<?php print_unescaped(image_path('core', 'actions/delete.svg')) ?>" class="svg" /> </a> diff --git a/settings/users.php b/settings/users.php index d3fcbb26a36..a1a1a41e67f 100644 --- a/settings/users.php +++ b/settings/users.php @@ -19,8 +19,6 @@ OC_Util::addStyle( 'settings', 'settings' ); OC_App::setActiveNavigationEntry( 'core_users' ); $users = array(); -$groups = array(); -$adminGroup = array(); $userManager = \OC_User::getManager(); $groupManager = \OC_Group::getManager(); @@ -36,16 +34,19 @@ if (isset($_GET['limit'])) { } $isadmin = OC_User::isAdminUser(OC_User::getUser()); + +$groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), $isadmin, $groupManager); +$groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT); +list($adminGroup, $groups) = $groupsInfo->get(); + $recoveryAdminEnabled = OC_App::isEnabled('files_encryption') && OC_Appconfig::getValue( 'files_encryption', 'recoveryAdminEnabled' ); if($isadmin) { - $accessiblegroups = OC_Group::getGroups(); $accessibleusers = OC_User::getDisplayNames('', 30); $subadmins = OC_SubAdmin::getAllSubAdmins(); }else{ - $accessiblegroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); - $accessibleusers = OC_Group::displayNamesInGroups($accessiblegroups, '', 30); + $accessibleusers = OC_Group::displayNamesInGroups($groups, '', 30); $subadmins = false; } @@ -85,50 +86,13 @@ foreach($accessibleusers as $uid => $displayName) { ); } -$sortGroupsIndex = 0; -$sortGroupsKeys = array(); -$sortAdminGroupsIndex = 0; -$sortAdminGroupsKeys = array(); -foreach( $accessiblegroups as $gid ) { - $group = $groupManager->get($gid); - if(!$group) { - continue; - } - $usersInGroup = $group->count(); - if (!OC_User::isAdminUser($gid)) { - $groups[] = array( - 'id' => str_replace(' ','', $gid ), - 'name' => $gid, - 'useringroup' => $usersInGroup, - ); - $sortGroupsKeys[$sortGroupsIndex] = $usersInGroup; - $sortGroupsIndex++; - } else { - $adminGroup[] = array( - 'id' => str_replace(' ','', $gid ), - 'name' => $gid, - 'useringroup' => $usersInGroup - ); - $sortAdminGroupsKeys[$sortAdminGroupsIndex] = $usersInGroup; - $sortAdminGroupsIndex++; - } -} - -//sorts groups by number of users (descending) -if(!empty($groups)) { - array_multisort($sortGroupsKeys, SORT_DESC, $groups); -} -if(!empty($adminGroup)) { - array_multisort($sortAdminGroupsKeys, SORT_DESC, $adminGroup); -} - $tmpl = new OC_Template( "settings", "users/main", "user" ); $tmpl->assign( 'users', $users ); $tmpl->assign( 'groups', $groups ); $tmpl->assign( 'adminGroup', $adminGroup ); $tmpl->assign( 'isadmin', (int) $isadmin); $tmpl->assign( 'subadmins', $subadmins); -$tmpl->assign( 'numofgroups', count($accessiblegroups)); +$tmpl->assign( 'numofgroups', count($groups) + count($adminGroup)); $tmpl->assign( 'quota_preset', $quotaPreset); $tmpl->assign( 'default_quota', $defaultQuota); $tmpl->assign( 'defaultQuotaIsUserDefined', $defaultQuotaIsUserDefined); |