Points integration?
jasonwhat - November 27, 2006 - 21:03
| Project: | Affiliates |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Any plan to add some form of integration with the points module to affiliates?

#1
Please let me know what you have in mind , thanks
#2
Also for me, userpoints module integration didn`t work, so i looked at code...
<?php
if (module_exists('userpoints')) {
$points = (int)db_result(db_query("SELECT points FROM {affiliates_ads} WHERE ad_id = %d", $ad_id));
userpoints_userpointsapi('points', $points, $uid, "affiliates");
}
?>
but userpoints module need array as params, so i changed this code to:
<?php
if (module_exists('userpoints')) {
$points = (int)db_result(db_query("SELECT points FROM {affiliates_ads} WHERE ad_id = %d", $ad_id));
$params = array('points'=>$points, 'uid'=>$uid, 'description'=>"affiliates");
userpoints_userpointsapi($params);
}
?>
And its work for me!
#3
Thanks for your help Babruix!
Ill try out the userpoints module and your patch later today.
Best, Paul
#4
Actually, it is much better to add a hook to affiliates.
This means that when someone accrues points we do the following:
<?phpmodule_invoke_all('affiliates', $user, $points); // points in affiliate points, not user points
?>
Then we can have modules act on that event whichever way we want.
So, we have a module called userpoints_affiliates.module, and in it we have:
<?phpfunction userpoints_affiliates($account, $points) {
$params = array(
'points'=>$points,
'uid'=>$uid,
'description'=>"affiliates",
);
userpoints_userpointsapi($params);
}
?>
The module can have a multiplier for points, or a fixed number of points for each point, or anything you want.
The possibilities are endless this way. So let us add a hook regardless.
As a separate topic, we can have userpoints be the underlying mechanism for storing points for affiliates as well, and the module would have a dependency on userpoints. This makes the database simpler, but adds some complexity.
#5
I agree with kbahey regarding hook, but I have been looking over the module's functionality and debating with myself regarding the idea of moving points to be dependent on userpoints. On the one hand, having a singular points system would be cleaner. On the other hand, categorization becomes more of an issue when trying to pull top affiliates data for blocks and pages. I am still thinking about it and may try to tackle it in the near future but, for now, I needed userpoints integration in its current form for Drupal 6 and the fix in #2 isn't proper (as kbahey suggests) as the $params line is in the older userpoints v2 api format.
Until I or someone else tackles a re-vamp of the points system overall, here is a patch that fixes userpoints for the v3 api and adds taxonomy categorization for the userpoints. I removed the point value field in the userpoints settings as it wasn't doing anything currently (it could be used as a multiplier, but I decided to hold off on that right now).
Also, I found some other problems in the code in general that this patch fixes:
First, the storage directory for the images was defined as /images/affiliates and that was causing errors since images isn't a default directory created by Drupal. I changed it to just be /affiliates so that it would be created in the directory defined in the Site Configuration>File System.
Second, there was a TRUE value mis-typed as TRE.
Third, the More button in the Top Affiliates block was failing if Drupal was installed in a subdirectory. I removed the leading / for the link and that cleared it up.
#6
Note that in addition to the .module patch in my previous post #5, there is a matching patch for the .install file I posted here: http://drupal.org/node/340053#comment-1173909
#7
Hmm.. had another thought. I decided to keep the userpoints values code in the module, but just comment it out so that it doesn't get lost and could be activated later on or if someone should want to use it as a modifier.
Also added text and link to the taxonomy category description that explains that points are set in the Affiliates admin section on a per button basis and fixed the fieldset title display.
Oh, one other thing to note is that while the Affiliates module has click fraud prevention based on ip address in a given period, the userpoints function does not. It is possible to repeatedly click on a button and rack up userpoints. I'll look at fixing that tomorrow after getting some sleep.
#8
Got it! The attached patch supercedes my previous 2. It adds click fraud protection to userpoints and tweaks the add button interface (specifically changes the required flag for the redirect URL since the redirect function will go to homepage if not specified and adds some text to better explain the OR option of upload image and image url).
I think I'm done for now...
Oh, btw, Paul or kbahey: all the module files are missing the $id: info.
#9
I lied. Just discovered that the permissions settings were not fully functional. Only administer affiliates was being used. I added affiliate click to the point logging function so that one can control whose clicks get logged. I left the original perms line in for reference and commented it out.
Again, this patch supercedes all my previous posts.
#10
More fixes...
-Re-fix More button URL from post #5
-Fix URL for userpoints category link to affiliates/admin
My head hurts now.
#11
Committed to 6.x-1.x-dev.
I had to change a variable name, and define it at the top.
Thank you.
#12
In the commit to the dev version, line 23 where the new variable is defined ends with a , when it should be a ;
#13
Thanks.
Fixed.
#14
With the Jan 9, 2009 6.x-1.0 release of Userpoints, the hook_userpoints function call changed. Here is patch to update for compatibility.
#15
Committed.
Released in 6.x-1.2
#16
Automatically closed -- issue fixed for two weeks with no activity.
#17
Has anyone figured out points integration for the 5.x version?