function _drupalgap_resource_user_permissions in DrupalGap 6
Same name and namespace in other branches
- 7.2 drupalgap.resource.inc \_drupalgap_resource_user_permissions()
- 7 drupalgap.resource.inc \_drupalgap_resource_user_permissions()
Returns the current user's permissions.
Return value
array Array of user roles and their corresponding permissions.
1 call to _drupalgap_resource_user_permissions()
- _drupalgap_resource_system_connect in ./
drupalgap.resource.inc - Performs service calls to various resources and bundles them all up so the mobile device gets results, settings and permissions in one request.
1 string reference to '_drupalgap_resource_user_permissions'
- drupalgap_services_resources in ./
drupalgap.services.inc - Defines function signatures for resources available to services.
File
- ./
drupalgap.resource.inc, line 259 - This file implements the DrupalGap service resource call back functions.
Code
function _drupalgap_resource_user_permissions() {
global $user;
$uid = $user->uid;
$user_roles_and_permissions = _drupalgap_resource_user_roles_and_permissions();
return $user_roles_and_permissions;
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(
'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();
}
}
}