How to setup a block showing the "top ten" users who flagged the most items (Views 2.x)
Showing the "top ten" flagged nodes is easy (see the "Counters" section in the guide). On the other hand, showing the "top ten" flagging users is a different story, because this statistics is not immediately available in the database. Fortunately, Views is powerful enough to let us generate this kind of list as well:
Instructions for Views 3.x users
If you're using Views 3.x, you'll find instructions here.
Instructions for Views 2.x users
First, install the Views Group By module. Then:
- Start a user-type view (as opposed to a node-type view).
- You're starting with "Style: Unformatted". Change it to "Style: Table".
This step isn't required, but a table makes it easier to see what's going on.
- Add the "User: Name" field.
- Bring in the "Flags: User's flagged content" relationship.
This step links each user with all the nodes she has flagged, and the consequence is that each user is now listed multiple times: as the number of nodes she has flagged (Since your view may show only a handful of records, you may not readily notice this). In the next few steps we will "squash" (or "summarize", or "group") these duplicate records.
- Add the "User: E-mail" field. (Under "Link this field:" choose "No link".)
(As you'll shortly see, we'll use this field for counting; its contents doesn't interest us.)
- Add the "SQL Aggregation: Group By Fields" field. Then configure it:
- For "Fields to Group On:" choose "User: Name".
- For "Fields to Aggregate with the SQL function:" choose "User: E-mail".
- For "Field to Sort Resultset On (after SQL Function is applied):" choose "User: E-email".
- For "Sorting Direction:" choose Descending.
- Click the "Update" button.
- You're done. You'll want to assign the view some URL, or make it a block. You'll also want to limit the view to, say, only 10 records. And change the heading of the "User: E-email" field to, say, "Count". Don't forget to Save the view.
Caching
The SQL query executed for this view is an expensive one. So tweak the Caching setting of your view to your liking (e.g, cache the view for a day). You may want to add a footer message informing your users that "The list is updated daily" so they won't think your site is broken.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion