We've got a panels page at groups/manage/%group/!action -- %group is the group's nid, and !action is something like "requests" for showing a view of all of the pending group membership requests.
We want to limit access to these pages in panels, based on whether or not the logged in user is the admin of the group in %group. So, I see that
<?php
$contexts[logged-in-user]->data->og_groups->859->is_admin
?>
...will tell me if this user is or is not an admin for the group id 859. And we know that $contexts[argument_string_1]->data is the group id.
But I am apparently experiencing some kind of mental malfunction, because I cannot for the life of me get this to work. It's gotta be a syntax thing with PHP that I'm not getting. I thought that this would work:
<?php
if($contexts[logged-in-user]->data->og_groups->{$contexts[argument_string_1]->data}->is_admin == 1){ return TRUE; } else{ return FALSE;}
?>
but it doesn't work, always returning false, whether the logged in user is the admin or not.
Is there something obvious I'm missing here, or is there a better way to check this? This seems like a really simple, elegant way to do it, since all the info is right there in $contexts.
Comments
Comment #1
merlinofchaos commentedI would recommend breaking that up and using some temporary variables. This will allow you to use dsm() to examine the data and wee where you are going wrong.
For example:
If you're using a string context, that ought to be more or less true. Though I would *think* that %group would actually not be a string but would instead be a group and provide an actual group context. Still, you could dsm and make sure it's correct. You may also want to intval() it to be sure it's an integer.
dsm() on that should give you a bit more on that. This is one I'd worry about, since it's just the global $user and that isn't always a complete user object. It strikes me that there may be a function og provides that might do this all a little more easily, as well.
Comment #2
friolator commentedright before you responded I figured out that $user->og_groups contains everything I need to do without getting particularly fancy, so now it works the way I originally intended, but it's a lot cleaner.
Thanks!