2

I'm trying to use Flexiaccess with ACL to build a view based on node that the user has access granted by Flexiaccess.

I found this on Drupal.org, it's the same use case, but is not working for me maybe because is for Drupal 6. (http://drupal.org/node/549412):

Here's how to do it:

Under Arguments, create a new argument: "Node: Nid"

Under "Action to take if argument is not present", select "Provide default argument"

Set the "Default argument type" to "PHP Code", and enter the following:

global $user; return db_result(db_query("SELECT GROUP_CONCAT(CAST(an.nid AS CHAR) SEPARATOR ',') FROM {acl_user} au INNER JOIN {acl_node} an ON au.acl_id = an.acl_id WHERE an.grant_view = 1 AND au.uid = %d", $user->uid));

Then check "Allow multiple terms per argument", and click "Update".

I follow those steps but my view shows nothing.

Any help is really appreciated.

0

According to: https://www.drupal.org/node/1255426, Drupal 7 does not have db_result function. You have to replace it with db_query().

Code which worked in my special case:

<?php
global $user;
$query = db_query("SELECT GROUP_CONCAT(CAST(an.nid AS CHAR) SEPARATOR ',') FROM {acl_user} au INNER JOIN {acl_node} an ON au.acl_id = an.acl_id WHERE an.grant_view = 1 AND au.uid = :uid", array(':uid' => $user->uid));
$result = $query->fetchObject();
return reset($result);
?>
| improve this answer | |
-1

Use Contextual Filters instead of arguments in Drupal 7 and check "Provide default value" and in PHP code insert like this.

global $user; 
$query = db_query("SELECT GROUP_CONCAT(CAST(an.nid AS CHAR) SEPARATOR ',') FROM {acl_user} au INNER JOIN {acl_node} an ON au.acl_id = an.acl_id WHERE an.grant_view = 1 AND au.uid = :uid", array(':uid' => $user->uid));

$result = $query->fetchObject();
 return reset($result);

You can also get users allowed to view against each node like this by adding field for "views PHP" with this code

$query = db_query("SELECT GROUP_CONCAT(CAST(au.uid AS CHAR) SEPARATOR ',') FROM acl_user as au INNER JOIN acl_node as an ON au.acl_id = an.acl_id WHERE an.grant_view = 1 AND an.nid =$row->nid ");
$result = $query->fetchObject();
$res = reset($result);

$myArray = explode(',', $res);
//print_r($myArray);
foreach($myArray as $key=>$value){
                     $user_id = $value;
                     $query_user = db_query("SELECT name FROM users WHERE uid = $user_id");
                    $result_u = $query_user->fetchObject();
                    print "<span>" .$result_u->name. "  </span>";

          }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.