You are here

function userpoints_nodeapi in User Points 5.2

Same name and namespace in other branches
  1. 5.3 userpoints_basic.module \userpoints_nodeapi()
  2. 5 userpoints_basic.module \userpoints_nodeapi()

File

./userpoints_basic.module, line 61

Code

function userpoints_nodeapi(&$node, $op, $teaser, $page) {
  static $orig_uid;
  $points = variable_get(USERPOINTS_POST . $node->type, 0);
  switch ($op) {
    case 'insert':
      $points = $points;
      userpoints_userpointsapi('points', $points, $node->uid, $node->type);
      break;
    case 'delete':
      $points = -$points;
      userpoints_userpointsapi('points', $points, $node->uid, $node->type);
      break;
    case 'prepare':
      $orig_uid = $node->uid;
      break;
    case 'update':
      if ($node->uid != $orig_uid) {

        // Add to the new node owner
        userpoints_userpointsapi('points', $points, $node->uid, $node->type);

        // subtract from the original node owner
        $points = -$points;
        userpoints_userpointsapi('points', $points, $orig_uid, $node->type);
      }
      break;
  }
}