0

Similar to this question, I have an elevated user role (Facilitator) that's associated via profile to a location (content type 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 Views Bulk Operations and have a custom action to change the user role, all of which is working, but 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?

EDIT:

The data relationship looks like this:

User -> Profile -> Space

A Profile can have multiple associated Spaces. I want the view to only show users whose associated space(s) match one or more of the associated space(s) of the current logged in user.

In general it doesn't have to be locations, it could be interests, or favorite colors, anything. Any matching of nodes/users by associated data values.

  • 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 '12 at 21:34
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.

  • what if we wanted to create a content view instead of users view ,, how should this change the embedded php script? – Bassel Alkhateeb Jun 28 '13 at 13:24

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.