Are there adjustments you can make to the code to show the total user points written beside each user name each time it appears? For example, when I post an article and the link to my user name appears, it would read "posted by Seanjuan (12)". It would be nice to let the admin determine the style in which the number appears, like parenthetical or hyphenated or whatever they like.

It would also be really cool to sort the entire list of users by the total user points, ascending or decending, etc.

Just a suggestion, thanks!

Sean

CommentFileSizeAuthor
#8 userpoints.txt6.16 KBkbahey
#4 userpoints.module5.95 KBkbahey

Comments

kbahey’s picture

The first one may be difficult to implement, since it requires changes everywhere the user is displayed, so it involves changes to other modules.

What can be done is to provide a link to the points in the user's profile. This can be done in the userpoints_user() function.

Try this, and if it works, I can can commit to the repository.

Add the following 4 lines after the "break;" line in that function.

    case 'view':
      $points = (int) db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d', $user->uid));
      return array('points' => form_item(t('Points'), $points);
      break;

See if it works.

A user list is possible. The "Highest Users" block already does half of that.

sciman’s picture

Not sure I'm understanding what this would do, or how to execute changes to the script, but I'd sure like to have a way, as administrator of identifying user points of all members of a community. I use drupal in teaching, and metrics of involvement in the site can be part of a grading scheme. If there were a table of some sort for administrators to display at least summry point results across authenticated users or users of various roles by participant, that would be cool. If each user had a running point total on their user page, that would be an improvement;-)

seaneffel’s picture

Thanks for the updates, but I need a little more information so I can try your extra code. I'm pretty darned good at the cut-n-paste but I need to know exactly where that new code belongs, if not line numbers then tell me the string I should search for. And I assume I should add this to my .module file, right? Thanks for the clarification!

kbahey’s picture

StatusFileSize
new5.95 KB

Here is a version with the above modification. It returns a new item called "points" to the user object when it is viewed.

Copy the module to the modules directory, then go to a user and view him (e.g. example.com/user/23), and see if anything is displayed.

sciman, for displaying all users with points, a page need to be added to the module to do this. It is not difficult, but I will get to it when time permits.

seaneffel’s picture

That file doesn't do much for me, I don't see any display of points or numbers aside from the block that appeared there from your orginal code.

http://www.cctvcambridge.org/user/17

kbahey’s picture

Try replacing the function userpoints_user() as follows:

========== CUT HERE ==============
function userpoints_user($op) {
  global $user;

  switch($op) {
    case 'delete':
      db_query('DELETE FROM {userpoints} WHERE uid = %d', $user->uid);
      break;
    case 'view':
      $points = (int) db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d', $user->uid));
      return array(t('Points') => form_item(t('Your Points'), $points));
      break;
  }
}
========== CUT HERE ==============

seaneffel’s picture

Title: Display of user points » not so hot

That change, as long as I did it right, caused my site to fail when loading. I got a blank white page on all load attempts. I put the file back the way I found it and the site is back up.

kbahey’s picture

StatusFileSize
new6.16 KB

Try this version. I tested it and it works (shows the points of the users in the profile).

Save it as userpoints.module.

kbahey’s picture

Title: not so hot » Display of user points
kbahey’s picture

Status: Active » Fixed

Sciman,

I went ahead and added the feature you want. It would be useful for others too.

If a user has the permission "view userpoints", they will have a menu item called "User Points", which is a page that lists all the users that have points in descending order.

Wait till tomorrow and download the 4.6 version, and it should contian that feature.

sciman’s picture

Absolutely terrific.. this is an extremely useful feature for those of us interested in educational uses of Drupal.. much appreciated.

Anonymous’s picture

Anonymous’s picture

Status: Fixed » Closed (fixed)