| 1 |
<?php
|
| 2 |
// $Id: user_service.module,v 1.2 2007/01/16 19:08:53 snelson Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_help().
|
| 6 |
*/
|
| 7 |
|
| 8 |
function userpoints_service_help($section) {
|
| 9 |
switch ($section) {
|
| 10 |
case 'admin/help#services_userpoints':
|
| 11 |
case 'admin/modules#description':
|
| 12 |
return t('<p>Provides Userpoints XML-RPC service. Requires services.module.</p>');
|
| 13 |
}
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_service().
|
| 18 |
*/
|
| 19 |
|
| 20 |
function userpoints_service_service() {
|
| 21 |
return array(
|
| 22 |
|
| 23 |
array(
|
| 24 |
'#method' => 'userpoints.get',
|
| 25 |
'#callback' => 'userpoints_service_get',
|
| 26 |
'#args' => array(
|
| 27 |
array(
|
| 28 |
'#name' => 'uid',
|
| 29 |
'#type' => 'int',
|
| 30 |
'#description' => t('A valid Drupal User ID.'),
|
| 31 |
),
|
| 32 |
array(
|
| 33 |
'#name' => 'tid',
|
| 34 |
'#type' => 'int',
|
| 35 |
'#optional' => TRUE,
|
| 36 |
'#description' => t('An optional Term ID for the category.'),
|
| 37 |
),
|
| 38 |
),
|
| 39 |
'#return' => 'struct',
|
| 40 |
'#help' => t('Retrieves the number of points the user has.')),
|
| 41 |
|
| 42 |
array(
|
| 43 |
'#method' => 'userpoints.points',
|
| 44 |
'#callback' => 'userpoints_service_points',
|
| 45 |
'#args' => array(
|
| 46 |
array(
|
| 47 |
'#name' => 'uid',
|
| 48 |
'#type' => 'int',
|
| 49 |
'#description' => t('A valid Drupal User ID.'),
|
| 50 |
),
|
| 51 |
array(
|
| 52 |
'#name' => 'points',
|
| 53 |
'#type' => 'int',
|
| 54 |
'#description' => t('Number of points to add/subtract.'),
|
| 55 |
),
|
| 56 |
array(
|
| 57 |
'#name' => 'tid',
|
| 58 |
'#type' => 'int',
|
| 59 |
'#optional' => TRUE,
|
| 60 |
'#description' => t('An optional Term ID for the category.'),
|
| 61 |
),
|
| 62 |
array(
|
| 63 |
'#name' => 'event',
|
| 64 |
'#type' => 'string',
|
| 65 |
'#optional' => TRUE,
|
| 66 |
'#description' => t('An optional event ID for this transaction.'),
|
| 67 |
),
|
| 68 |
array(
|
| 69 |
'#name' => 'description',
|
| 70 |
'#type' => 'string',
|
| 71 |
'#optional' => TRUE,
|
| 72 |
'#description' => t('An optional description of this transaction.'),
|
| 73 |
),
|
| 74 |
),
|
| 75 |
'#return' => 'struct',
|
| 76 |
'#help' => t('Adds/subtracts points to a user.')),
|
| 77 |
);
|
| 78 |
}
|
| 79 |
|
| 80 |
/**
|
| 81 |
* Get the number of points
|
| 82 |
*/
|
| 83 |
function userpoints_service_get($uid, $tid = NULL) {
|
| 84 |
if (!$uid) {
|
| 85 |
return services_error(t('User ID parameter is required.'));
|
| 86 |
}
|
| 87 |
|
| 88 |
$points = userpoints_get_current_points($uid, $tid);
|
| 89 |
|
| 90 |
$return = new stdClass();
|
| 91 |
$return->points = $points;
|
| 92 |
|
| 93 |
return $return;
|
| 94 |
}
|
| 95 |
|
| 96 |
/**
|
| 97 |
* Logout user
|
| 98 |
*/
|
| 99 |
function userpoints_service_points($uid, $points, $tid = NULL, $event = 'userpoints service', $description = NULL) {
|
| 100 |
if (!$uid) {
|
| 101 |
return services_error(t('User ID parameter is required.'));
|
| 102 |
}
|
| 103 |
|
| 104 |
if (!$points) {
|
| 105 |
return services_error(t('Points parameter must be a negative or positive number.'));
|
| 106 |
}
|
| 107 |
|
| 108 |
$params = array (
|
| 109 |
'uid' => $uid,
|
| 110 |
'points' => $points,
|
| 111 |
'tid' => $tid,
|
| 112 |
'event' => $event,
|
| 113 |
'description' => $desc,
|
| 114 |
'display' => FALSE,
|
| 115 |
'moderate' => FALSE,
|
| 116 |
);
|
| 117 |
|
| 118 |
$result = userpoints_userpointsapi($params);
|
| 119 |
|
| 120 |
$return = new stdClass();
|
| 121 |
|
| 122 |
if (!$result['status']) {
|
| 123 |
$return->reason = $result['reason'];
|
| 124 |
$return->status = FALSE;
|
| 125 |
}
|
| 126 |
else {
|
| 127 |
$return->status = TRUE;
|
| 128 |
}
|
| 129 |
|
| 130 |
return $return;
|
| 131 |
}
|