Is there a way to show the members who have posted the most comments (or contributed the most to the site)? E.g. Top 20 Members.

Comments

Rachel C’s picture

Can anyone help?

Max Bell’s picture

I've wanted such a feature for a long time, myself, Rachel, and there is no such beastie.

grohk’s picture

It would be a fairly simple block. You could base it off the top nodes block.

---
Code Orange: Drink Your Juice

bryan kennedy’s picture

I agree that programing this wouldn't be to complex. You would just need to pull the 'uid' feild of the 'comments' table in the database, sort them, and then do a count to see who had the most. Then just sort them again to get the list. Does this help?

morbus iff’s picture

Here's the SQL statement you'd need, which would give you the following results (per the Gamegrene.com database at least):

SELECT COUNT(cid) AS count, users.uid, users.name FROM comments LEFT JOIN users ON comments.uid = users.uid WHERE comments.uid != 0 GROUP BY uid ORDER BY count DESC LIMIT 20;

+-------+------+-----------------+
| count | uid  | name            |
+-------+------+-----------------+
|   455 |   57 | EaterOfTheDead  |
|    65 |    1 | Morbus Iff      |
|    47 |  294 | Vaxalon         |
|    41 |   64 | Rogue Githyanki |
|    27 |  150 | OldTimer        |

http://disobey.com/
http://gamegrene.com/

Tpyo’s picture

If you wanted to take this one gaint step up. You could store the users points and reward them Privileges based on thier points.

I don't program, so I can't help there. But if anyone wants to build such a Mod and hook it into the other features - I can do Specs :-).

I work with you and show you how to triple your customer Loyalty and have them Participate more. they'll be coming back more and more.

I also have a methodology for reducing Spam "Hey, remove me from your emailing list" I didn't sign up when in FACT they did sign up -- they just forgot.

They forget and you get a Spam complaint :-( we can help there :-)

javanaut’s picture

FYI, this type of thing was being discussed about a month ago. I don't know if anyone followed it up with any code (I've been outta the loop lately).

http://drupal.org/node/14175

Also,
http://drupal.org/node/1260
http://drupal.org/node/14583

grohk’s picture

I am talking with Moshe about developing this module. My idea is to meld this idea into the Node Moderation, Comment Moderation, and AutoMember modules. Ideally, it will also be flexible enough to allow several point scoring systems.

I will let you know when we start actually having code.

---
Code Orange: Drink Your Juice

bryan kennedy’s picture

Check out the autorole.module It allows for some of this automatic role management you mention. In combination with the SQL command posted above this could be a cool community tool.

morbus iff’s picture

1. Go to http://yoursite.com/admin/block/add
2. The Block Title is "Top 20 Users".
3. The Block Description is "Top 20 Users".
4. The Input Filter is "PHP Code".
5. And the block body is below.

$users = db_query("SELECT COUNT(cid) AS count, {users}.uid, {users}.name FROM {comments} LEFT JOIN {users} ON {comments}.uid = {users}.uid WHERE {comments}.uid != 0 GROUP BY uid ORDER BY count DESC LIMIT 20");

print "<ul>"; while ($user = db_fetch_object($users)) {
  print "<li>$user->name ($user->count)</li>";
} print "</ul>";

Save your block and enable it as usual. This is a VERY VERY basic block, just to show you as an example. It doesn't link to the user's profile, and it writes raw HTML as opposed to using the Drupal template builtins. Adding those features are an exercise for the reader.

http://disobey.com/
http://gamegrene.com/

javanaut’s picture

..at least on the linking to a user's journal feature...for the convenience of non-programmers...

global $base_url;
$users = db_query("SELECT COUNT(cid) AS count, {users}.uid, {users}.name FROM {comments} LEFT JOIN {users} ON {comments}.uid = {users}.uid WHERE {comments}.uid != 0 GROUP BY uid ORDER BY count DESC LIMIT 20");

