I added a user reference field in one of my content types. I have another filefield in that content type which stores files for each node/content page. I would like to only show the files for that node/content page to users entered in the user reference list. I created a view with the previously mentioned filefield being displayed as a list, and argument is set to nid. How do I setup the view to only be displayed for users selected in the user reference list for that node/content page? Any guidance is appreciated. Thank you, Rani

Comments

danielb’s picture

In your node template you check the current user's uid against the view reference field's data. If it matches you print out the file stuff, if not... then do nothing. Doesn't get any easier.

rmassamiri’s picture

Thank you danielb. By any chance, would you mind sharing the php snippet for this that I can put in the node template? I am not a php coder. Thank you very much. -Rani

danielb’s picture

I'm not sure you even have to use this module? Files aren't nodes, and this is node access, not file access. But you could use an idea like this in your node-your_content_type.tpl.php template:

<?php

global $user;  // get current user

$show_files = FALSE;  // assume he is not allowed to see files

foreach ($node->field_allowed_users as $allowed_user) {  // check each allowed user in a userreference field called 'Allowed users'
  if ($allowed_user['uid'] == $user->uid) {  // test if the allowed user matches the current user
    $show_files = TRUE;  // assert this person is allowed to see files
    break;   // stop this foreach loop now that we have found the person
  } 
}

if ($show_files) {  // test whether we decided to show files or not in the previous bit
  print "file stuff";  // sorry dunno this bit
}

?>
rmassamiri’s picture

Thank you very much. I will give it a try.

danielb’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.