drupalfun.com
How to add AND &user_roles condition to empty text code for galleries,etc
Submitted by executrex on Thu, 03/24/2011 - 18:43
Status:
Open Question:
One of the filters I use on my photo album is user roles, and it works fine. the photo album doesn't appear.
The only problem is the empty text message "Add your pictures here" does show up, and if you click on it, it goes right into the upload page.
So, I think what i need to do is in empty text code provided in the book at the command if($id1==$id2)
is to add an AND condition like AND $user_role == "My_role"
The only problem is, I don't know the name of the variable used in the view for user role, so I can't get it to work.
I've tried to figure this out for awhile but haven't been able to. I'm not a PHP programmer and not a Drupal expert, and any help would be appreciated.
Thanks


1. user->roles
I figured it out. In the book Pro Drupal development under the chapter on users they lay out the global user field contents. User->roles is an array. I did a dump of my user field using the print_r command and it turns out the role I added, "myrole" was the fifth element of the roles array. So I added the field and then AND condition in the if statement. The final empty text code looked like this.
<?php
global $user;
$idn1=$user->uid; //my userid
$id2= arg(1); //my contentprofileid
$role= $user->roles[5]; //my content roles
$mynode= content_profile_load(profile, $idn1);
$id1= $mynode->nid;
//check if the user is looking at his own gallery:
if($id1==$id2 AND $role=="myrole"){
//If so: display add link
echo 'Add your audio recordings here!';
}
else{
//if not do nothing:
// echo 'Reserved for the audio recordings';
}
?>