0

I have created a social site where users can flag other users as "blocked". The primary view for the site lists users along with a bit of profile2 data and a "block" flag link. Users cannot see themselves in the view.

What relationships and filter criteria do I need to add to hide blocked users from the view on a per-user basis?

Example use case: 4 users, User A blocks User C

User A's view:

  • User B
  • User C (message about how you blocked them)
  • User D

User B's view:

  • User A
  • User C
  • User D

User C's view:

  • User B
  • User D

User D's view:

  • User A
  • User B
  • User C
  • You can add a filter criteria (Flags: Flagged (False))to list only those user who are not flagged by the current user. For this you have to use relationship as Flags: User flag – nit3ch Apr 9 '13 at 11:09
1

I couldn't find a way to do this within Views, despite the seemingly simple task and the various decent explanations found around the internet (nit3ch's comment included). The explanations limited the view results too much or in the wrong way.

I ended up using a Views PHP filter field to perform the filtering task:

global $user;
$flags = flag_get_user_flags('user', NULL, $row->uid);
if( array_key_exists('block', $flags) && array_key_exists($user->uid, $flags['block'])){
    //dsm($row); // optional debug
    return TRUE; // prevents row from being displayed
}

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.