Comments

Anonymous’s picture

Version: 4.7.x-1.0 » 5.x-1.x-dev
Assigned: Unassigned »
Status: Active » Postponed (maintainer needs more info)

Please let me know what you have in mind , thanks

babruix’s picture

Status: Postponed (maintainer needs more info) » Needs review

Also for me, userpoints module integration didn`t work, so i looked at code...

 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:

  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!

Anonymous’s picture

Thanks for your help Babruix!

Ill try out the userpoints module and your patch later today.

Best, Paul

kbahey’s picture

Actually, it is much better to add a hook to affiliates.

This means that when someone accrues points we do the following:

  module_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:

function 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.

fred0’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
StatusFileSize
new2.82 KB

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.

fred0’s picture

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

fred0’s picture

StatusFileSize
new3.4 KB

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.

fred0’s picture

StatusFileSize
new5.19 KB

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.

fred0’s picture

StatusFileSize
new6.34 KB

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.

fred0’s picture

StatusFileSize
new6.69 KB

More fixes...
-Re-fix More button URL from post #5
-Fix URL for userpoints category link to affiliates/admin

My head hurts now.

kbahey’s picture

Assigned: » Unassigned
Status: Needs review » Fixed

Committed to 6.x-1.x-dev.

I had to change a variable name, and define it at the top.

Thank you.

fred0’s picture

In the commit to the dev version, line 23 where the new variable is defined ends with a , when it should be a ;

kbahey’s picture

Thanks.

Fixed.

fred0’s picture

StatusFileSize
new344 bytes

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.

kbahey’s picture

Committed.

Released in 6.x-1.2

Status: Fixed » Closed (fixed)

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

jusyjim’s picture

Has anyone figured out points integration for the 5.x version?