hi and thanks for the module

Ive just started using this module so I may have missed something.

But as a way to stop users spamming to gain points, I would like to limit the amount of times points are given.

Fore example I set users to gain points after they post a comment, now they can just go and post random comments in an attempt to gain more points, this creates more work for admins to clean up. So what Im trying to achieve is only give points for the first x ammount of comments posted a day or week (or any given time period)

The same with nodes created, users get points when creating nodes, so now users just create random pointless nodes just to get more points, so I would like to say you only get x ammount of points for the first however many nodes you create, then you have to wait a certain time period before you started getting points again.

Am I making sence?

Thanks for any feedback,

Comments

Rolf van de Krol’s picture

Assigned: Unassigned » Rolf van de Krol
Category: support » feature

This is a feature request. My employer will provide a patch for this shortly.

ropic’s picture

I'm doing that using rules and with a condition that evaluates a php code, example i want only a comment per hour sum points

$result = db_fetch_array(db_query("SELECT * FROM comments WHERE uid = %d AND cid != %d ORDER BY timestamp DESC LIMIT 1", $user->uid, $comment->cid));
if($result)
{
   $timestamp = $result['timestamp'];
   $last_comment_hour = date("YmdH", $timestamp);
   $now_hour = date("YmdH");
   if( $now_hour == $last_comment_hour )
      return false;
}
return true;

Obviously the rule gives the points to the user and then user points for comments has to be disabled.

BenK’s picture

Subscribing...

Jon Rodriguez’s picture

I'm trying to do something a little different. I'm still using rules with a custom PHP condition, but I want to set a global number of points a person can get in a day, 10 for instance. I'm not much of a php developer by any means, but this is what I have so far:

$number = db_result(db_query("SELECT SUM(points) FROM {userpoints_txn} WHERE uid = %d AND time_stamp > %d", $uid, time() - 86400));

{
   if( $number >= 10 )
      return false;
}
return true;

The problem is that this always seems to return true no matter what. I'm obviously doing something rather wrong and I'd appreciate it if someone could point out my mistake(s).

Jon Rodriguez’s picture

Just found out what was going wrong, the time wasn't being parsed correctly. Here's the updated code:

$today = date(Ymd);
$currentday = strtotime($today);
$number = db_result(db_query("SELECT SUM(points) FROM {userpoints_txn} WHERE uid = 1 AND time_stamp > $currentday", $uid));

{
   if( $number + 2 > 10 )
      return false;
}
return true;

I was able to make it so that it operates on a fixed day. The way I was trying to do it before made it a rolling day where it was just calculating the number of points 24 hours from whenever the person was trying. To make it operate on a rolling day (or whatever increment you'd like), you can use this code:

$currentday = time() - 86400;
$number = db_result(db_query("SELECT SUM(points) FROM {userpoints_txn} WHERE uid = 1 AND time_stamp > $currentday", $uid));

{
   if( $number + 2 > 10 )
      return false;
}
return true;

Also, some notes about my if() statement. I realized that if someone had, let's say, 9 points, and they performed an action worth 2 points, it would return true, even though they've exceeded the limit for the day. Therefore, I added + 2 to the sum of the points they have currently as a means to check how many points they will have. I'll just adjust it manually for each rule.

Berdir’s picture

Category: feature » support
Status: Active » Fixed

Note that you can do this in an implementation of hook_userpoints() with $op 'before'. If you return FALSE in that hook, the transaction will automatically be blocked.

This will allow to block all transaction, no matter where they are coming from. Instead of a fixed 2, you want to user $params['points'] and $params['uid'] for the user.

Als, it would be great if you could have a look at the existing documentation at http://drupal.org/documentation/modules/userpoints and see if you can somehow add your code there, for example as a separate How-To page (add child page).

That will be much easier to find than in here...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.