Hi everybody,

I hope this issue isn't too specific to me, but I need some help with some custom PHP code, I think. I think I understand what to do in principle, but I am new to PHP coding, and could use your advice.

Let me try to explain the issue.

I'm building a theatre listing website where theatre companies can post show and ticket information. There are two Custom Content types I'm dealing with: Member Theatres and Shows. Every show listing has a drop-down list to select which member company is presenting the show.

Right now, every member company appears in that list for all users. This is a problem, because I don't want users creating or editing content for Member Companies that they don't belong to.

The only way I could figure out how to link user accounts to the Member Theatre Content type is to do a node reference to the users in the appropriate role on the Member Company content type. I can't see a way to build a node reference to a Member Company company through User Profiles. I think this is okay. I also allowed multiple select in this, because some people post shows for a couple of different companies.

I think what I need to do is get into my Show content type, and in the Member Theatre node reference field under default value, add some php code in the field provided. I think the logic needs to be something like:

if current user = Member Company user reference
print Member Company

I'm not sure if it needs an "else" statement, but I obviously don't want the user to be able to choose companies they're not referenced to, so maybe it's

else: hide Member Company

Obviously, I'm not sure how to express the variables, so I would appreciate instruction in that way, as well as any help with the structure and syntax of the code. This is my first PHP script, and I only have a limited amount of flash actionscript under my belt, so I'm clearly groping for a clue. I may be way off on this conceptually too, so if that's the case, please let me know. I'd be so happy to hear any other suggestions.

Thanks,

jw

Comments

jonathanwinn’s picture

I'm not so surprised that nobody responded. It's a pretty individual issue. But I've tried figure out the code on my own, and I'd appreciate any input on the syntax.

global $user;
if ($user->uid == companies.field_user_reference){
echo field_theatre_company;
}

companies is the content type for member companies, where I've inserted field_user_reference to assign select users to companies. field_theatre_company is a node reference I've built into the "show" content type.

My hope is that this will return only the company names that the user is assigned to on the drop-down list where the user creates "show" nodes, instead of the complete list of companies.

Since I've never written any PHP, I'm a little reluctant to test this for fear of screwing something up and not being able to fix it. If anyone can take a look at my code and give suggestions, I'd appreciate it.

thanks!!

jonathanwinn’s picture

and got an error message:
The default value php code must return an array like array(0 => array('value' => 'myvalue')) but returned.

Can anyone tell me where I went wrong?

Thanks,

jw

mariagwyn’s picture

Did you ever figure out a solution to this? If you did, I would be grateful to see it, i think I want to do something similar.

Thanks,
Maria