3

I need to create a flags view that displays a list of users that have "poked" the current user with D7, Views 3 and Flag 3. I've read through this question and drupal.org/node/296971, neither instruction seems to work or at least I am not able to get the settings right.

To define the functionality:

  1. Users are presented with a list view of other users
  2. Users click the "poke" flag link on a single user
  3. Users then browse to /pokes/ and view all other people that have poked them

This is either a difficult setup or I'm missing a couple settings (the latter is extremely likely). Any hints or thoughts?

2
  • Flag/unflag. Poke/unpoke ?
    – AKS
    Commented Apr 7, 2013 at 23:01
  • Let "poke" == flag for now. I plan to add an unflag action when users view their list of pokes/flags, but that can happen later.
    – emc
    Commented Apr 7, 2013 at 23:16

2 Answers 2

5

I created a test site with Flag and Views module enabled and so far, I could create a view to display users who have poked me.

Create a new Flag to flag users. This don't have to be a global flag. Flag text could be "Poke" and unflag text could be "remove".

Users are presented with a list view of other users Users click the "poke" flag link on a single user

  1. Create a view on users table
  2. Add a new relationship: Flags: User.
  3. Uncheck "Include only flagged content "; Choose the poke flag; By: Current user. enter image description here
  4. You will see a new field "Flags: Flag link". Add it.

You will now get a view that shows users and a flag link to flag them. Modify the View as you wish. http://paste2.org/CGZshUFN

Users then browse to /pokes/ and view all other people that have poked them

This is a really tricky part.

  1. Create a new View on users table.
  2. Add a new relationship: Flags: User flag.
  3. Uncheck "Include only flagged content "; Choose the poke flag; By: Any user. enter image description here
  4. Add a new contextual filter: Flags: Content ID
  5. Under contextual filter settings, choose the just-added relationship and set to user the current logged in user ID. enter image description here
  6. Now we have access to a list of user IDs that has flagged the currently logged in user.
  7. Add a new relationship: Flags: User
  8. Under this relationship's settings, check "require this relationship".
  9. Add a new field: User: name and choose the relationship created in step #7.
  10. Add a new relationship: Flags: User flag (yes, you are added one already in step 2 but go ahead).
  11. Under this relationship's settings, choose the the user relationship created at step #7. Uncheck "include only flagged content"; By: current user. enter image description here
  12. Add a new field: Flags: Flag link and choose the relationship created at step #10. http://paste2.org/tkWg99vp

Above step 12 will add the "flag back" type link that the user can see a list of users who have flagged the current user and a link to flag them back. You will need many Views template tweaks to adjust the wording of the View to suit your need.

Good luck!

1
  • 1
    INCREDIBLE answer, thanks so much for your hard work! This is performing quite well so far. I'm having trouble showing multiple 'pokes', any ideas? EDIT: Nevermind, had "Distinct" query turned on!
    – emc
    Commented Apr 8, 2013 at 17:46
1

It works for me too. But When multiple people flagged the same user, When I go on its profile and see the numbers of users who flagged him, I always see the first one and not the others.

In my code I count the number of users who flagged him with this script :

if ($flag) {
 print "The number of people who voted for this proposal:";
 print $flag->get_count($user->uid);
}

And I my output is 3 people.

I don't know why I see only 1 user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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