unify and consolidate group fetching method for initial template fill and ajax request
This commit is contained in:
parent
d87347e64e
commit
3e411c82a5
3 changed files with 56 additions and 81 deletions
|
@ -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);
|
||||
$accessiblegroups = array_intersect($groups, $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++;
|
||||
}
|
||||
}
|
||||
|
||||
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)));
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue