function nodeaccess_get_grants in Nodeaccess 7
Return the grants applied to a node object used for Grant form.
Parameters
Object $node:
Return value
array An array of grants with keys 'rid' for roles and 'uid' for users.
4 calls to nodeaccess_get_grants()
- nodeaccess_delete_user_reference in ./
nodeaccess.module - Delete all userreference user grants from a node.
- nodeaccess_grants_form in ./
nodeaccess.module - Menu callback. Draws the grant tab.
- nodeaccess_insert_user_reference in ./
nodeaccess.module - Insert userreference grants from a node.
- nodeaccess_node_access in ./
nodeaccess.module - Implements hook_node_access().
File
- ./
nodeaccess.module, line 940 - Provide per node access control
Code
function nodeaccess_get_grants($node) {
$grants = array();
// Load grants by roles.
$query = db_select('role', 'r');
$query
->leftJoin('nodeaccess_role_alias', 'nra', 'nra.rid = r.rid');
$query
->leftJoin('node_access', 'na', 'na.gid = r.rid AND na.realm = :realm AND na.nid = :nid', array(
':realm' => 'nodeaccess_rid',
':nid' => $node->nid,
));
$query
->fields('r', array(
'rid',
));
$query
->fields('nra', array(
'name',
));
$query
->fields('na', array(
'grant_view',
'grant_update',
'grant_delete',
));
$query
->orderBy('nra.weight');
$query
->orderBy('nra.name');
$result = $query
->execute();
while ($grant = $result
->fetch()) {
$grants['rid'][$grant->rid] = array(
'name' => empty($grant->name) ? '' : check_plain($grant->name),
'grant_view' => (bool) $grant->grant_view,
'grant_update' => (bool) $grant->grant_update,
'grant_delete' => (bool) $grant->grant_delete,
);
}
// Load grants by users
$query = db_select('node_access', 'na');
$query
->join('users', 'u', 'u.uid = na.gid');
$query
->fields('u', array(
'uid',
'name',
));
$query
->fields('na', array(
'grant_view',
'grant_update',
'grant_delete',
));
$query
->condition('na.nid', $node->nid, '=');
$query
->condition('na.realm', 'nodeaccess_uid', '=');
$query
->orderBy('name');
$result = $query
->execute();
while ($account = $result
->fetch()) {
$grants['uid'][$account->uid] = array(
'name' => $account->name,
'keep' => TRUE,
'grant_view' => (bool) $account->grant_view,
'grant_update' => (bool) $account->grant_update,
'grant_delete' => (bool) $account->grant_delete,
);
}
return $grants;
}