Posted by SocialNicheGuru on September 29, 2009 at 11:48pm
Jump to:
| Project: | User Points |
| Version: | 6.x-1.x-dev |
| Component: | Code: userpoints_rules/userpoints_workflow_ng |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
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?
Comments
#1
// 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);
#2
The below rule trigger should do the trick.
Event: content is going to be saved
Condition: content is published / unchanged content / negate
Condition: content is published / saved content
Action: load the content author
Action: // deduct the point from the author here
#3
Automatically closed -- issue fixed for 2 weeks with no activity.