MDL-40424 user: Incorrect use of named parameters
[moodle.git] / user / externallib.php
CommitLineData
ef22c1b6 1<?php
ef22c1b6 2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
4615817d 17
ef22c1b6 18/**
19 * External user API
20 *
4615817d
JM
21 * @package core_user
22 * @category external
23 * @copyright 2009 Petr Skodak
ef22c1b6 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27require_once("$CFG->libdir/externallib.php");
28
5d1017e1 29/**
4615817d
JM
30 * User external functions
31 *
32 * @package core_user
33 * @category external
34 * @copyright 2011 Jerome Mouneyrac
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 * @since Moodle 2.2
5d1017e1
JM
37 */
38class core_user_external extends external_api {
ef22c1b6 39
7b472b32
PS
40 /**
41 * Returns description of method parameters
4615817d 42 *
7b472b32 43 * @return external_function_parameters
4615817d 44 * @since Moodle 2.2
7b472b32 45 */
d4e13355 46 public static function create_users_parameters() {
667b496a
PS
47 global $CFG;
48
35b9a80a 49 return new external_function_parameters(
50 array(
51 'users' => new external_multiple_structure(
52 new external_single_structure(
53 array(
a327f25e
AG
54 'username' => new external_value(PARAM_USERNAME, 'Username policy is defined in Moodle security config.'),
55 'password' => new external_value(PARAM_RAW, 'Plain text password consisting of any characters'),
56 'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user'),
57 'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user'),
58 'email' => new external_value(PARAM_EMAIL, 'A valid and unique email address'),
59 'auth' => new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT, 'manual', NULL_NOT_ALLOWED),
60 'idnumber' => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_DEFAULT, ''),
61 'lang' => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_DEFAULT, $CFG->lang, NULL_NOT_ALLOWED),
62 'theme' => new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL),
63 'timezone' => new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL),
64 'mailformat' => new external_value(PARAM_INT, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL),
65 'description' => new external_value(PARAM_TEXT, 'User profile description, no HTML', VALUE_OPTIONAL),
66 'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
67 'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
68 'firstnamephonetic' => new external_value(PARAM_NOTAGS, 'The first name(s) phonetically of the user', VALUE_OPTIONAL),
69 'lastnamephonetic' => new external_value(PARAM_NOTAGS, 'The family name phonetically of the user', VALUE_OPTIONAL),
70 'middlename' => new external_value(PARAM_NOTAGS, 'The middle name of the user', VALUE_OPTIONAL),
71 'alternatename' => new external_value(PARAM_NOTAGS, 'The alternate name of the user', VALUE_OPTIONAL),
72 'preferences' => new external_multiple_structure(
35b9a80a 73 new external_single_structure(
74 array(
7b472b32 75 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preference'),
35b9a80a 76 'value' => new external_value(PARAM_RAW, 'The value of the preference')
77 )
fb79269b 78 ), 'User preferences', VALUE_OPTIONAL),
35b9a80a 79 'customfields' => new external_multiple_structure(
80 new external_single_structure(
81 array(
7b472b32 82 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'),
35b9a80a 83 'value' => new external_value(PARAM_RAW, 'The value of the custom field')
84 )
6bb31e40 85 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL)
35b9a80a 86 )
87 )
88 )
89 )
90 );
625f0a24 91 }
92
d4e13355 93 /**
5de592b1 94 * Create one or more users
95 *
4615817d 96 * @param array $users An array of users to create.
71864f15 97 * @return array An array of arrays
4615817d 98 * @since Moodle 2.2
5de592b1 99 */
7b472b32 100 public static function create_users($users) {
ef22c1b6 101 global $CFG, $DB;
25eb9090 102 require_once($CFG->dirroot."/lib/weblib.php");
fb79269b 103 require_once($CFG->dirroot."/user/lib.php");
30a4fb1b 104 require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function
109b453b 105
5de592b1 106 // Ensure the current user is allowed to run this function
43731030 107 $context = context_system::instance();
ef22c1b6 108 self::validate_context($context);
fb79269b 109 require_capability('moodle/user:create', $context);
d9ad0103 110
5de592b1 111 // Do basic automatic PARAM checks on incoming data, using params description
5de592b1 112 // If any problems are found then exceptions are thrown with helpful error messages
7b472b32 113 $params = self::validate_parameters(self::create_users_parameters(), array('users'=>$users));
109b453b 114
bd3b3bba 115 $availableauths = core_component::get_plugin_list('auth');
667b496a
PS
116 unset($availableauths['mnet']); // these would need mnethostid too
117 unset($availableauths['webservice']); // we do not want new webservice users for now
118
bd3b3bba 119 $availablethemes = core_component::get_plugin_list('theme');
1f96e907 120 $availablelangs = get_string_manager()->get_list_of_translations();
5de592b1 121
38b76f3c 122 $transaction = $DB->start_delegated_transaction();
5de592b1 123
fb79269b 124 $userids = array();
7b472b32 125 foreach ($params['users'] as $user) {
667b496a
PS
126 // Make sure that the username doesn't already exist
127 if ($DB->record_exists('user', array('username'=>$user['username'], 'mnethostid'=>$CFG->mnet_localhost_id))) {
128 throw new invalid_parameter_exception('Username already exists: '.$user['username']);
ef22c1b6 129 }
ef22c1b6 130
667b496a
PS
131 // Make sure auth is valid
132 if (empty($availableauths[$user['auth']])) {
133 throw new invalid_parameter_exception('Invalid authentication type: '.$user['auth']);
ef22c1b6 134 }
135
667b496a
PS
136 // Make sure lang is valid
137 if (empty($availablelangs[$user['lang']])) {
138 throw new invalid_parameter_exception('Invalid language code: '.$user['lang']);
ef22c1b6 139 }
140
667b496a 141 // Make sure lang is valid
fb79269b 142 if (!empty($user['theme']) && empty($availablethemes[$user['theme']])) { //theme is VALUE_OPTIONAL,
143 // so no default value.
144 // We need to test if the client sent it
145 // => !empty($user['theme'])
667b496a 146 throw new invalid_parameter_exception('Invalid theme: '.$user['theme']);
ef22c1b6 147 }
5de592b1 148
fb79269b 149 $user['confirmed'] = true;
a1988186 150 $user['mnethostid'] = $CFG->mnet_localhost_id;
30a4fb1b 151
25eb9090
AB
152 // Start of user info validation.
153 // Lets make sure we validate current user info as handled by current GUI. see user/editadvanced_form.php function validation()
154 if (!validate_email($user['email'])) {
155 throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
156 } else if ($DB->record_exists('user', array('email'=>$user['email'], 'mnethostid'=>$user['mnethostid']))) {
157 throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
158 }
159 // End of user info validation.
160
615abdda
AB
161 // create the user data now!
162 $user['id'] = user_create_user($user);
25eb9090 163
30a4fb1b 164 // custom fields
165 if(!empty($user['customfields'])) {
166 foreach($user['customfields'] as $customfield) {
167 $user["profile_field_".$customfield['type']] = $customfield['value']; //profile_save_data() saves profile file
168 //it's expecting a user with the correct id,
169 //and custom field to be named profile_field_"shortname"
170 }
171 profile_save_data((object) $user);
172 }
667b496a 173
d9ad0103 174 //preferences
175 if (!empty($user['preferences'])) {
176 foreach($user['preferences'] as $preference) {
177 set_user_preference($preference['type'], $preference['value'],$user['id']);
178 }
179 }
d4e13355 180
c4c352dd 181 $userids[] = array('id'=>$user['id'], 'username'=>$user['username']);
ef22c1b6 182 }
183
38b76f3c 184 $transaction->allow_commit();
667b496a 185
fb79269b 186 return $userids;
ef22c1b6 187 }
188
7b472b32
PS
189 /**
190 * Returns description of method result value
4615817d 191 *
7b472b32 192 * @return external_description
4615817d 193 * @since Moodle 2.2
7b472b32
PS
194 */
195 public static function create_users_returns() {
196 return new external_multiple_structure(
197 new external_single_structure(
198 array(
199 'id' => new external_value(PARAM_INT, 'user id'),
45b4464c 200 'username' => new external_value(PARAM_USERNAME, 'user name'),
7b472b32
PS
201 )
202 )
203 );
d4e13355 204 }
205
206
930680cb
PS
207 /**
208 * Returns description of method parameters
4615817d 209 *
930680cb 210 * @return external_function_parameters
4615817d 211 * @since Moodle 2.2
930680cb 212 */
d4e13355 213 public static function delete_users_parameters() {
930680cb
PS
214 return new external_function_parameters(
215 array(
216 'userids' => new external_multiple_structure(new external_value(PARAM_INT, 'user ID')),
217 )
218 );
d4e13355 219 }
930680cb 220
5d1017e1
JM
221 /**
222 * Delete users
4615817d 223 *
5d1017e1 224 * @param array $userids
e6acc551 225 * @return null
4615817d 226 * @since Moodle 2.2
5d1017e1 227 */
38b76f3c 228 public static function delete_users($userids) {
b73a28be 229 global $CFG, $DB, $USER;
fb79269b 230 require_once($CFG->dirroot."/user/lib.php");
38b76f3c
PS
231
232 // Ensure the current user is allowed to run this function
43731030 233 $context = context_system::instance();
38b76f3c
PS
234 require_capability('moodle/user:delete', $context);
235 self::validate_context($context);
236
fb79269b 237 $params = self::validate_parameters(self::delete_users_parameters(), array('userids'=>$userids));
38b76f3c
PS
238
239 $transaction = $DB->start_delegated_transaction();
38b76f3c
PS
240
241 foreach ($params['userids'] as $userid) {
242 $user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST);
b73a28be 243 // must not allow deleting of admins or self!!!
4f622c38
PS
244 if (is_siteadmin($user)) {
245 throw new moodle_exception('useradminodelete', 'error');
246 }
247 if ($USER->id == $user->id) {
248 throw new moodle_exception('usernotdeletederror', 'error');
b73a28be 249 }
fb79269b 250 user_delete_user($user);
38b76f3c
PS
251 }
252
253 $transaction->allow_commit();
254
255 return null;
ef22c1b6 256 }
930680cb
PS
257
258 /**
259 * Returns description of method result value
4615817d
JM
260 *
261 * @return null
262 * @since Moodle 2.2
930680cb 263 */
d4e13355 264 public static function delete_users_returns() {
930680cb 265 return null;
d4e13355 266 }
ef22c1b6 267
268
930680cb
PS
269 /**
270 * Returns description of method parameters
4615817d 271 *
930680cb 272 * @return external_function_parameters
4615817d 273 * @since Moodle 2.2
930680cb 274 */
d4e13355 275 public static function update_users_parameters() {
fb79269b 276 global $CFG;
2336a843 277 return new external_function_parameters(
fb79269b 278 array(
279 'users' => new external_multiple_structure(
280 new external_single_structure(
281 array(
61cca0b7 282 'id' => new external_value(PARAM_INT, 'ID of the user'),
a327f25e
AG
283 'username' => new external_value(PARAM_USERNAME, 'Username policy is defined in Moodle security config.', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED),
284 'password' => new external_value(PARAM_RAW, 'Plain text password consisting of any characters', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED),
285 'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED),
286 'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
287 'email' => new external_value(PARAM_EMAIL, 'A valid and unique email address', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED),
288 'auth' => new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL, '', NULL_NOT_ALLOWED),
289 'idnumber' => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL),
290 'lang' => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_OPTIONAL, '', NULL_NOT_ALLOWED),
291 'theme' => new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL),
292 'timezone' => new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL),
293 'mailformat' => new external_value(PARAM_INT, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL),
294 'description' => new external_value(PARAM_TEXT, 'User profile description, no HTML', VALUE_OPTIONAL),
295 'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
296 'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
297 'firstnamephonetic' => new external_value(PARAM_NOTAGS, 'The first name(s) phonetically of the user', VALUE_OPTIONAL),
298 'lastnamephonetic' => new external_value(PARAM_NOTAGS, 'The family name phonetically of the user', VALUE_OPTIONAL),
299 'middlename' => new external_value(PARAM_NOTAGS, 'The middle name of the user', VALUE_OPTIONAL),
300 'alternatename' => new external_value(PARAM_NOTAGS, 'The alternate name of the user', VALUE_OPTIONAL),
301 'customfields' => new external_multiple_structure(
fb79269b 302 new external_single_structure(
303 array(
304 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'),
305 'value' => new external_value(PARAM_RAW, 'The value of the custom field')
306 )
6bb31e40 307 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL),
d9ad0103 308 'preferences' => new external_multiple_structure(
309 new external_single_structure(
310 array(
311 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preference'),
312 'value' => new external_value(PARAM_RAW, 'The value of the preference')
313 )
314 ), 'User preferences', VALUE_OPTIONAL),
fb79269b 315 )
316 )
317 )
318 )
319 );
d4e13355 320 }
38b76f3c 321
5d1017e1
JM
322 /**
323 * Update users
4615817d 324 *
5d1017e1 325 * @param array $users
e6acc551 326 * @return null
4615817d 327 * @since Moodle 2.2
5d1017e1 328 */
38b76f3c
PS
329 public static function update_users($users) {
330 global $CFG, $DB;
fb79269b 331 require_once($CFG->dirroot."/user/lib.php");
9baf3a7b 332 require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function
38b76f3c
PS
333
334 // Ensure the current user is allowed to run this function
43731030 335 $context = context_system::instance();
38b76f3c
PS
336 require_capability('moodle/user:update', $context);
337 self::validate_context($context);
338
339 $params = self::validate_parameters(self::update_users_parameters(), array('users'=>$users));
340
341 $transaction = $DB->start_delegated_transaction();
342
343 foreach ($params['users'] as $user) {
fb79269b 344 user_update_user($user);
9baf3a7b 345 //update user custom fields
346 if(!empty($user['customfields'])) {
347
348 foreach($user['customfields'] as $customfield) {
349 $user["profile_field_".$customfield['type']] = $customfield['value']; //profile_save_data() saves profile file
350 //it's expecting a user with the correct id,
351 //and custom field to be named profile_field_"shortname"
352 }
353 profile_save_data((object) $user);
354 }
d9ad0103 355
356 //preferences
357 if (!empty($user['preferences'])) {
358 foreach($user['preferences'] as $preference) {
359 set_user_preference($preference['type'], $preference['value'],$user['id']);
360 }
361 }
38b76f3c
PS
362 }
363
364 $transaction->allow_commit();
365
366 return null;
ef22c1b6 367 }
930680cb
PS
368
369 /**
370 * Returns description of method result value
4615817d
JM
371 *
372 * @return null
373 * @since Moodle 2.2
930680cb 374 */
d4e13355 375 public static function update_users_returns() {
930680cb 376 return null;
d4e13355 377 }
378
86477112
FS
379 /**
380 * Returns description of method parameters
381 *
382 * @return external_function_parameters
c70b9853 383 * @since Moodle 2.4
86477112 384 */
c70b9853 385 public static function get_users_by_field_parameters() {
86477112
FS
386 return new external_function_parameters(
387 array(
c70b9853
JM
388 'field' => new external_value(PARAM_ALPHA, 'the search field can be
389 \'id\' or \'idnumber\' or \'username\' or \'email\''),
390 'values' => new external_multiple_structure(
391 new external_value(PARAM_RAW, 'the value to match'))
86477112
FS
392 )
393 );
394 }
395
396 /**
c70b9853 397 * Get user information for a unique field.
86477112 398 *
c70b9853
JM
399 * @param string $field
400 * @param array $values
401 * @return array An array of arrays containg user profiles.
402 * @since Moodle 2.4
86477112 403 */
c70b9853 404 public static function get_users_by_field($field, $values) {
86477112
FS
405 global $CFG, $USER, $DB;
406 require_once($CFG->dirroot . "/user/lib.php");
407
c70b9853
JM
408 $params = self::validate_parameters(self::get_users_by_field_parameters(),
409 array('field' => $field, 'values' => $values));
410
411 // This array will keep all the users that are allowed to be searched,
412 // according to the current user's privileges.
413 $cleanedvalues = array();
414
415 switch ($field) {
416 case 'id':
417 $paramtype = PARAM_INT;
418 break;
419 case 'idnumber':
420 $paramtype = PARAM_RAW;
421 break;
422 case 'username':
ec80bc6b 423 $paramtype = PARAM_RAW;
c70b9853
JM
424 break;
425 case 'email':
426 $paramtype = PARAM_EMAIL;
427 break;
428 default:
429 throw new coding_exception('invalid field parameter',
430 'The search field \'' . $field . '\' is not supported, look at the web service documentation');
86477112
FS
431 }
432
c70b9853
JM
433 // Clean the values
434 foreach ($values as $value) {
435 $cleanedvalue = clean_param($value, $paramtype);
436 if ( $value != $cleanedvalue) {
437 throw new invalid_parameter_exception('The field \'' . $field .
438 '\' value is invalid: ' . $value . '(cleaned value: '.$cleanedvalue.')');
439 }
440 $cleanedvalues[] = $cleanedvalue;
86477112
FS
441 }
442
c70b9853
JM
443 // Retrieve the users
444 $users = $DB->get_records_list('user', $field, $cleanedvalues, 'id');
86477112 445
c70b9853
JM
446 // Finally retrieve each users information
447 $returnedusers = array();
86477112 448 foreach ($users as $user) {
86477112
FS
449 $userdetails = user_get_user_details_courses($user);
450
c70b9853
JM
451 // Return the user only if the searched field is returned
452 // Otherwise it means that the $USER was not allowed to search the returned user
453 if (!empty($userdetails) and !empty($userdetails[$field])) {
454 $returnedusers[] = $userdetails;
86477112
FS
455 }
456 }
86477112 457
c70b9853 458 return $returnedusers;
86477112
FS
459 }
460
461 /**
462 * Returns description of method result value
463 *
c70b9853
JM
464 * @return external_multiple_structure
465 * @since Moodle 2.4
86477112 466 */
c70b9853 467 public static function get_users_by_field_returns() {
85e6bf8e 468 return new external_multiple_structure(self::user_description());
b0365ea5
JM
469 }
470
471
472 /**
bb1105ae 473 * Returns description of get_users() parameters.
b0365ea5
JM
474 *
475 * @return external_function_parameters
bb1105ae 476 * @since Moodle 2.5
b0365ea5
JM
477 */
478 public static function get_users_parameters() {
479 return new external_function_parameters(
480 array(
481 'criteria' => new external_multiple_structure(
482 new external_single_structure(
483 array(
bb1105ae
JM
484 'key' => new external_value(PARAM_ALPHA, 'the user column to search, expected keys (value format) are:
485 "id" (int) matching user id,
486 "lastname" (string) user last name (Note: you can use % for searching but it may be considerably slower!),
487 "firstname" (string) user first name (Note: you can use % for searching but it may be considerably slower!),
488 "idnumber" (string) matching user idnumber,
489 "username" (string) matching user username,
490 "email" (string) user email (Note: you can use % for searching but it may be considerably slower!),
491 "auth" (string) matching user auth plugin'),
492 'value' => new external_value(PARAM_RAW, 'the value to search')
b0365ea5
JM
493 )
494 ), 'the key/value pairs to be considered in user search. Values can not be empty.
bb1105ae 495 Specify different keys only once (fullname => \'user1\', auth => \'manual\', ...) -
85e6bf8e 496 key occurences are forbidden.
0c34e803 497 The search is executed with AND operator on the criterias. Invalid criterias (keys) are ignored,
85e6bf8e
JM
498 the search is still executed on the valid criterias.
499 You can search without criteria, but the function is not designed for it.
500 It could very slow or timeout. The function is designed to search some specific users.'
86477112
FS
501 )
502 )
503 );
504 }
505
b0365ea5 506 /**
bb1105ae 507 * Retrieve matching user.
b0365ea5 508 *
bb1105ae
JM
509 * @param array $criteria the allowed array keys are id/lastname/firstname/idnumber/username/email/auth.
510 * @return array An array of arrays containing user profiles.
511 * @since Moodle 2.5
b0365ea5
JM
512 */
513 public static function get_users($criteria = array()) {
514 global $CFG, $USER, $DB;
515
516 require_once($CFG->dirroot . "/user/lib.php");
517
518 $params = self::validate_parameters(self::get_users_parameters(),
519 array('criteria' => $criteria));
520
bb1105ae 521 // Validate the criteria and retrieve the users.
b0365ea5
JM
522 $users = array();
523 $warnings = array();
b0365ea5 524 $sqlparams = array();
85e6bf8e
JM
525 $usedkeys = array();
526
527 // Do not retrieve deleted users.
528 $sql = ' deleted = 0';
b0365ea5 529
0c34e803 530 foreach ($params['criteria'] as $criteriaindex => $criteria) {
85e6bf8e
JM
531
532 // Check that the criteria has never been used.
533 if (array_key_exists($criteria['key'], $usedkeys)) {
534 throw new moodle_exception('keyalreadyset', '', '', null, 'The key ' . $criteria['key'] . ' can only be sent once');
535 } else {
536 $usedkeys[$criteria['key']] = true;
537 }
538
0c34e803 539 $invalidcriteria = false;
bb1105ae 540 // Clean the parameters.
b0365ea5
JM
541 $paramtype = PARAM_RAW;
542 switch ($criteria['key']) {
543 case 'id':
544 $paramtype = PARAM_INT;
545 break;
546 case 'idnumber':
547 $paramtype = PARAM_RAW;
548 break;
549 case 'username':
ec80bc6b 550 $paramtype = PARAM_RAW;
b0365ea5
JM
551 break;
552 case 'email':
bb1105ae 553 // We use PARAM_RAW to allow searches with %.
b0365ea5
JM
554 $paramtype = PARAM_RAW;
555 break;
556 case 'auth':
557 $paramtype = PARAM_AUTH;
558 break;
559 case 'lastname':
560 case 'firstname':
561 $paramtype = PARAM_TEXT;
562 break;
563 default:
bb1105ae
JM
564 // Send back a warning that this search key is not supported in this version.
565 // This warning will make the function extandable without breaking clients.
b0365ea5 566 $warnings[] = array(
0c34e803 567 'item' => $criteria['key'],
b0365ea5 568 'warningcode' => 'invalidfieldparameter',
bb1105ae 569 'message' => 'The search key \'' . $criteria['key'] . '\' is not supported, look at the web service documentation'
b0365ea5 570 );
0c34e803
JM
571 // Do not add this invalid criteria to the created SQL request.
572 $invalidcriteria = true;
573 unset($params['criteria'][$criteriaindex]);
574 break;
b0365ea5 575 }
b0365ea5 576
0c34e803
JM
577 if (!$invalidcriteria) {
578 $cleanedvalue = clean_param($criteria['value'], $paramtype);
b0365ea5 579
85e6bf8e 580 $sql .= ' AND ';
0c34e803
JM
581
582 // Create the SQL.
583 switch ($criteria['key']) {
584 case 'id':
585 case 'idnumber':
586 case 'username':
587 case 'auth':
588 $sql .= $criteria['key'] . ' = :' . $criteria['key'];
589 $sqlparams[$criteria['key']] = $cleanedvalue;
590 break;
591 case 'email':
592 case 'lastname':
593 case 'firstname':
594 $sql .= $DB->sql_like($criteria['key'], ':' . $criteria['key'], false);
595 $sqlparams[$criteria['key']] = $cleanedvalue;
596 break;
597 default:
598 break;
599 }
b0365ea5
JM
600 }
601 }
602
603 $users = $DB->get_records_select('user', $sql, $sqlparams, 'id ASC');
604
bb1105ae 605 // Finally retrieve each users information.
b0365ea5
JM
606 $returnedusers = array();
607 foreach ($users as $user) {
b0365ea5
JM
608 $userdetails = user_get_user_details_courses($user);
609
610 // Return the user only if all the searched fields are returned.
611 // Otherwise it means that the $USER was not allowed to search the returned user.
612 if (!empty($userdetails)) {
613 $validuser = true;
614
615 foreach($params['criteria'] as $criteria) {
616 if (empty($userdetails[$criteria['key']])) {
617 $validuser = false;
618 }
619 }
620
621 if ($validuser) {
622 $returnedusers[] = $userdetails;
623 }
624 }
625 }
626
627 return array('users' => $returnedusers, 'warnings' => $warnings);
628 }
629
630 /**
bb1105ae 631 * Returns description of get_users result value.
b0365ea5
JM
632 *
633 * @return external_description
bb1105ae 634 * @since Moodle 2.5
b0365ea5
JM
635 */
636 public static function get_users_returns() {
637 return new external_single_structure(
638 array('users' => new external_multiple_structure(
85e6bf8e 639 self::user_description()
b0365ea5 640 ),
bb1105ae 641 'warnings' => new external_warnings('always set to \'key\'', 'faulty key name')
b0365ea5
JM
642 )
643 );
644 }
645
7b472b32
PS
646 /**
647 * Returns description of method parameters
4615817d 648 *
7b472b32 649 * @return external_function_parameters
4615817d 650 * @since Moodle 2.2
41f5285f
JM
651 * @deprecated Moodle 2.5 MDL-38030 - Please do not call this function any more.
652 * @see core_user_external::get_users_by_field_parameters()
7b472b32 653 */
fb79269b 654 public static function get_users_by_id_parameters() {
71864f15 655 return new external_function_parameters(
109b453b 656 array(
657 'userids' => new external_multiple_structure(new external_value(PARAM_INT, 'user ID')),
658 )
71864f15 659 );
d4e13355 660 }
7b472b32 661
71864f15
PS
662 /**
663 * Get user information
b4c74367
JM
664 * - This function is matching the permissions of /user/profil.php
665 * - It is also matching some permissions from /user/editadvanced.php for the following fields:
666 * auth, confirmed, idnumber, lang, theme, timezone, mailformat
4615817d 667 *
71864f15
PS
668 * @param array $userids array of user ids
669 * @return array An array of arrays describing users
4615817d 670 * @since Moodle 2.2
41f5285f
JM
671 * @deprecated Moodle 2.5 MDL-38030 - Please do not call this function any more.
672 * @see core_user_external::get_users_by_field()
71864f15 673 */
fb79269b 674 public static function get_users_by_id($userids) {
b4c74367 675 global $CFG, $USER, $DB;
109b453b 676 require_once($CFG->dirroot . "/user/lib.php");
fb79269b 677
109b453b 678 $params = self::validate_parameters(self::get_users_by_id_parameters(),
679 array('userids'=>$userids));
5de592b1 680
0d352dbc 681 list($sqluserids, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
2e4c0c91
FM
682 $uselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
683 $ujoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
684 $params['contextlevel'] = CONTEXT_USER;
ea4e96c2
DC
685 $usersql = "SELECT u.* $uselect
686 FROM {user} u $ujoin
687 WHERE u.id $sqluserids";
688 $users = $DB->get_recordset_sql($usersql, $params);
d4e13355 689
109b453b 690 $result = array();
0601e0ee 691 $hasuserupdatecap = has_capability('moodle/user:update', context_system::instance());
d4e13355 692 foreach ($users as $user) {
ea4e96c2
DC
693 if (!empty($user->deleted)) {
694 continue;
695 }
db314f34 696 context_helper::preload_from_record($user);
43731030 697 $usercontext = context_user::instance($user->id, IGNORE_MISSING);
01479290 698 self::validate_context($usercontext);
b4c74367
JM
699 $currentuser = ($user->id == $USER->id);
700
01479290
DC
701 if ($userarray = user_get_user_details($user)) {
702 //fields matching permissions from /user/editadvanced.php
703 if ($currentuser or $hasuserupdatecap) {
704 $userarray['auth'] = $user->auth;
705 $userarray['confirmed'] = $user->confirmed;
706 $userarray['idnumber'] = $user->idnumber;
707 $userarray['lang'] = $user->lang;
708 $userarray['theme'] = $user->theme;
709 $userarray['timezone'] = $user->timezone;
710 $userarray['mailformat'] = $user->mailformat;
b4c74367 711 }
01479290 712 $result[] = $userarray;
ea4e96c2 713 }
fb79269b 714 }
ea4e96c2 715 $users->close();
71864f15
PS
716
717 return $result;
d4e13355 718 }
7b472b32 719
109b453b 720 /**
7b472b32 721 * Returns description of method result value
4615817d 722 *
7b472b32 723 * @return external_description
4615817d 724 * @since Moodle 2.2
41f5285f
JM
725 * @deprecated Moodle 2.5 MDL-38030 - Please do not call this function any more.
726 * @see core_user_external::get_users_by_field_returns()
7b472b32 727 */
fb79269b 728 public static function get_users_by_id_returns() {
bb1105ae
JM
729 $additionalfields = array (
730 'enrolledcourses' => new external_multiple_structure(
503c14a6
DW
731 new external_single_structure(
732 array(
733 'id' => new external_value(PARAM_INT, 'Id of the course'),
734 'fullname' => new external_value(PARAM_RAW, 'Fullname of the course'),
735 'shortname' => new external_value(PARAM_RAW, 'Shortname of the course')
736 )
737 ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL));
85e6bf8e 738 return new external_multiple_structure(self::user_description($additionalfields));
ea4e96c2 739 }
bb1105ae 740
ea4e96c2
DC
741 /**
742 * Returns description of method parameters
4615817d 743 *
ea4e96c2 744 * @return external_function_parameters
4615817d 745 * @since Moodle 2.2
ea4e96c2 746 */
5d1017e1 747 public static function get_course_user_profiles_parameters() {
ea4e96c2
DC
748 return new external_function_parameters(
749 array(
750 'userlist' => new external_multiple_structure(
751 new external_single_structure(
752 array(
753 'userid' => new external_value(PARAM_INT, 'userid'),
754 'courseid' => new external_value(PARAM_INT, 'courseid'),
109b453b 755 )
ea4e96c2 756 )
71864f15 757 )
ea4e96c2
DC
758 )
759 );
760 }
761
762 /**
763 * Get course participant's details
4615817d 764 *
ea4e96c2
DC
765 * @param array $userlist array of user ids and according course ids
766 * @return array An array of arrays describing course participants
4615817d 767 * @since Moodle 2.2
ea4e96c2 768 */
5d1017e1 769 public static function get_course_user_profiles($userlist) {
ea4e96c2
DC
770 global $CFG, $USER, $DB;
771 require_once($CFG->dirroot . "/user/lib.php");
5d1017e1 772 $params = self::validate_parameters(self::get_course_user_profiles_parameters(), array('userlist'=>$userlist));
ea4e96c2
DC
773
774 $userids = array();
775 $courseids = array();
776 foreach ($params['userlist'] as $value) {
777 $userids[] = $value['userid'];
778 $courseids[$value['userid']] = $value['courseid'];
779 }
780
781 // cache all courses
782 $courses = array();
0d352dbc 783 list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids), SQL_PARAMS_NAMED);
2e4c0c91
FM
784 $cselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
785 $cjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
786 $params['contextlevel'] = CONTEXT_COURSE;
ecfc06d8 787 $coursesql = "SELECT c.* $cselect
ea4e96c2
DC
788 FROM {course} c $cjoin
789 WHERE c.id $sqlcourseids";
790 $rs = $DB->get_recordset_sql($coursesql, $params);
791 foreach ($rs as $course) {
792 // adding course contexts to cache
db314f34 793 context_helper::preload_from_record($course);
ea4e96c2
DC
794 // cache courses
795 $courses[$course->id] = $course;
796 }
797 $rs->close();
798
0d352dbc 799 list($sqluserids, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
2e4c0c91
FM
800 $uselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
801 $ujoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
802 $params['contextlevel'] = CONTEXT_USER;
ea4e96c2
DC
803 $usersql = "SELECT u.* $uselect
804 FROM {user} u $ujoin
805 WHERE u.id $sqluserids";
806 $users = $DB->get_recordset_sql($usersql, $params);
807 $result = array();
808 foreach ($users as $user) {
809 if (!empty($user->deleted)) {
810 continue;
811 }
db314f34 812 context_helper::preload_from_record($user);
ea4e96c2 813 $course = $courses[$courseids[$user->id]];
43731030 814 $context = context_course::instance($courseids[$user->id], IGNORE_MISSING);
ea4e96c2 815 self::validate_context($context);
01479290
DC
816 if ($userarray = user_get_user_details($user, $course)) {
817 $result[] = $userarray;
ea4e96c2 818 }
01479290 819 }
ea4e96c2 820
01479290 821 $users->close();
ea4e96c2 822
01479290
DC
823 return $result;
824 }
ea4e96c2 825
01479290
DC
826 /**
827 * Returns description of method result value
4615817d 828 *
01479290 829 * @return external_description
4615817d 830 * @since Moodle 2.2
01479290 831 */
5d1017e1 832 public static function get_course_user_profiles_returns() {
b0365ea5
JM
833 $additionalfields = array(
834 'groups' => new external_multiple_structure(
835 new external_single_structure(
836 array(
837 'id' => new external_value(PARAM_INT, 'group id'),
838 'name' => new external_value(PARAM_RAW, 'group name'),
839 'description' => new external_value(PARAM_RAW, 'group description'),
840 'descriptionformat' => new external_format_value('description'),
841 )
842 ), 'user groups', VALUE_OPTIONAL),
843 'roles' => new external_multiple_structure(
844 new external_single_structure(
845 array(
846 'roleid' => new external_value(PARAM_INT, 'role id'),
847 'name' => new external_value(PARAM_RAW, 'role name'),
848 'shortname' => new external_value(PARAM_ALPHANUMEXT, 'role shortname'),
849 'sortorder' => new external_value(PARAM_INT, 'role sortorder')
850 )
851 ), 'user roles', VALUE_OPTIONAL),
852 'enrolledcourses' => new external_multiple_structure(
503c14a6
DW
853 new external_single_structure(
854 array(
855 'id' => new external_value(PARAM_INT, 'Id of the course'),
856 'fullname' => new external_value(PARAM_RAW, 'Fullname of the course'),
857 'shortname' => new external_value(PARAM_RAW, 'Shortname of the course')
858 )
859 ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL)
b0365ea5
JM
860 );
861
85e6bf8e 862 return new external_multiple_structure(self::user_description($additionalfields));
b0365ea5
JM
863 }
864
865 /**
866 * Create user return value description.
867 *
bb1105ae 868 * @param array $additionalfields some additional field
b0365ea5
JM
869 * @return single_structure_description
870 */
bb1105ae 871 public static function user_description($additionalfields = array()) {
b0365ea5 872 $userfields = array(
61cca0b7 873 'id' => new external_value(PARAM_INT, 'ID of the user'),
ec80bc6b 874 'username' => new external_value(PARAM_RAW, 'The username', VALUE_OPTIONAL),
01479290
DC
875 'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL),
876 'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
877 'fullname' => new external_value(PARAM_NOTAGS, 'The fullname of the user'),
878 'email' => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost', VALUE_OPTIONAL),
071e68f9 879 'address' => new external_value(PARAM_TEXT, 'Postal address', VALUE_OPTIONAL),
01479290
DC
880 'phone1' => new external_value(PARAM_NOTAGS, 'Phone 1', VALUE_OPTIONAL),
881 'phone2' => new external_value(PARAM_NOTAGS, 'Phone 2', VALUE_OPTIONAL),
882 'icq' => new external_value(PARAM_NOTAGS, 'icq number', VALUE_OPTIONAL),
883 'skype' => new external_value(PARAM_NOTAGS, 'skype id', VALUE_OPTIONAL),
884 'yahoo' => new external_value(PARAM_NOTAGS, 'yahoo id', VALUE_OPTIONAL),
885 'aim' => new external_value(PARAM_NOTAGS, 'aim id', VALUE_OPTIONAL),
886 'msn' => new external_value(PARAM_NOTAGS, 'msn number', VALUE_OPTIONAL),
887 'department' => new external_value(PARAM_TEXT, 'department', VALUE_OPTIONAL),
888 'institution' => new external_value(PARAM_TEXT, 'institution', VALUE_OPTIONAL),
3a3f3b22 889 'idnumber' => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL),
01479290
DC
890 'interests' => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL),
891 'firstaccess' => new external_value(PARAM_INT, 'first access to the site (0 if never)', VALUE_OPTIONAL),
892 'lastaccess' => new external_value(PARAM_INT, 'last access to the site (0 if never)', VALUE_OPTIONAL),
b0365ea5
JM
893 'auth' => new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL),
894 'confirmed' => new external_value(PARAM_INT, 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL),
895 'lang' => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_OPTIONAL),
896 'theme' => new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL),
897 'timezone' => new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL),
898 'mailformat' => new external_value(PARAM_INT, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL),
01479290 899 'description' => new external_value(PARAM_RAW, 'User profile description', VALUE_OPTIONAL),
93ce0e82 900 'descriptionformat' => new external_format_value('description', VALUE_OPTIONAL),
01479290
DC
901 'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
902 'url' => new external_value(PARAM_URL, 'URL of the user', VALUE_OPTIONAL),
903 'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
904 'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'),
905 'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'),
906 'customfields' => new external_multiple_structure(
907 new external_single_structure(
908 array(
909 'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'),
910 'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
911 'name' => new external_value(PARAM_RAW, 'The name of the custom field'),
912 'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'),
913 )
bb1105ae 914 ), 'User custom fields (also known as user profile fields)', VALUE_OPTIONAL),
01479290
DC
915 'preferences' => new external_multiple_structure(
916 new external_single_structure(
917 array(
918 'name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preferences'),
919 'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
920 )
b0365ea5
JM
921 ), 'Users preferences', VALUE_OPTIONAL)
922 );
923 if (!empty($additionalfields)) {
924 $userfields = array_merge($userfields, $additionalfields);
925 }
926 return new external_single_structure($userfields);
01479290 927 }
b0365ea5 928
5d1017e1
JM
929}
930
4615817d
JM
931 /**
932 * Deprecated user external functions
933 *
934 * @package core_user
935 * @copyright 2009 Petr Skodak
936 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
937 * @since Moodle 2.0
938 * @deprecated Moodle 2.2 MDL-29106 - Please do not use this class any more.
4615817d 939 * @see core_user_external
5d1017e1
JM
940 */
941class moodle_user_external extends external_api {
942
943 /**
944 * Returns description of method parameters
4615817d 945 *
5d1017e1 946 * @return external_function_parameters
4615817d
JM
947 * @since Moodle 2.0
948 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 949 * @see core_user_external::create_users_parameters()
5d1017e1
JM
950 */
951 public static function create_users_parameters() {
952 return core_user_external::create_users_parameters();
953 }
954
955 /**
956 * Create one or more users
4615817d 957 *
5d1017e1
JM
958 * @param array $users An array of users to create.
959 * @return array An array of arrays
4615817d
JM
960 * @since Moodle 2.0
961 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 962 * @see core_user_external::create_users()
5d1017e1
JM
963 */
964 public static function create_users($users) {
965 return core_user_external::create_users($users);
966 }
967
968 /**
969 * Returns description of method result value
4615817d 970 *
5d1017e1 971 * @return external_description
4615817d
JM
972 * @since Moodle 2.0
973 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 974 * @see core_user_external::create_users_returns()
5d1017e1
JM
975 */
976 public static function create_users_returns() {
977 return core_user_external::create_users_returns();
978 }
979
980
981 /**
982 * Returns description of method parameters
4615817d 983 *
5d1017e1 984 * @return external_function_parameters
4615817d
JM
985 * @since Moodle 2.0
986 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 987 * @see core_user_external::delete_users_parameters()
5d1017e1
JM
988 */
989 public static function delete_users_parameters() {
990 return core_user_external::delete_users_parameters();
991 }
992
993 /**
994 * Delete users
4615817d 995 *
5d1017e1 996 * @param array $userids
e6acc551 997 * @return null
4615817d
JM
998 * @since Moodle 2.0
999 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1000 * @see core_user_external::delete_users()
5d1017e1
JM
1001 */
1002 public static function delete_users($userids) {
1003 return core_user_external::delete_users($userids);
1004 }
1005
1006 /**
1007 * Returns description of method result value
4615817d
JM
1008 *
1009 * @return null
1010 * @since Moodle 2.0
1011 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1012 * @see core_user_external::delete_users_returns()
5d1017e1
JM
1013 */
1014 public static function delete_users_returns() {
1015 return core_user_external::delete_users_returns();
1016 }
1017
1018
1019 /**
1020 * Returns description of method parameters
4615817d 1021 *
5d1017e1 1022 * @return external_function_parameters
4615817d
JM
1023 * @since Moodle 2.0
1024 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1025 * @see core_user_external::update_users_parameters()
5d1017e1
JM
1026 */
1027 public static function update_users_parameters() {
1028 return core_user_external::update_users_parameters();
1029 }
1030
1031 /**
1032 * Update users
4615817d 1033 *
5d1017e1 1034 * @param array $users
e6acc551 1035 * @return null
4615817d
JM
1036 * @since Moodle 2.0
1037 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1038 * @see core_user_external::update_users()
5d1017e1
JM
1039 */
1040 public static function update_users($users) {
1041 return core_user_external::update_users($users);
1042 }
1043
1044 /**
1045 * Returns description of method result value
4615817d
JM
1046 *
1047 * @return null
1048 * @since Moodle 2.0
1049 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1050 * @see core_user_external::update_users_returns()
5d1017e1
JM
1051 */
1052 public static function update_users_returns() {
1053 return core_user_external::update_users_returns();
1054 }
1055
1056 /**
1057 * Returns description of method parameters
4615817d 1058 *
5d1017e1 1059 * @return external_function_parameters
4615817d
JM
1060 * @since Moodle 2.0
1061 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1062 * @see core_user_external::get_users_by_id_parameters()
5d1017e1
JM
1063 */
1064 public static function get_users_by_id_parameters() {
1065 return core_user_external::get_users_by_id_parameters();
1066 }
1067
1068 /**
1069 * Get user information
1070 * - This function is matching the permissions of /user/profil.php
1071 * - It is also matching some permissions from /user/editadvanced.php for the following fields:
1072 * auth, confirmed, idnumber, lang, theme, timezone, mailformat
4615817d 1073 *
5d1017e1
JM
1074 * @param array $userids array of user ids
1075 * @return array An array of arrays describing users
4615817d
JM
1076 * @since Moodle 2.0
1077 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1078 * @see core_user_external::get_users_by_id()
5d1017e1
JM
1079 */
1080 public static function get_users_by_id($userids) {
1081 return core_user_external::get_users_by_id($userids);
1082 }
1083
1084 /**
1085 * Returns description of method result value
4615817d 1086 *
5d1017e1 1087 * @return external_description
4615817d
JM
1088 * @since Moodle 2.0
1089 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1090 * @see core_user_external::get_users_by_id_returns()
5d1017e1
JM
1091 */
1092 public static function get_users_by_id_returns() {
bb1105ae 1093 return core_user_external::get_users_by_id_returns();
5d1017e1
JM
1094 }
1095 /**
1096 * Returns description of method parameters
4615817d 1097 *
5d1017e1 1098 * @return external_function_parameters
4615817d
JM
1099 * @since Moodle 2.1
1100 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1101 * @see core_user_external::get_course_user_profiles_parameters()
5d1017e1
JM
1102 */
1103 public static function get_course_participants_by_id_parameters() {
1104 return core_user_external::get_course_user_profiles_parameters();
1105 }
1106
1107 /**
1108 * Get course participant's details
4615817d 1109 *
5d1017e1
JM
1110 * @param array $userlist array of user ids and according course ids
1111 * @return array An array of arrays describing course participants
4615817d
JM
1112 * @since Moodle 2.1
1113 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1114 * @see core_user_external::get_course_user_profiles()
5d1017e1
JM
1115 */
1116 public static function get_course_participants_by_id($userlist) {
1117 return core_user_external::get_course_user_profiles($userlist);
1118 }
1119
1120 /**
1121 * Returns description of method result value
4615817d 1122 *
5d1017e1 1123 * @return external_description
4615817d
JM
1124 * @since Moodle 2.1
1125 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1126 * @see core_user_external::get_course_user_profiles_returns()
5d1017e1
JM
1127 */
1128 public static function get_course_participants_by_id_returns() {
1129 return core_user_external::get_course_user_profiles_returns();
1130 }
ea4e96c2 1131
01479290
DC
1132 /**
1133 * Returns description of method parameters
4615817d 1134 *
01479290 1135 * @return external_function_parameters
4615817d
JM
1136 * @since Moodle 2.1
1137 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1138 * @see core_enrol_external::get_enrolled_users_parameters()
01479290
DC
1139 */
1140 public static function get_users_by_courseid_parameters() {
5d1017e1
JM
1141 global $CFG;
1142 require_once($CFG->dirroot . '/enrol/externallib.php');
1143 return core_enrol_external::get_enrolled_users_parameters();
01479290 1144 }
ea4e96c2 1145
01479290
DC
1146 /**
1147 * Get course participants details
4615817d 1148 *
01479290
DC
1149 * @param int $courseid course id
1150 * @param array $options options {
4615817d
JM
1151 * 'name' => option name
1152 * 'value' => option value
1153 * }
01479290 1154 * @return array An array of users
4615817d
JM
1155 * @since Moodle 2.1
1156 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1157 * @see core_enrol_external::get_enrolled_users()
01479290
DC
1158 */
1159 public static function get_users_by_courseid($courseid, $options) {
5d1017e1
JM
1160 global $CFG;
1161 require_once($CFG->dirroot . '/enrol/externallib.php');
1162 return core_enrol_external::get_enrolled_users($courseid, $options);
ea4e96c2 1163 }
ea4e96c2
DC
1164 /**
1165 * Returns description of method result value
4615817d 1166 *
ea4e96c2 1167 * @return external_description
4615817d
JM
1168 * @since Moodle 2.1
1169 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
4615817d 1170 * @see core_enrol_external::get_enrolled_users_returns()
ea4e96c2 1171 */
01479290 1172 public static function get_users_by_courseid_returns() {
5d1017e1
JM
1173 global $CFG;
1174 require_once($CFG->dirroot . '/enrol/externallib.php');
1175 return core_enrol_external::get_enrolled_users_returns();
5de592b1 1176 }
b0365ea5 1177}