/[drupal]/contributions/modules/userpoints/userpoints_service.module
ViewVC logotype

Contents of /contributions/modules/userpoints/userpoints_service.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Apr 2 23:41:08 2008 UTC (19 months, 3 weeks ago) by kbahey
Branch: MAIN
CVS Tags: DRUPAL-5--3-5, DRUPAL-6--1-1, HEAD
Branch point for: DRUPAL-5--3, DRUPAL-6--1
File MIME type: text/x-php
XML RPC for userpoints via integration with the services module.

This allows external applications and sites to retrieve and update
points on your site. Many things are possible with this, such as
a Drupal site acting as an award points or user reputation repository
for Joomla or Wordpress sites, or having user actions captured in
other systems (not necessarily web sites) updating the points on
your Drupal site. Use your imagination ...
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 }

  ViewVC Help
Powered by ViewVC 1.1.2