function _drupalgap_resource_user_roles_and_permissions in DrupalGap 7
Same name and namespace in other branches
- 6 drupalgap.resource.inc \_drupalgap_resource_user_roles_and_permissions()
- 7.2 drupalgap.resource.inc \_drupalgap_resource_user_roles_and_permissions()
Returns a user's roles and permissions.
Return value
array Array of user roles and their corresponding permissions.
1 string reference to '_drupalgap_resource_user_roles_and_permissions'
- drupalgap_services_resources in ./
drupalgap.services.inc - Defines function signatures for resources available to services.
File
- ./
drupalgap.resource.inc, line 209 - This file implements the DrupalGap service resource call back functions.
Code
function _drupalgap_resource_user_roles_and_permissions() {
global $user;
$uid = $user->uid;
if ($uid == 0) {
// Grab permissions for 'anonymous user' role.
$query = db_select('role_permission', 'rp');
$query
->condition('rp.rid', '1')
->fields('rp', array(
'permission',
'module',
));
$result = $query
->execute();
return $result
->fetchAll();
}
else {
// Grab roles for authenticated user.
$query = db_select('users_roles', 'ur');
$query
->condition('ur.uid', $uid)
->fields('ur', array(
'rid',
));
$result = $query
->execute();
$results = $result
->fetchAll();
if (empty($results)) {
// The user only has the 'authenticated user' role.
// Grab permissions for 'anonymous user' role.
$query = db_select('role_permission', 'rp');
$query
->condition('rp.rid', '2')
->fields('rp', array(
'permission',
'module',
));
$result = $query
->execute();
return $result
->fetchAll();
}
else {
// The user has roles other than the 'authenticated user' role.
$query = db_select('users_roles', 'ur');
$query
->condition('ur.uid', $uid)
->fields('ur', array(
'uid',
'rid',
))
->fields('r', array(
'name',
))
->innerJoin('role', 'r', 'ur.rid = r.rid');
$query
->fields('rp', array(
'permission',
'module',
))
->innerJoin('role_permission', 'rp', 'rp.rid = r.rid');
$result = $query
->execute();
return $result
->fetchAll();
}
}
}