-
-
Save raghunayyar/cf8d29d9e4ccc0423125 to your computer and use it in GitHub Desktop.
Ajaxifying group sidebar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ownCloud - Core | |
* | |
* @author Morris Jobke | |
* @copyright 2013 Morris Jobke morris.jobke@gmail.com | |
* | |
* This library is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | |
* License as published by the Free Software Foundation; either | |
* version 3 of the License, or any later version. | |
* | |
* This library is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. | |
* | |
* You should have received a copy of the GNU Affero General Public | |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | |
* | |
*/ | |
OC_JSON::checkSubAdminUser(); | |
$userUid = OC_User::getUser(); | |
$isAdmin = OC_User::isAdminUser($userUid); | |
if (isset($_GET['offset'])) { | |
$offset = $_GET['offset']; | |
} else { | |
$offset = 0; | |
} | |
if (isset($_GET['limit'])) { | |
$limit = $_GET['limit']; | |
} else { | |
$limit = 10; | |
} | |
if($isAdmin) { | |
$groups = OC_Group::getGroups(); | |
} else { | |
$groups = OC_SubAdmin::getSubAdminsGroups($userUid); | |
} | |
$users = array(); | |
$result = array( 'groups' => array() ); | |
// convert them to the needed format | |
foreach( $groups as $gid ) { | |
if ($isAdmin) { | |
$batch = OC_User::getDisplayNames('', $limit, $offset); | |
foreach ($batch as $user => $displayname) { | |
$users[] = array( 'loginname' => $user ); | |
} | |
} | |
else { | |
$groups = OC_SubAdmin::getSubAdminsGroups($userUid); | |
$batch = OC_Group::usersInGroups($groups, '', $limit, $offset); | |
foreach( $batch as $user ) { | |
$users[] = array( 'loginname' => $user ); | |
} | |
} | |
$result['groups'][$gid] = array('user' => $users); | |
//$result['groups'][] = array( 'name' => $gid ); | |
} | |
OCP\JSON::success(array('result' => $result)); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data": { | |
"groups": [ | |
{"admin(groupname)": [ | |
{"raghu(loginname)" : [ | |
"userid" : "1", | |
"displayname" : "raghunayyar", | |
"password" : "*****", | |
"isadmin" : "success" ], | |
"pawan(loginname)" : [ | |
"userid" : "1", | |
"displayname" : "raghunayyar", | |
"password" : "*****", | |
"isadmin" : "success" ] | |
} | |
], | |
"group1(groupname)" : [ | |
... | |
] | |
} | |
] | |
}, | |
"status":"success" | |
} |
pardon the password field. Lukas was kill me. xD
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the user management has users driven from from groups instead of groups driven from users which is there currently. I wanted to change the ajax calls such that a JSON output of this sort is implemented, I guess this allows me to access users from a particular group better. Any suggestions? I plan to do this over the weekend.. here is the json output I wish to create.
Problems this has : if a user belongs to more then one group, its data is repeated, is there an alternative to this?