3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
22 * @subpackage webservice
23 * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once("$CFG->libdir/externallib.php");
32 class core_user_external
extends external_api
{
35 * Returns description of method parameters
36 * @return external_function_parameters
38 public static function create_users_parameters() {
41 return new external_function_parameters(
43 'users' => new external_multiple_structure(
44 new external_single_structure(
46 'username' => new external_value(PARAM_RAW
, 'Username policy is defined in Moodle security config'),
47 'password' => new external_value(PARAM_RAW
, 'Plain text password consisting of any characters'),
48 'firstname' => new external_value(PARAM_NOTAGS
, 'The first name(s) of the user'),
49 'lastname' => new external_value(PARAM_NOTAGS
, 'The family name of the user'),
50 'email' => new external_value(PARAM_EMAIL
, 'A valid and unique email address'),
51 'auth' => new external_value(PARAM_PLUGIN
, 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT
, 'manual', NULL_NOT_ALLOWED
),
52 'idnumber' => new external_value(PARAM_RAW
, 'An arbitrary ID code number perhaps from the institution', VALUE_DEFAULT
, ''),
53 'lang' => new external_value(PARAM_SAFEDIR
, 'Language code such as "en", must exist on server', VALUE_DEFAULT
, $CFG->lang
, NULL_NOT_ALLOWED
),
54 'theme' => new external_value(PARAM_PLUGIN
, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL
),
55 'timezone' => new external_value(PARAM_TIMEZONE
, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL
),
56 'mailformat' => new external_value(PARAM_INTEGER
, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL
),
57 'description' => new external_value(PARAM_TEXT
, 'User profile description, no HTML', VALUE_OPTIONAL
),
58 'city' => new external_value(PARAM_NOTAGS
, 'Home city of the user', VALUE_OPTIONAL
),
59 'country' => new external_value(PARAM_ALPHA
, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL
),
60 'preferences' => new external_multiple_structure(
61 new external_single_structure(
63 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the preference'),
64 'value' => new external_value(PARAM_RAW
, 'The value of the preference')
66 ), 'User preferences', VALUE_OPTIONAL
),
67 'customfields' => new external_multiple_structure(
68 new external_single_structure(
70 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the custom field'),
71 'value' => new external_value(PARAM_RAW
, 'The value of the custom field')
73 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL
)
82 * Create one or more users
84 * @param array $users An array of users to create.
85 * @return array An array of arrays
87 public static function create_users($users) {
89 require_once($CFG->dirroot
."/lib/weblib.php");
90 require_once($CFG->dirroot
."/user/lib.php");
91 require_once($CFG->dirroot
."/user/profile/lib.php"); //required for customfields related function
92 //TODO: move the functions somewhere else as
93 //they are "user" related
95 // Ensure the current user is allowed to run this function
96 $context = get_context_instance(CONTEXT_SYSTEM
);
97 self
::validate_context($context);
98 require_capability('moodle/user:create', $context);
100 // Do basic automatic PARAM checks on incoming data, using params description
101 // If any problems are found then exceptions are thrown with helpful error messages
102 $params = self
::validate_parameters(self
::create_users_parameters(), array('users'=>$users));
104 $availableauths = get_plugin_list('auth');
105 unset($availableauths['mnet']); // these would need mnethostid too
106 unset($availableauths['webservice']); // we do not want new webservice users for now
108 $availablethemes = get_plugin_list('theme');
109 $availablelangs = get_string_manager()->get_list_of_translations();
111 $transaction = $DB->start_delegated_transaction();
114 foreach ($params['users'] as $user) {
115 // Make sure that the username doesn't already exist
116 if ($DB->record_exists('user', array('username'=>$user['username'], 'mnethostid'=>$CFG->mnet_localhost_id
))) {
117 throw new invalid_parameter_exception('Username already exists: '.$user['username']);
120 // Make sure auth is valid
121 if (empty($availableauths[$user['auth']])) {
122 throw new invalid_parameter_exception('Invalid authentication type: '.$user['auth']);
125 // Make sure lang is valid
126 if (empty($availablelangs[$user['lang']])) {
127 throw new invalid_parameter_exception('Invalid language code: '.$user['lang']);
130 // Make sure lang is valid
131 if (!empty($user['theme']) && empty($availablethemes[$user['theme']])) { //theme is VALUE_OPTIONAL,
132 // so no default value.
133 // We need to test if the client sent it
134 // => !empty($user['theme'])
135 throw new invalid_parameter_exception('Invalid theme: '.$user['theme']);
138 $user['confirmed'] = true;
139 $user['mnethostid'] = $CFG->mnet_localhost_id
;
141 // Start of user info validation.
142 // Lets make sure we validate current user info as handled by current GUI. see user/editadvanced_form.php function validation()
143 if (!validate_email($user['email'])) {
144 throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
145 } else if ($DB->record_exists('user', array('email'=>$user['email'], 'mnethostid'=>$user['mnethostid']))) {
146 throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
148 // End of user info validation.
150 // create the user data now!
151 $user['id'] = user_create_user($user);
154 if(!empty($user['customfields'])) {
155 foreach($user['customfields'] as $customfield) {
156 $user["profile_field_".$customfield['type']] = $customfield['value']; //profile_save_data() saves profile file
157 //it's expecting a user with the correct id,
158 //and custom field to be named profile_field_"shortname"
160 profile_save_data((object) $user);
164 if (!empty($user['preferences'])) {
165 foreach($user['preferences'] as $preference) {
166 set_user_preference($preference['type'], $preference['value'],$user['id']);
170 $userids[] = array('id'=>$user['id'], 'username'=>$user['username']);
173 $transaction->allow_commit();
179 * Returns description of method result value
180 * @return external_description
182 public static function create_users_returns() {
183 return new external_multiple_structure(
184 new external_single_structure(
186 'id' => new external_value(PARAM_INT
, 'user id'),
187 'username' => new external_value(PARAM_RAW
, 'user name'),
195 * Returns description of method parameters
196 * @return external_function_parameters
198 public static function delete_users_parameters() {
199 return new external_function_parameters(
201 'userids' => new external_multiple_structure(new external_value(PARAM_INT
, 'user ID')),
208 * @param array $userids
211 public static function delete_users($userids) {
212 global $CFG, $DB, $USER;
213 require_once($CFG->dirroot
."/user/lib.php");
215 // Ensure the current user is allowed to run this function
216 $context = get_context_instance(CONTEXT_SYSTEM
);
217 require_capability('moodle/user:delete', $context);
218 self
::validate_context($context);
220 $params = self
::validate_parameters(self
::delete_users_parameters(), array('userids'=>$userids));
222 $transaction = $DB->start_delegated_transaction();
224 foreach ($params['userids'] as $userid) {
225 $user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST
);
226 // must not allow deleting of admins or self!!!
227 if (is_siteadmin($user)) {
228 throw new moodle_exception('useradminodelete', 'error');
230 if ($USER->id
== $user->id
) {
231 throw new moodle_exception('usernotdeletederror', 'error');
233 user_delete_user($user);
236 $transaction->allow_commit();
242 * Returns description of method result value
243 * @return external_description
245 public static function delete_users_returns() {
251 * Returns description of method parameters
252 * @return external_function_parameters
254 public static function update_users_parameters() {
256 return new external_function_parameters(
258 'users' => new external_multiple_structure(
259 new external_single_structure(
261 'id' => new external_value(PARAM_NUMBER
, 'ID of the user'),
262 'username' => new external_value(PARAM_RAW
, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL
, '',NULL_NOT_ALLOWED
),
263 'password' => new external_value(PARAM_RAW
, 'Plain text password consisting of any characters', VALUE_OPTIONAL
, '',NULL_NOT_ALLOWED
),
264 'firstname' => new external_value(PARAM_NOTAGS
, 'The first name(s) of the user', VALUE_OPTIONAL
, '',NULL_NOT_ALLOWED
),
265 'lastname' => new external_value(PARAM_NOTAGS
, 'The family name of the user', VALUE_OPTIONAL
),
266 'email' => new external_value(PARAM_EMAIL
, 'A valid and unique email address', VALUE_OPTIONAL
, '',NULL_NOT_ALLOWED
),
267 'auth' => new external_value(PARAM_PLUGIN
, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL
, '', NULL_NOT_ALLOWED
),
268 'idnumber' => new external_value(PARAM_RAW
, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL
),
269 'lang' => new external_value(PARAM_SAFEDIR
, 'Language code such as "en", must exist on server', VALUE_OPTIONAL
, '', NULL_NOT_ALLOWED
),
270 'theme' => new external_value(PARAM_PLUGIN
, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL
),
271 'timezone' => new external_value(PARAM_TIMEZONE
, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL
),
272 'mailformat' => new external_value(PARAM_INTEGER
, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL
),
273 'description' => new external_value(PARAM_TEXT
, 'User profile description, no HTML', VALUE_OPTIONAL
),
274 'city' => new external_value(PARAM_NOTAGS
, 'Home city of the user', VALUE_OPTIONAL
),
275 'country' => new external_value(PARAM_ALPHA
, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL
),
276 'customfields' => new external_multiple_structure(
277 new external_single_structure(
279 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the custom field'),
280 'value' => new external_value(PARAM_RAW
, 'The value of the custom field')
282 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL
),
283 'preferences' => new external_multiple_structure(
284 new external_single_structure(
286 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the preference'),
287 'value' => new external_value(PARAM_RAW
, 'The value of the preference')
289 ), 'User preferences', VALUE_OPTIONAL
),
299 * @param array $users
302 public static function update_users($users) {
304 require_once($CFG->dirroot
."/user/lib.php");
305 require_once($CFG->dirroot
."/user/profile/lib.php"); //required for customfields related function
306 //TODO: move the functions somewhere else as
307 //they are "user" related
309 // Ensure the current user is allowed to run this function
310 $context = get_context_instance(CONTEXT_SYSTEM
);
311 require_capability('moodle/user:update', $context);
312 self
::validate_context($context);
314 $params = self
::validate_parameters(self
::update_users_parameters(), array('users'=>$users));
316 $transaction = $DB->start_delegated_transaction();
318 foreach ($params['users'] as $user) {
319 user_update_user($user);
320 //update user custom fields
321 if(!empty($user['customfields'])) {
323 foreach($user['customfields'] as $customfield) {
324 $user["profile_field_".$customfield['type']] = $customfield['value']; //profile_save_data() saves profile file
325 //it's expecting a user with the correct id,
326 //and custom field to be named profile_field_"shortname"
328 profile_save_data((object) $user);
332 if (!empty($user['preferences'])) {
333 foreach($user['preferences'] as $preference) {
334 set_user_preference($preference['type'], $preference['value'],$user['id']);
339 $transaction->allow_commit();
345 * Returns description of method result value
346 * @return external_description
348 public static function update_users_returns() {
353 * Returns description of method parameters
354 * @return external_function_parameters
356 public static function get_users_by_id_parameters() {
357 return new external_function_parameters(
359 'userids' => new external_multiple_structure(new external_value(PARAM_INT
, 'user ID')),
365 * Get user information
366 * - This function is matching the permissions of /user/profil.php
367 * - It is also matching some permissions from /user/editadvanced.php for the following fields:
368 * auth, confirmed, idnumber, lang, theme, timezone, mailformat
369 * @param array $userids array of user ids
370 * @return array An array of arrays describing users
372 public static function get_users_by_id($userids) {
373 global $CFG, $USER, $DB;
374 require_once($CFG->dirroot
. "/user/lib.php");
376 $params = self
::validate_parameters(self
::get_users_by_id_parameters(),
377 array('userids'=>$userids));
379 list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER
, 'ctx');
380 list($sqluserids, $params) = $DB->get_in_or_equal($userids);
381 $usersql = "SELECT u.* $uselect
383 WHERE u.id $sqluserids";
384 $users = $DB->get_recordset_sql($usersql, $params);
387 $hasuserupdatecap = has_capability('moodle/user:update', get_system_context());
388 foreach ($users as $user) {
389 if (!empty($user->deleted
)) {
392 context_instance_preload($user);
393 $usercontext = get_context_instance(CONTEXT_USER
, $user->id
);
394 self
::validate_context($usercontext);
395 $currentuser = ($user->id
== $USER->id
);
397 if ($userarray = user_get_user_details($user)) {
398 //fields matching permissions from /user/editadvanced.php
399 if ($currentuser or $hasuserupdatecap) {
400 $userarray['auth'] = $user->auth
;
401 $userarray['confirmed'] = $user->confirmed
;
402 $userarray['idnumber'] = $user->idnumber
;
403 $userarray['lang'] = $user->lang
;
404 $userarray['theme'] = $user->theme
;
405 $userarray['timezone'] = $user->timezone
;
406 $userarray['mailformat'] = $user->mailformat
;
408 $result[] = $userarray;
417 * Returns description of method result value
418 * @return external_description
420 public static function get_users_by_id_returns() {
421 return new external_multiple_structure(
422 new external_single_structure(
424 'id' => new external_value(PARAM_NUMBER
, 'ID of the user'),
425 'username' => new external_value(PARAM_RAW
, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL
),
426 'firstname' => new external_value(PARAM_NOTAGS
, 'The first name(s) of the user', VALUE_OPTIONAL
),
427 'lastname' => new external_value(PARAM_NOTAGS
, 'The family name of the user', VALUE_OPTIONAL
),
428 'fullname' => new external_value(PARAM_NOTAGS
, 'The fullname of the user'),
429 'email' => new external_value(PARAM_TEXT
, 'An email address - allow email as root@localhost', VALUE_OPTIONAL
),
430 'address' => new external_value(PARAM_MULTILANG
, 'Postal address', VALUE_OPTIONAL
),
431 'phone1' => new external_value(PARAM_NOTAGS
, 'Phone 1', VALUE_OPTIONAL
),
432 'phone2' => new external_value(PARAM_NOTAGS
, 'Phone 2', VALUE_OPTIONAL
),
433 'icq' => new external_value(PARAM_NOTAGS
, 'icq number', VALUE_OPTIONAL
),
434 'skype' => new external_value(PARAM_NOTAGS
, 'skype id', VALUE_OPTIONAL
),
435 'yahoo' => new external_value(PARAM_NOTAGS
, 'yahoo id', VALUE_OPTIONAL
),
436 'aim' => new external_value(PARAM_NOTAGS
, 'aim id', VALUE_OPTIONAL
),
437 'msn' => new external_value(PARAM_NOTAGS
, 'msn number', VALUE_OPTIONAL
),
438 'department' => new external_value(PARAM_TEXT
, 'department', VALUE_OPTIONAL
),
439 'institution' => new external_value(PARAM_TEXT
, 'institution', VALUE_OPTIONAL
),
440 'interests' => new external_value(PARAM_TEXT
, 'user interests (separated by commas)', VALUE_OPTIONAL
),
441 'firstaccess' => new external_value(PARAM_INT
, 'first access to the site (0 if never)', VALUE_OPTIONAL
),
442 'lastaccess' => new external_value(PARAM_INT
, 'last access to the site (0 if never)', VALUE_OPTIONAL
),
443 'auth' => new external_value(PARAM_PLUGIN
, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL
),
444 'confirmed' => new external_value(PARAM_NUMBER
, 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL
),
445 'idnumber' => new external_value(PARAM_RAW
, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL
),
446 'lang' => new external_value(PARAM_SAFEDIR
, 'Language code such as "en", must exist on server', VALUE_OPTIONAL
),
447 'theme' => new external_value(PARAM_PLUGIN
, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL
),
448 'timezone' => new external_value(PARAM_TIMEZONE
, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL
),
449 'mailformat' => new external_value(PARAM_INTEGER
, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL
),
450 'description' => new external_value(PARAM_RAW
, 'User profile description', VALUE_OPTIONAL
),
451 'descriptionformat' => new external_value(PARAM_INT
, 'User profile description format', VALUE_OPTIONAL
),
452 'city' => new external_value(PARAM_NOTAGS
, 'Home city of the user', VALUE_OPTIONAL
),
453 'url' => new external_value(PARAM_URL
, 'URL of the user', VALUE_OPTIONAL
),
454 'country' => new external_value(PARAM_ALPHA
, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL
),
455 'profileimageurlsmall' => new external_value(PARAM_URL
, 'User image profile URL - small version'),
456 'profileimageurl' => new external_value(PARAM_URL
, 'User image profile URL - big version'),
457 'customfields' => new external_multiple_structure(
458 new external_single_structure(
460 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The type of the custom field - text field, checkbox...'),
461 'value' => new external_value(PARAM_RAW
, 'The value of the custom field'),
462 'name' => new external_value(PARAM_RAW
, 'The name of the custom field'),
463 'shortname' => new external_value(PARAM_RAW
, 'The shortname of the custom field - to be able to build the field class in the code'),
465 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL
),
466 'preferences' => new external_multiple_structure(
467 new external_single_structure(
469 'name' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the preferences'),
470 'value' => new external_value(PARAM_RAW
, 'The value of the custom field'),
472 ), 'User preferences', VALUE_OPTIONAL
),
473 'enrolledcourses' => new external_multiple_structure(
474 new external_single_structure(
476 'id' => new external_value(PARAM_INT
, 'Id of the course'),
477 'fullname' => new external_value(PARAM_RAW
, 'Fullname of the course'),
478 'shortname' => new external_value(PARAM_RAW
, 'Shortname of the course')
480 ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL
)
486 * Returns description of method parameters
487 * @return external_function_parameters
489 public static function get_course_user_profiles_parameters() {
490 return new external_function_parameters(
492 'userlist' => new external_multiple_structure(
493 new external_single_structure(
495 'userid' => new external_value(PARAM_INT
, 'userid'),
496 'courseid' => new external_value(PARAM_INT
, 'courseid'),
505 * Get course participant's details
506 * @param array $userlist array of user ids and according course ids
507 * @return array An array of arrays describing course participants
509 public static function get_course_user_profiles($userlist) {
510 global $CFG, $USER, $DB;
511 require_once($CFG->dirroot
. "/user/lib.php");
512 $params = self
::validate_parameters(self
::get_course_user_profiles_parameters(), array('userlist'=>$userlist));
515 $courseids = array();
516 foreach ($params['userlist'] as $value) {
517 $userids[] = $value['userid'];
518 $courseids[$value['userid']] = $value['courseid'];
523 list($cselect, $cjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE
, 'ctx');
524 list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids));
525 $coursesql = "SELECT c.* $cselect
526 FROM {course} c $cjoin
527 WHERE c.id $sqlcourseids";
528 $rs = $DB->get_recordset_sql($coursesql, $params);
529 foreach ($rs as $course) {
530 // adding course contexts to cache
531 context_instance_preload($course);
533 $courses[$course->id
] = $course;
537 list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER
, 'ctx');
538 list($sqluserids, $params) = $DB->get_in_or_equal($userids);
539 $usersql = "SELECT u.* $uselect
541 WHERE u.id $sqluserids";
542 $users = $DB->get_recordset_sql($usersql, $params);
544 foreach ($users as $user) {
545 if (!empty($user->deleted
)) {
548 context_instance_preload($user);
549 $course = $courses[$courseids[$user->id
]];
550 $context = get_context_instance(CONTEXT_COURSE
, $courseids[$user->id
]);
551 self
::validate_context($context);
552 if ($userarray = user_get_user_details($user, $course)) {
553 $result[] = $userarray;
563 * Returns description of method result value
564 * @return external_description
566 public static function get_course_user_profiles_returns() {
567 return new external_multiple_structure(
568 new external_single_structure(
570 'id' => new external_value(PARAM_NUMBER
, 'ID of the user'),
571 'username' => new external_value(PARAM_RAW
, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL
),
572 'firstname' => new external_value(PARAM_NOTAGS
, 'The first name(s) of the user', VALUE_OPTIONAL
),
573 'lastname' => new external_value(PARAM_NOTAGS
, 'The family name of the user', VALUE_OPTIONAL
),
574 'fullname' => new external_value(PARAM_NOTAGS
, 'The fullname of the user'),
575 'email' => new external_value(PARAM_TEXT
, 'An email address - allow email as root@localhost', VALUE_OPTIONAL
),
576 'address' => new external_value(PARAM_MULTILANG
, 'Postal address', VALUE_OPTIONAL
),
577 'phone1' => new external_value(PARAM_NOTAGS
, 'Phone 1', VALUE_OPTIONAL
),
578 'phone2' => new external_value(PARAM_NOTAGS
, 'Phone 2', VALUE_OPTIONAL
),
579 'icq' => new external_value(PARAM_NOTAGS
, 'icq number', VALUE_OPTIONAL
),
580 'skype' => new external_value(PARAM_NOTAGS
, 'skype id', VALUE_OPTIONAL
),
581 'yahoo' => new external_value(PARAM_NOTAGS
, 'yahoo id', VALUE_OPTIONAL
),
582 'aim' => new external_value(PARAM_NOTAGS
, 'aim id', VALUE_OPTIONAL
),
583 'msn' => new external_value(PARAM_NOTAGS
, 'msn number', VALUE_OPTIONAL
),
584 'department' => new external_value(PARAM_TEXT
, 'department', VALUE_OPTIONAL
),
585 'institution' => new external_value(PARAM_TEXT
, 'institution', VALUE_OPTIONAL
),
586 'interests' => new external_value(PARAM_TEXT
, 'user interests (separated by commas)', VALUE_OPTIONAL
),
587 'firstaccess' => new external_value(PARAM_INT
, 'first access to the site (0 if never)', VALUE_OPTIONAL
),
588 'lastaccess' => new external_value(PARAM_INT
, 'last access to the site (0 if never)', VALUE_OPTIONAL
),
589 'description' => new external_value(PARAM_RAW
, 'User profile description', VALUE_OPTIONAL
),
590 'descriptionformat' => new external_value(PARAM_INT
, 'User profile description format', VALUE_OPTIONAL
),
591 'city' => new external_value(PARAM_NOTAGS
, 'Home city of the user', VALUE_OPTIONAL
),
592 'url' => new external_value(PARAM_URL
, 'URL of the user', VALUE_OPTIONAL
),
593 'country' => new external_value(PARAM_ALPHA
, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL
),
594 'profileimageurlsmall' => new external_value(PARAM_URL
, 'User image profile URL - small version'),
595 'profileimageurl' => new external_value(PARAM_URL
, 'User image profile URL - big version'),
596 'customfields' => new external_multiple_structure(
597 new external_single_structure(
599 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The type of the custom field - text field, checkbox...'),
600 'value' => new external_value(PARAM_RAW
, 'The value of the custom field'),
601 'name' => new external_value(PARAM_RAW
, 'The name of the custom field'),
602 'shortname' => new external_value(PARAM_RAW
, 'The shortname of the custom field - to be able to build the field class in the code'),
604 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL
),
605 'groups' => new external_multiple_structure(
606 new external_single_structure(
608 'id' => new external_value(PARAM_INT
, 'group id'),
609 'name' => new external_value(PARAM_RAW
, 'group name'),
610 'description' => new external_value(PARAM_RAW
, 'group description'),
612 ), 'user groups', VALUE_OPTIONAL
),
613 'roles' => new external_multiple_structure(
614 new external_single_structure(
616 'roleid' => new external_value(PARAM_INT
, 'role id'),
617 'name' => new external_value(PARAM_RAW
, 'role name'),
618 'shortname' => new external_value(PARAM_ALPHANUMEXT
, 'role shortname'),
619 'sortorder' => new external_value(PARAM_INT
, 'role sortorder')
621 ), 'user roles', VALUE_OPTIONAL
),
622 'preferences' => new external_multiple_structure(
623 new external_single_structure(
625 'name' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the preferences'),
626 'value' => new external_value(PARAM_RAW
, 'The value of the custom field'),
628 ), 'User preferences', VALUE_OPTIONAL
),
629 'enrolledcourses' => new external_multiple_structure(
630 new external_single_structure(
632 'id' => new external_value(PARAM_INT
, 'Id of the course'),
633 'fullname' => new external_value(PARAM_RAW
, 'Fullname of the course'),
634 'shortname' => new external_value(PARAM_RAW
, 'Shortname of the course')
636 ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL
)
644 * Deprecated user functions
645 * @deprecated since Moodle 2.2 please use core_user_external instead
647 class moodle_user_external
extends external_api
{
650 * Returns description of method parameters
651 * @deprecated since Moodle 2.2 please use core_user_external::create_users_parameters instead
652 * @return external_function_parameters
654 public static function create_users_parameters() {
655 return core_user_external
::create_users_parameters();
659 * Create one or more users
660 * @deprecated since Moodle 2.2 please use core_user_external::create_users instead
661 * @param array $users An array of users to create.
662 * @return array An array of arrays
664 public static function create_users($users) {
665 return core_user_external
::create_users($users);
669 * Returns description of method result value
670 * @deprecated since Moodle 2.2 please use core_user_external::create_users_returns instead
671 * @return external_description
673 public static function create_users_returns() {
674 return core_user_external
::create_users_returns();
679 * Returns description of method parameters
680 * @deprecated since Moodle 2.2 please use core_user_external::delete_users_parameters instead
681 * @return external_function_parameters
683 public static function delete_users_parameters() {
684 return core_user_external
::delete_users_parameters();
689 * @deprecated since Moodle 2.2 please use core_user_external::delete_users instead
690 * @param array $userids
693 public static function delete_users($userids) {
694 return core_user_external
::delete_users($userids);
698 * Returns description of method result value
699 * @deprecated since Moodle 2.2 please use core_user_external::delete_users_returns instead
700 * @return external_description
702 public static function delete_users_returns() {
703 return core_user_external
::delete_users_returns();
708 * Returns description of method parameters
709 * @deprecated since Moodle 2.2 please use core_user_external::update_users_parameters instead
710 * @return external_function_parameters
712 public static function update_users_parameters() {
713 return core_user_external
::update_users_parameters();
718 * @deprecated since Moodle 2.2 please use core_user_external::update_users instead
719 * @param array $users
722 public static function update_users($users) {
723 return core_user_external
::update_users($users);
727 * Returns description of method result value
728 * @deprecated since Moodle 2.2 please use core_user_external::update_users_returns instead
729 * @return external_description
731 public static function update_users_returns() {
732 return core_user_external
::update_users_returns();
736 * Returns description of method parameters
737 * @deprecated since Moodle 2.2 please use core_user_external::get_users_by_id_parameters instead
738 * @return external_function_parameters
740 public static function get_users_by_id_parameters() {
741 return core_user_external
::get_users_by_id_parameters();
745 * Get user information
746 * - This function is matching the permissions of /user/profil.php
747 * - It is also matching some permissions from /user/editadvanced.php for the following fields:
748 * auth, confirmed, idnumber, lang, theme, timezone, mailformat
749 * @deprecated since Moodle 2.2 please use core_user_external::get_users_by_id instead
750 * @param array $userids array of user ids
751 * @return array An array of arrays describing users
753 public static function get_users_by_id($userids) {
754 return core_user_external
::get_users_by_id($userids);
758 * Returns description of method result value
759 * @deprecated since Moodle 2.2 please use core_user_external::get_users_by_id_returns instead
760 * @return external_description
762 public static function get_users_by_id_returns() {
763 return core_user_external
::get_users_by_id_returns();
766 * Returns description of method parameters
767 * @deprecated since Moodle 2.2 please use core_user_external::get_course_user_profiles_parameters instead
768 * @return external_function_parameters
770 public static function get_course_participants_by_id_parameters() {
771 return core_user_external
::get_course_user_profiles_parameters();
775 * Get course participant's details
776 * @deprecated since Moodle 2.2 please use core_user_external::get_course_user_profiles instead
777 * @param array $userlist array of user ids and according course ids
778 * @return array An array of arrays describing course participants
780 public static function get_course_participants_by_id($userlist) {
781 return core_user_external
::get_course_user_profiles($userlist);
785 * Returns description of method result value
786 * @deprecated since Moodle 2.2 please use core_user_external::get_course_user_profiles_returns instead
787 * @return external_description
789 public static function get_course_participants_by_id_returns() {
790 return core_user_external
::get_course_user_profiles_returns();
794 * Returns description of method parameters
795 * @deprecated since Moodle 2.2 please use core_enrol_external::get_enrolled_users_parameters instead
796 * @return external_function_parameters
798 public static function get_users_by_courseid_parameters() {
800 require_once($CFG->dirroot
. '/enrol/externallib.php');
801 return core_enrol_external
::get_enrolled_users_parameters();
805 * Get course participants details
806 * @deprecated since Moodle 2.2 please use core_enrol_external::get_enrolled_users instead
807 * @param int $courseid course id
808 * @param array $options options {
809 * 'name' => option name
810 * 'value' => option value
812 * @return array An array of users
814 public static function get_users_by_courseid($courseid, $options) {
816 require_once($CFG->dirroot
. '/enrol/externallib.php');
817 return core_enrol_external
::get_enrolled_users($courseid, $options);
820 * Returns description of method result value
821 * @deprecated since Moodle 2.2 please use core_enrol_external::get_enrolled_users_returns instead
822 * @return external_description
824 public static function get_users_by_courseid_returns() {
826 require_once($CFG->dirroot
. '/enrol/externallib.php');
827 return core_enrol_external
::get_enrolled_users_returns();