Creating a list of total flags per user

By Bill Seremetis, 25 November, 2014

I needed to create a list with the total count of flags, for a specific flag type, made by users. The query to do this for one user is this:
SELECT COUNT(*) FROM flagging WHERE uid=[user_id] AND fid=[flag_id];

Doing this with views, while not very difficult is a bit trivial. You need to start with a node view and not with a user view. From here on things go as follows:

  1.  Add a relationship: Flags Content Flag and set it to the flag type you want. Make sure to check 'by any user'. Do net check 'include only flagged content'.
  2. Then add a relationship: Flags User and set its relationship to be the one from the first step. Check 'require this relationship'.
  3. Enable aggregation from the advanced settings
  4. Add a field in the view: User Name (aggregation type: group results together)
  5. Add a field: Content Title, with aggregation set to COUNT.
  6. Display the results in a table or filter them any way you want, you view is ready.


Total flags per user