function userpoints_service_add in User Points 7
Same name and namespace in other branches
- 7.2 userpoints_service/userpoints_service.inc \userpoints_service_add()
Add points to a user.
1 string reference to 'userpoints_service_add'
- userpoints_service_services_resources in ./
userpoints_service.module - Implementation of hook_services_resources().
File
- ./
userpoints_service.inc, line 73 - Callbacks and access callbacks for userpoints services integration.
Code
function userpoints_service_add($uid, $points, $tid, $operation, $description, $entity_type, $entity_id) {
if (!$uid) {
return services_error(t('User ID parameter is required.'));
}
if (!$points) {
return services_error(t('Points parameter must be a negative or positive number.'));
}
$params = array(
'uid' => $uid,
'points' => $points,
'tid' => $tid,
'operation' => $operation,
'description' => $description,
'entity_type' => $entity_type,
'entity_id' => $entity_id,
);
$result = userpoints_userpointsapi($params);
$total_points = userpoints_get_current_points($uid);
if (!$result['status']) {
return services_error(t('Adding points failed: @reason', array(
'@reason' => $result['reason'],
)));
}
return (object) array(
'id' => $result['transaction']['txn_id'],
'uri' => services_resource_uri(array(
'userpoints_transaction',
$result['transaction']['txn_id'],
$total_points,
)),
'total_points' => $total_points,
);
}