I want to show users events for only their city. I have set up a taxonomy list for cities that is attached to events that are posted and also to users' profiles via Content Profile. In Views do I need to set up a relationship for user's to be shown only the events in their city? I don't think a filter would be the answer because the event wouldn't have "content:city" attached to it. I'm just haven't quite wrapped my brain around what relationships are in drupal or how to use them so I don't know if I need a relationship or an arguement. Thank you in advance for any help.

Comments

marcvangend’s picture

See http://drupal.org/node/368767 for two video's about views relationships, I hope they answer your questions.

scalp’s picture

and learned a lot about relationships in drupal. The problem I'm still having is that because I'm using the taxonomy terms in the content type "location" it doesn't seem to show up in options for a new relationship. The taxonomy field in the content type is fixed so that I can't change it to be a referenced field. Am I missing something?

scalp’s picture

Is relationships the solution here is my question. It seems like becuase the user and the event are using the same taxonomy there should be some way to link them by saying something to the effect of "select only events where event city=content profile location of current user."

marcvangend’s picture

Good question. I have re-read your first post and you're right, you can (should?) do this without relationships.

If you set up your view, add an argument for Taxonomy: Term. Under 'Action to take if argument is not present:', select 'Provide default argument'. Under 'Default argument type:' choose 'PHP code'. Here you enter some php code (without the php tags):

global $user;
$profile = content_profile_load('profile', $user->uid); // where 'profile' is the node type of your profiles
foreach ($profile->taxonomy AS $tid => $term){
  if ($term->vid == 1){ // where 1 is the id of the cities vocabulary
    return $term->name; // this returns the name of the taxonomy term (the city) as argument
  }
}
return 'all'; // this will only be returned if the user did not select a city in his profile

In this code I am assuming that a user can select only 1 city (it's a single select vocabulary).
Using arguments effectively means that users will see events for their own city when they do not provide an argument (www.example.com/events), but they can see the events for other cities by adding an argument (www.example.com/events/boston). They can view all events on www.example.com/events/all.

PS. I didn't thoroughly test the code above, so if you run into errors, let me know.

scalp’s picture

I haven't had a chance to try implementing it yet, but I will let you know as soon as I do and see how it goes.