function _nodeaccess_get_grants in Nodeaccess 6
Same name and namespace in other branches
- 8.2 nodeaccess.module \_nodeaccess_get_grants()
- 8 nodeaccess.module \_nodeaccess_get_grants()
- 6.2 nodeaccess.module \_nodeaccess_get_grants()
Return the grants applied to a node object. This is used to generate values for the Grants form.
Parameters
$node: The node to return grants for.
Return value
array An array of grants with keys 'rid' for roles and 'uid' for users.
3 calls to _nodeaccess_get_grants()
- nodeaccess_delete_userreference in ./
nodeaccess.module - Delete all userreference user grants from a node.
- nodeaccess_edit_access in ./
nodeaccess.module - Prevent anonymous users from edit/delete access via node->uid = 0 flaw.
- nodeaccess_insert_userreference in ./
nodeaccess.module - Insert userreference grants from a node.
File
- ./
nodeaccess.module, line 911
Code
function _nodeaccess_get_grants($node) {
$grants = array();
// Load all roles.
$result = db_query("SELECT r.rid, nra.name, na.grant_view, na.grant_update, na.grant_delete FROM {role} r LEFT JOIN {nodeaccess_role_alias} nra ON r.rid = nra.rid LEFT JOIN {node_access} na ON r.rid = na.gid AND na.realm = '%s' AND na.nid = %d ORDER BY nra.weight, nra.name", 'nodeaccess_rid', $node->nid);
while ($grant = db_fetch_object($result)) {
$grants['rid'][$grant->rid] = array(
'name' => $grant->name,
'grant_view' => (bool) $grant->grant_view,
'grant_update' => (bool) $grant->grant_update,
'grant_delete' => (bool) $grant->grant_delete,
);
}
// Load users from node_access.
$result = db_query("SELECT uid, name, grant_view, grant_update, grant_delete FROM {node_access} LEFT JOIN {users} ON uid = gid WHERE nid = %d AND realm = '%s' ORDER BY name", $node->nid, 'nodeaccess_uid');
while ($account = db_fetch_object($result)) {
$grants['uid'][$account->uid] = array(
'name' => $account->name,
'keep' => 1,
'grant_view' => $account->grant_view,
'grant_update' => $account->grant_update,
'grant_delete' => $account->grant_delete,
);
}
return $grants;
}