print "<ul>";
while ($user = db_fetch_object($users)) {
  print "<li><a href='$base_url/user/$user->uid'>$user->name</a> ($user->count)</li>";
}
print "</ul>";

Now, if only there were a place to list out the most recent comments that a user posted....

Rachel C’s picture

Thanks so much, that's wonderful!

javanaut’s picture

The code above assumes that you are using clean urls. The more generic solution would be:

$users = db_query("SELECT COUNT(cid) AS count, {users}.uid, {users}.name FROM {comments} LEFT JOIN {users} ON {comments}.uid = {users}.uid WHERE {comments}.uid != 0 GROUP BY uid ORDER BY count DESC LIMIT 20");
print "<ul>";
while ($user = db_fetch_object($users)) {
    print "<li>".l($user->name,"user/$user->uid")." ($user->count)</li>";
}
print "</ul>";

I wonder if there shouldn't be a section on drupal.org for clever block hacks such as these. There are so many little things like this that don't necessarily warrant creating a module for but would be "nice to have". Maybe someone should create a stupidblocktricks.module to house so many such blocks.

sepeck’s picture

Where in the handbook do you feel such a section should go? I agree with you, it would be nice. It is also posible.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

javanaut’s picture

I don't know if the handbook would be a proper place for them. I suppose if a new top-level section was created ("Tips and Tricks"?), it could fit in, but none of the current sections would naturally house them very well.

I would think that another section on the Downloads page would make more sense. There's already Drupal, Modules, Themes, Translations and Theme Engines, why not add another section here for inline code hacks and blocks?

I don't have much of a personal preference for storing them so long as they're not too difficult to find. The current bag of tricks is not really easy for people to find (http://cvs.drupal.org/viewcvs/drupal/contributions/tricks/blocks/) and requires CVS access to contribute to.

grohk’s picture

http://drupal.org/node/17170

Perhaps it would be nice to propose moving this book page to another location, where it could be more useful?

---
Code Orange: Drink Your Juice

javanaut’s picture

I never would have looked under the Administration Guide's Troubleshooting FAQ for a repository of various blocks.

sepeck’s picture

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

bryan kennedy’s picture

Just to keep links up to date in the forums I wanted to mention that I created a higher level Blocks directory where these custom blocks may be posted.

frjo’s picture

Maybe this is something you and others can use? It's based on some of the example code here but are a module and use Drupal funktions for item list etc.


/**
 * @file
 * top_users.module 4.5.0v1, Fredrik Jonsson, 2005-02-17
 * Enables admins to display a block with the top users, 
 * the ones that has posted most comments.
 */

/**
 * Implementation of hook_help().
 */
function top_users_help($section = "admin/help#top_users") {
  switch ($section) {
    case 'admin/modules#description':
      $output = t("Block that display the top users, the ones that has posted most comments.");
      break;
  }
  return $output;
}

/**
 * Implementation of hook_block().
 *
 * Generates a block with the comments approval queue and
 * the node moderation queue.
 * $nlimit sets the number of comments and nodes to display
 */

function top_users_block($op = 'list', $delta = 0) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('Top Users');
    return $blocks;
  }
  else if (user_access('access content')) {
    $nlimit = 10;

    $users = db_query_range('SELECT COUNT(c.cid) AS count, u.uid, u.name 
      FROM {comments} c 
      LEFT JOIN {users} u ON c.uid = u.uid 
      WHERE c.uid != 0 
      GROUP BY uid 
      ORDER BY count DESC', 0, $nlimit);
    $items = array();
    while ($user = db_fetch_object($users)) {
      $items[] = l($user->name,'user/'. $user->uid) .' ('. l($user->count,'tracker/'. $user->uid) .')';
    }

    $block['subject'] = t('Top Users');
    $block['content'] = theme('item_list', $items);
    return $block;
  }
}
frjo’s picture

Used another module as template and forgot to change a comment block.

/**
* Implementation of hook_block().
*
* Generates a block with the top users,
* the ones that has posted most comments.
* $nlimit sets the number of top users to display
*/