0

This question is similar to Filter View based on current user profile info (from Content Profile Module).

I have an elevated user role (Facilitator) that's associated via profile to a location (whose content type is Space) and should see a list of pre-authorized users who have matching profile locations that they can authorize or deny. I've built a view using the Views Bulk Operations module; I have a custom action to change the user role, all of which is working. I can't figure out how to filter the pre-authorized students by their location matched to the location of the currently logged-in user. Do I have to make a custom filter for this?

The data relationship looks like User -> Profile -> Space. A profile can have multiple associated spaces. I want the view to only show users whose associated spaces match one or more of the associated spaces of the currently logged-in user. In general they don't need to be locations; they could be interests, or favorite colors, for example.

1
  • 1
    Your question is difficult to follow. It would be helpful if you could describe the settings of your view including all filters, fields, relationships and contextual filters.
    – Ashlar
    Apr 11, 2012 at 21:34

1 Answer 1

2

The only way to do this within views is the following:

  1. Make View of using User type
  2. add a Relationship to a Profile2 type (in my case 'Student')
  3. Add Contextual Filter of type profile:student:location
  4. select "provide default value"
  5. type: "php code"
  6. Use the following code:

    global $user;
    $profile = profile2_load_by_user($user->uid,'facilitator');
    if (!$profile) { return ''; }
    if (!isset($profile->field_location['und'])) { return ''; }
    $locations='';
    foreach ($profile->field_location['und'] as $location) {
      $locations.=','.$location['nid'];
    }
    return substr($locations,1);
    
  7. Under "More", Set "Allow Multiple Values" to TRUE
  8. Save your Contextual Filter

Using PHP in this manner, you can load the current User and get associated values to filter by. This may be useful in many other contexts and circumstances.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.