how do I deduct points from a user for publishing.

SocialNicheGuru - September 29, 2009 - 23:48
Project:User Points
Version:6.x-1.x-dev
Component:Code: userpoints_rules/userpoints_workflow_ng
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I am trying to deduct points from a user.

here is what I have written so far.

I have lots of questions
1. in the php section
$node and $author are variables.
do i have access to $node->uid or do I have to use node_load?
2. returning $node will return all changes?

Here is the code. Any help?

#1

SocialNicheGuru - September 29, 2009 - 23:50

// deduct points from their account
// if no points print message

global $base_path;

// Set number of points needed
$general_events_points = 100;

// Set messages
$message = 'Your event, '.$node->title.', is published';
$error_message = 'Your event, '.$node->title.', could not be published because you do not have enough AO points';
$linktitle = 'Click here to purchase more points';
$payment_url =$base_url.'apps/points';


$author_points = userpoints_get_current_points($author->uid);

   userpoints_userpointsapi( ($author_points - $general_events_points),FALSE, $author->uid);
    $node->content['field_general_paid'] = 'Yes';
    drupal_set_message($message,'warning',false);
    $node->status = 1;


if ($author_points >= $general_events_points) {
   // Set points for author
   userpoints_userpointsapi( ($author_points-$general_events_points),FALSE, $author->uid);
    $node->content['field_general_paid'] = 'Yes';
    drupal_set_message($message,'warning',false);
    $node->status = 1;
        }
   else {
       drupal_set_message($error_message . " " . l($linktitle,$payment_url),'warning',false);
    }

return ("node" => $node);

 
 

Drupal is a registered trademark of Dries Buytaert.