Closed (fixed)
Project:
User Points
Version:
6.x-1.1
Component:
Code: userpoints API
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
20 Jan 2011 at 11:38 UTC
Updated:
15 Feb 2011 at 13:30 UTC
how can i deduct users(member) points by user's last login..?
the workflow maybe like this :
user A had 100 points, if user A didn't log back in 2 days, his/her points will be deduct 10 points automatically...
Can anyone help me to achieve this.
Comments
Comment #1
adit234 commentedstill waiting....:(
Comment #2
berdirWhen is this supposed to happen? When he logs in again? Or regularly (eg. loose 10 points for every 2 days you aren't logged in)
You need custom code for both of these.
The first is simpler. Implement hook_user() op login. Check last login time, subtract points for the difference with userpoints_userpointsapi(). But this means that points are only subtracted if he logs in again.
The other way would be to implement hook_cron(), check for users which haven't logged in in the last 2 days and have points and haven't already been deducted points in the last two days (custom table). Then remove some points for them, add them to your custom table (uid and timestamp).
Note that this is not a support forum. Feel free to ask specific, userpoints.module related questions and I'll try to help but I won't give you code that you can just copy and paste.
Comment #3
berdirComment #4
adit234 commentedthanks @Berdir for quick response
this is what i want.
actually i'm lack of experience in PHP plus i'm still newbie in Drupal. I think, i will go to support forum to create (if i can) my own code...:D
thanks anyway @Berdir and sorry for my bad english....;)
Comment #5
berdirThe userpoints specific part of that is very simply. You just need to call "userpoints_userpointsapi($points)", where points could e.g. be -5. You need to figure out when to do that and how many points you want to subtract. Support forums, stackoverflow.com etc. should be a good place to ask a question like this.
One another userpoints thing you might need it is get the points a user currently has: "userpoints_get_current_points($uid)". You can for example multiply that with 0.1 if you want to deduct 10% of the points.
Feel free to re-open this issue (Remember to mark issues as fixed if they are) if you have more specific questions.