Hi does someone have a solution using views? Thanks.

Comments

doublejosh’s picture

Create a node view.

Add Relationship.
Flag: "buddy"
By: "current user"

Done.

doublejosh’s picture

Now can you tell me how to create a list of the user's I've flagged, that doesn't work based on the "current user" radio box?

dropchew’s picture

I found the solution here. Thanks to all.

http://drupal.org/node/326580

quicksketch’s picture

Status: Active » Fixed
dropchew’s picture

Status: Fixed » Active

Sorry for resetting the status,

Its turns out http://drupal.org/node/326580 is not the solution i wanted.

I need to get all flagged nodes (flag by users) from the users I have flagged. So there will be 2 flags, 1 is for flagging node by the other users. Another is user flag, which is use to flag the users. The aim is to get all nodes flagged by them as a whole. It that possible to achieve in a single view? Thanks

doublejosh’s picture

Currently you can only get "flagged by: current user" or "flagged by: any user" :(
That's what I was getting at above.

quicksketch’s picture

I don't think this is currently possible with our existing Views implementation. What you should be able to do:

- Start with user based view, since your first table is a list of users you have flagged.
- Add a "Flag: User flag" relationship for the user-based flag (By: Current user).
- Add a "Flag: User's flagged content" relationship for the node-based flag (By: Any user).
- Add all your fields.

However, it looks like Flag's Views implementation falls a little short here. It should make the flagged content table (node) available for use as fields, filters, arguments, etc., but it doesn't. So the only things you can add to the view are things like the Flagged time, so you can see the time your flagged users flagged content, but you can't actually see what that content is. :P

This is probably only a 1-3 line change somewhere in our Views integration to ensure that the node table is added when using the flagged content argument, it's just a matter of finding what those three lines are, so this could take a while for me to figure out.

dropchew’s picture

Thanks for the thought :)

What I can only think of is to create 2 views,

-User view no.1 with an array of flagged user ids, implode into multiple user id args.
-Node view no.2, takes in multiple user ids args and filter out nodes flagged by them.

Seems like an unorthodox method, but it satisfies my needs for the time being...

sirkitree’s picture

quicksketch, maybe just in the views_data_alter()?

untested:

  $data['node']['table']['join']['flag_content'] = array(
    'left_table' => 'flag_content',
    'left_field' => 'content_id',
    'field' => 'nid',
  );

However I guess this assumes you're content is a node, or your flag type is node - hrm.

mooffie’s picture

Nate wrote:

However, it looks like Flag's Views implementation falls a little short here. It should make the flagged content table (node) available for use as fields, filters, arguments, etc.

I've already done this in the patch attached to #371432: Exposing the flaggings table: Alternative Views support (Search within for "The flagged node.")

sirkitree wrote:

$data['node']['table']['join']['flag_content'] = array(

While this "3 line solution" is possible (another variation, somewhat better, is to add a node relationship to the flag_content table), it has two problems:

  1. It clutters Views' admin UI (making relationships and/or fields available in pick lists when they aren't explicitly asked for).
  2. It's an ad-hoc hack. Interestingly, had we had the wisdom to reject a previous ad-hoc hack, we'd now have the flaggings table exposed (see #371432) and wouldn't have needed any more of those "3 lines" hacks.
mooffie’s picture

Nate wrote:

What you should be able to do:

- Start with user based view,

Note that there's an interesting, subtle issue here:

If the view is of type "user" then we won't be able to use any of the node style/display-plugins for it (E.g., we won't be able to use the node RSS plugin).

And vice versa: if a view is of type "node" then user style-plugins won't be available for it.

(That's how matters were "back in my days". Perhaps things have changed, but I doubt it.)

doublejosh’s picture

That's the problem. Even the first view here is not possible, (via an arbitrary user.)
Right now you can ONLY get a list of users flagged by either the "Current User" or "Any User". There is no "Flagged by UID" passed via argument.

mooffie’s picture

Right now you can ONLY get a list of users flagged by either the "Current User" or "Any User". There is no "Flagged by UID" passed via argument.

Of course it is possible to filter to items flagged by some arbitrary user. That's how the ?q=user/123/bookmarks tab is implemented.

This is mentioned in "A short guide to using the Views integration", and in "How to setup a 'bookmarks' tab on each user's profile page". See the handbook.

===

Other queries will be possible once the #371432: Exposing the flaggings table: Alternative Views support patch gets committed. So I think this issue should be marked a duplicate.

mitchell’s picture

Component: Code » Views integration
Status: Active » Closed (duplicate)