Userpoints 3.x in BETA

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
jredding's picture

Not sure if people know but I took on the redevelopment of the userpoints module to version 3. I did it for two reasons.

The first was making good on my word. I told the module maintainer that I would do the upgrade. Although, at that time, I thought I could get it done before I left NYC.
The second was that the changes make it extremely flexible for multiple purposes, allow for easier module development, and, more specifically, has some awesome features for the PEG world.

Userpoints is/was designed to provide a method to encourage users to participate on the website by giving them "points" for some sort of action. The actions could be posting nodes, comments, events, referring users, etc. etc. At MNN we decided to use it as a method to track user's penalty points. Then at certain point levels the users would be "put on warning", "sanctioned" and/or "banned".

Userpoints v3 is almost a complete rewrite of the module, I spent quite a lot of time on it. The two big feature additions are automatic point expirations (on a per point basis) and point categorization (based on taxonomy).

Point expiration was built for MNN so that when a user received a "penalty" point it would automatically expire at the start of every quarter OR certain penalty points would last for a user-defined time (for example if a manager wanted to ensure a user was banned for an entire year).

Point categorization was built-in so that you could use the module for penalty points as well as other types of points (examples: posting nodes/comments). A good use of userpoints would be to use it for a "budget" system or a declining balance system. If your center gives users a set amount of "Money" to spend during a quarter you can credit their account with auto-expiring points and then let them spend those points during the period. This is already built into the system.

The code is currently frozen to new features and is in dire need of some serious BETA testing. The code can be grabbed from CVS under the tag "DRUPAL-5--3".
http://drupal.org/node/180992

Userpoints can a really good install base behind it, several decent contributed modules and is already slated for a d6 upgrade. Its one of those modules that will be around for a while.

I'm already proposing a v4 of the module that would add a eid column to the table for entity id. This would be handled similarly to the location module. The addition of this column (and some code to back it up) would mean that the module could then be used to track which points were awarded for what nodes/comments/users, etc. OR you could track individual points for node (example: if, like MNN, you give a PROJECT "money" to spend vs. a user this column would allow for that). The now built-in categorization would keep user points and node points separated.

In some geeky talk the API was dramatically switched so that its easier to use. The full-run down is in the README file in the module and on the module's project page but in short using the API can be as easy as
userpoints_userpointsapi(10);

That would give 10 points to the current user placed into the default category and adhered to the site settings for expiration, moderation, etc.

A more detailed example is
$params = array (
'uid' => -10,
'moderate' => false,
'expirydate' => date(now + 1 day),
'event' => "Equipment Rental",
'description' => "Rental of PD-150 camera for 5 days",
'tid' => 3
);

The array can accept anything in the DB as well as the txn_id. If the txn_id is present an UPDATE will be done against existing points (their are reasons for this). In short this means that all modules do not (And should not) do an INSERT/UPDATE to the txn tables directly they have a quick and easy API that will do all the work for them (including keeping the caching tables in sync).

If you have questions on the userpoints module head over to the module page.
If you have questions on how it can be used for PEG respond here.