Closed (fixed)
Project:
ACL
Version:
5.x-1.4
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
24 Jul 2007 at 05:46 UTC
Updated:
26 Feb 2008 at 04:13 UTC
I'm trying to execute this code:
foreach (acl_node_grants($user, $op) as $realm => $gids) {
as per the example in hook_node_grants permissions search in the node_access module, and getting this error:
warning: Invalid argument supplied for foreach()
What I'm trying to do is see what grants a user has for a particular node, if any. If I should be doing something else, could you please advise. The full code is as follows:
function og_user_roles_content_access_acl_check($op, $node = NULL) {
global $user;
$uid = $user->uid;
if (module_exists('acl')) {
if ($op != 'create' && $node->nid && $node->status) {
$grants = array();
foreach (acl_node_grants($user, $op) as $realm => $gids) {
foreach ($gids as $gid) {
$grants[] = "(gid = $gid AND realm = '$realm')";
}
}
$grants_sql = '';
if (count($grants)) {
$grants_sql = 'AND ('. implode(' OR ', $grants) .')';
}
$sql = "SELECT COUNT(*) FROM {node_access} WHERE (nid = 0 OR nid = %d) $grants_sql AND grant_$op >= 1";
$result = db_query($sql, $node->nid);
$output = (db_result($result));
if ($output > 0) {
return TRUE;
}
if ($output == 0) {
return FALSE;
}
}
} else {
return null;
}
}
Thanks for any assistance.
Comments
Comment #1
somebodysysop commentedAlthough for consistency sake, I'd like to use the acl_node_grants() format above, I did come up with a way to check acl permissions access for user:
Please let me know if this looks ok. Thanks.
Comment #2
salvisYour original approach to using acl_node_grants() was ok, except for it might return NULL.
http://api.drupal.org/api/function/hook_node_grants/5 does not specify what should be returned if no grants are found. The original implementor of ACL went out of his way to return NULL rather than an empty array, but obviously an empty array would be more convenient for you.
I'm trying to find out what the proper "empty" return value is.
Comment #3
salvisThe proper "empty" return value is to return nothing (NULL). So, you need to deal with that.
Comment #4
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.