2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
22 * @copyright 2009 Petr Skodak
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once("$CFG->libdir/externallib.php");
29 * User external functions
33 * @copyright 2011 Jerome Mouneyrac
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class core_user_external
extends external_api
{
40 * Returns description of method parameters
42 * @return external_function_parameters
45 public static function create_users_parameters() {
48 return new external_function_parameters(
50 'users' => new external_multiple_structure(
51 new external_single_structure(
54 new external_value(PARAM_USERNAME
, 'Username policy is defined in Moodle security config.'),
56 new external_value(PARAM_RAW
, 'Plain text password consisting of any characters'),
58 new external_value(PARAM_NOTAGS
, 'The first name(s) of the user'),
60 new external_value(PARAM_NOTAGS
, 'The family name of the user'),
62 new external_value(PARAM_EMAIL
, 'A valid and unique email address'),
64 new external_value(PARAM_PLUGIN
, 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT
,
65 'manual', NULL_NOT_ALLOWED
),
67 new external_value(PARAM_RAW
, 'An arbitrary ID code number perhaps from the institution',
70 new external_value(PARAM_SAFEDIR
, 'Language code such as "en", must exist on server', VALUE_DEFAULT
,
71 $CFG->lang
, NULL_NOT_ALLOWED
),
73 new external_value(PARAM_PLUGIN
, 'Calendar type such as "gregorian", must exist on server',
74 VALUE_DEFAULT
, $CFG->calendartype
, VALUE_OPTIONAL
),
76 new external_value(PARAM_PLUGIN
, 'Theme name such as "standard", must exist on server',
79 new external_value(PARAM_TIMEZONE
, 'Timezone code such as Australia/Perth, or 99 for default',
82 new external_value(PARAM_INT
, 'Mail format code is 0 for plain text, 1 for HTML etc',
85 new external_value(PARAM_TEXT
, 'User profile description, no HTML', VALUE_OPTIONAL
),
87 new external_value(PARAM_NOTAGS
, 'Home city of the user', VALUE_OPTIONAL
),
89 new external_value(PARAM_ALPHA
, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL
),
90 'firstnamephonetic' =>
91 new external_value(PARAM_NOTAGS
, 'The first name(s) phonetically of the user', VALUE_OPTIONAL
),
93 new external_value(PARAM_NOTAGS
, 'The family name phonetically of the user', VALUE_OPTIONAL
),
95 new external_value(PARAM_NOTAGS
, 'The middle name of the user', VALUE_OPTIONAL
),
97 new external_value(PARAM_NOTAGS
, 'The alternate name of the user', VALUE_OPTIONAL
),
98 'preferences' => new external_multiple_structure(
99 new external_single_structure(
101 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the preference'),
102 'value' => new external_value(PARAM_RAW
, 'The value of the preference')
104 ), 'User preferences', VALUE_OPTIONAL
),
105 'customfields' => new external_multiple_structure(
106 new external_single_structure(
108 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the custom field'),
109 'value' => new external_value(PARAM_RAW
, 'The value of the custom field')
111 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL
)
120 * Create one or more users.
122 * @throws invalid_parameter_exception
123 * @param array $users An array of users to create.
124 * @return array An array of arrays
127 public static function create_users($users) {
129 require_once($CFG->dirroot
."/lib/weblib.php");
130 require_once($CFG->dirroot
."/user/lib.php");
131 require_once($CFG->dirroot
."/user/profile/lib.php"); // Required for customfields related function.
133 // Ensure the current user is allowed to run this function.
134 $context = context_system
::instance();
135 self
::validate_context($context);
136 require_capability('moodle/user:create', $context);
138 // Do basic automatic PARAM checks on incoming data, using params description.
139 // If any problems are found then exceptions are thrown with helpful error messages.
140 $params = self
::validate_parameters(self
::create_users_parameters(), array('users' => $users));
142 $availableauths = core_component
::get_plugin_list('auth');
143 unset($availableauths['mnet']); // These would need mnethostid too.
144 unset($availableauths['webservice']); // We do not want new webservice users for now.
146 $availablethemes = core_component
::get_plugin_list('theme');
147 $availablelangs = get_string_manager()->get_list_of_translations();
149 $transaction = $DB->start_delegated_transaction();
152 foreach ($params['users'] as $user) {
153 // Make sure that the username doesn't already exist.
154 if ($DB->record_exists('user', array('username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id
))) {
155 throw new invalid_parameter_exception('Username already exists: '.$user['username']);
158 // Make sure auth is valid.
159 if (empty($availableauths[$user['auth']])) {
160 throw new invalid_parameter_exception('Invalid authentication type: '.$user['auth']);
163 // Make sure lang is valid.
164 if (empty($availablelangs[$user['lang']])) {
165 throw new invalid_parameter_exception('Invalid language code: '.$user['lang']);
168 // Make sure lang is valid.
169 if (!empty($user['theme']) && empty($availablethemes[$user['theme']])) { // Theme is VALUE_OPTIONAL,
170 // so no default value
171 // We need to test if the client sent it
172 // => !empty($user['theme']).
173 throw new invalid_parameter_exception('Invalid theme: '.$user['theme']);
176 $user['confirmed'] = true;
177 $user['mnethostid'] = $CFG->mnet_localhost_id
;
179 // Start of user info validation.
180 // Make sure we validate current user info as handled by current GUI. See user/editadvanced_form.php func validation().
181 if (!validate_email($user['email'])) {
182 throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
183 } else if ($DB->record_exists('user', array('email' => $user['email'], 'mnethostid' => $user['mnethostid']))) {
184 throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
186 // End of user info validation.
188 // Create the user data now!
189 $user['id'] = user_create_user($user, true, false);
192 if (!empty($user['customfields'])) {
193 foreach ($user['customfields'] as $customfield) {
194 // Profile_save_data() saves profile file it's expecting a user with the correct id,
195 // and custom field to be named profile_field_"shortname".
196 $user["profile_field_".$customfield['type']] = $customfield['value'];
198 profile_save_data((object) $user);
202 \core\event\user_created
::create_from_userid($user['id'])->trigger();
205 if (!empty($user['preferences'])) {
206 foreach ($user['preferences'] as $preference) {
207 set_user_preference($preference['type'], $preference['value'], $user['id']);
211 $userids[] = array('id' => $user['id'], 'username' => $user['username']);
214 $transaction->allow_commit();
220 * Returns description of method result value
222 * @return external_description
225 public static function create_users_returns() {
226 return new external_multiple_structure(
227 new external_single_structure(
229 'id' => new external_value(PARAM_INT
, 'user id'),
230 'username' => new external_value(PARAM_USERNAME
, 'user name'),
238 * Returns description of method parameters
240 * @return external_function_parameters
243 public static function delete_users_parameters() {
244 return new external_function_parameters(
246 'userids' => new external_multiple_structure(new external_value(PARAM_INT
, 'user ID')),
254 * @throws moodle_exception
255 * @param array $userids
259 public static function delete_users($userids) {
260 global $CFG, $DB, $USER;
261 require_once($CFG->dirroot
."/user/lib.php");
263 // Ensure the current user is allowed to run this function.
264 $context = context_system
::instance();
265 require_capability('moodle/user:delete', $context);
266 self
::validate_context($context);
268 $params = self
::validate_parameters(self
::delete_users_parameters(), array('userids' => $userids));
270 $transaction = $DB->start_delegated_transaction();
272 foreach ($params['userids'] as $userid) {
273 $user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0), '*', MUST_EXIST
);
274 // Must not allow deleting of admins or self!!!
275 if (is_siteadmin($user)) {
276 throw new moodle_exception('useradminodelete', 'error');
278 if ($USER->id
== $user->id
) {
279 throw new moodle_exception('usernotdeletederror', 'error');
281 user_delete_user($user);
284 $transaction->allow_commit();
290 * Returns description of method result value
295 public static function delete_users_returns() {
301 * Returns description of method parameters
303 * @return external_function_parameters
306 public static function update_users_parameters() {
307 return new external_function_parameters(
309 'users' => new external_multiple_structure(
310 new external_single_structure(
313 new external_value(PARAM_INT
, 'ID of the user'),
315 new external_value(PARAM_USERNAME
, 'Username policy is defined in Moodle security config.',
316 VALUE_OPTIONAL
, '', NULL_NOT_ALLOWED
),
318 new external_value(PARAM_RAW
, 'Plain text password consisting of any characters', VALUE_OPTIONAL
,
319 '', NULL_NOT_ALLOWED
),
321 new external_value(PARAM_NOTAGS
, 'The first name(s) of the user', VALUE_OPTIONAL
, '',
324 new external_value(PARAM_NOTAGS
, 'The family name of the user', VALUE_OPTIONAL
),
326 new external_value(PARAM_EMAIL
, 'A valid and unique email address', VALUE_OPTIONAL
, '',
329 new external_value(PARAM_PLUGIN
, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL
, '',
332 new external_value(PARAM_RAW
, 'An arbitrary ID code number perhaps from the institution',
335 new external_value(PARAM_SAFEDIR
, 'Language code such as "en", must exist on server',
336 VALUE_OPTIONAL
, '', NULL_NOT_ALLOWED
),
338 new external_value(PARAM_PLUGIN
, 'Calendar type such as "gregorian", must exist on server',
339 VALUE_OPTIONAL
, '', NULL_NOT_ALLOWED
),
341 new external_value(PARAM_PLUGIN
, 'Theme name such as "standard", must exist on server',
344 new external_value(PARAM_TIMEZONE
, 'Timezone code such as Australia/Perth, or 99 for default',
347 new external_value(PARAM_INT
, 'Mail format code is 0 for plain text, 1 for HTML etc',
350 new external_value(PARAM_TEXT
, 'User profile description, no HTML', VALUE_OPTIONAL
),
352 new external_value(PARAM_NOTAGS
, 'Home city of the user', VALUE_OPTIONAL
),
354 new external_value(PARAM_ALPHA
, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL
),
355 'firstnamephonetic' =>
356 new external_value(PARAM_NOTAGS
, 'The first name(s) phonetically of the user', VALUE_OPTIONAL
),
357 'lastnamephonetic' =>
358 new external_value(PARAM_NOTAGS
, 'The family name phonetically of the user', VALUE_OPTIONAL
),
360 new external_value(PARAM_NOTAGS
, 'The middle name of the user', VALUE_OPTIONAL
),
362 new external_value(PARAM_NOTAGS
, 'The alternate name of the user', VALUE_OPTIONAL
),
363 'customfields' => new external_multiple_structure(
364 new external_single_structure(
366 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the custom field'),
367 'value' => new external_value(PARAM_RAW
, 'The value of the custom field')
369 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL
),
370 'preferences' => new external_multiple_structure(
371 new external_single_structure(
373 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the preference'),
374 'value' => new external_value(PARAM_RAW
, 'The value of the preference')
376 ), 'User preferences', VALUE_OPTIONAL
),
387 * @param array $users
391 public static function update_users($users) {
393 require_once($CFG->dirroot
."/user/lib.php");
394 require_once($CFG->dirroot
."/user/profile/lib.php"); // Required for customfields related function.
396 // Ensure the current user is allowed to run this function.
397 $context = context_system
::instance();
398 require_capability('moodle/user:update', $context);
399 self
::validate_context($context);
401 $params = self
::validate_parameters(self
::update_users_parameters(), array('users' => $users));
403 $transaction = $DB->start_delegated_transaction();
405 foreach ($params['users'] as $user) {
406 user_update_user($user, true, false);
407 // Update user custom fields.
408 if (!empty($user['customfields'])) {
410 foreach ($user['customfields'] as $customfield) {
411 // Profile_save_data() saves profile file it's expecting a user with the correct id,
412 // and custom field to be named profile_field_"shortname".
413 $user["profile_field_".$customfield['type']] = $customfield['value'];
415 profile_save_data((object) $user);
419 \core\event\user_updated
::create_from_userid($user['id'])->trigger();
422 if (!empty($user['preferences'])) {
423 foreach ($user['preferences'] as $preference) {
424 set_user_preference($preference['type'], $preference['value'], $user['id']);
429 $transaction->allow_commit();
435 * Returns description of method result value
440 public static function update_users_returns() {
445 * Returns description of method parameters
447 * @return external_function_parameters
450 public static function get_users_by_field_parameters() {
451 return new external_function_parameters(
453 'field' => new external_value(PARAM_ALPHA
, 'the search field can be
454 \'id\' or \'idnumber\' or \'username\' or \'email\''),
455 'values' => new external_multiple_structure(
456 new external_value(PARAM_RAW
, 'the value to match'))
462 * Get user information for a unique field.
464 * @throws coding_exception
465 * @throws invalid_parameter_exception
466 * @param string $field
467 * @param array $values
468 * @return array An array of arrays containg user profiles.
471 public static function get_users_by_field($field, $values) {
472 global $CFG, $USER, $DB;
473 require_once($CFG->dirroot
. "/user/lib.php");
475 $params = self
::validate_parameters(self
::get_users_by_field_parameters(),
476 array('field' => $field, 'values' => $values));
478 // This array will keep all the users that are allowed to be searched,
479 // according to the current user's privileges.
480 $cleanedvalues = array();
484 $paramtype = PARAM_INT
;
487 $paramtype = PARAM_RAW
;
490 $paramtype = PARAM_RAW
;
493 $paramtype = PARAM_EMAIL
;
496 throw new coding_exception('invalid field parameter',
497 'The search field \'' . $field . '\' is not supported, look at the web service documentation');
501 foreach ($values as $value) {
502 $cleanedvalue = clean_param($value, $paramtype);
503 if ( $value != $cleanedvalue) {
504 throw new invalid_parameter_exception('The field \'' . $field .
505 '\' value is invalid: ' . $value . '(cleaned value: '.$cleanedvalue.')');
507 $cleanedvalues[] = $cleanedvalue;
510 // Retrieve the users.
511 $users = $DB->get_records_list('user', $field, $cleanedvalues, 'id');
513 // Finally retrieve each users information.
514 $returnedusers = array();
515 foreach ($users as $user) {
516 $userdetails = user_get_user_details_courses($user);
518 // Return the user only if the searched field is returned.
519 // Otherwise it means that the $USER was not allowed to search the returned user.
520 if (!empty($userdetails) and !empty($userdetails[$field])) {
521 $returnedusers[] = $userdetails;
525 return $returnedusers;
529 * Returns description of method result value
531 * @return external_multiple_structure
534 public static function get_users_by_field_returns() {
535 return new external_multiple_structure(self
::user_description());
540 * Returns description of get_users() parameters.
542 * @return external_function_parameters
545 public static function get_users_parameters() {
546 return new external_function_parameters(
548 'criteria' => new external_multiple_structure(
549 new external_single_structure(
551 'key' => new external_value(PARAM_ALPHA
, 'the user column to search, expected keys (value format) are:
552 "id" (int) matching user id,
553 "lastname" (string) user last name (Note: you can use % for searching but it may be considerably slower!),
554 "firstname" (string) user first name (Note: you can use % for searching but it may be considerably slower!),
555 "idnumber" (string) matching user idnumber,
556 "username" (string) matching user username,
557 "email" (string) user email (Note: you can use % for searching but it may be considerably slower!),
558 "auth" (string) matching user auth plugin'),
559 'value' => new external_value(PARAM_RAW
, 'the value to search')
561 ), 'the key/value pairs to be considered in user search. Values can not be empty.
562 Specify different keys only once (fullname => \'user1\', auth => \'manual\', ...) -
563 key occurences are forbidden.
564 The search is executed with AND operator on the criterias. Invalid criterias (keys) are ignored,
565 the search is still executed on the valid criterias.
566 You can search without criteria, but the function is not designed for it.
567 It could very slow or timeout. The function is designed to search some specific users.'
574 * Retrieve matching user.
576 * @throws moodle_exception
577 * @param array $criteria the allowed array keys are id/lastname/firstname/idnumber/username/email/auth.
578 * @return array An array of arrays containing user profiles.
581 public static function get_users($criteria = array()) {
582 global $CFG, $USER, $DB;
584 require_once($CFG->dirroot
. "/user/lib.php");
586 $params = self
::validate_parameters(self
::get_users_parameters(),
587 array('criteria' => $criteria));
589 // Validate the criteria and retrieve the users.
592 $sqlparams = array();
595 // Do not retrieve deleted users.
596 $sql = ' deleted = 0';
598 foreach ($params['criteria'] as $criteriaindex => $criteria) {
600 // Check that the criteria has never been used.
601 if (array_key_exists($criteria['key'], $usedkeys)) {
602 throw new moodle_exception('keyalreadyset', '', '', null, 'The key ' . $criteria['key'] . ' can only be sent once');
604 $usedkeys[$criteria['key']] = true;
607 $invalidcriteria = false;
608 // Clean the parameters.
609 $paramtype = PARAM_RAW
;
610 switch ($criteria['key']) {
612 $paramtype = PARAM_INT
;
615 $paramtype = PARAM_RAW
;
618 $paramtype = PARAM_RAW
;
621 // We use PARAM_RAW to allow searches with %.
622 $paramtype = PARAM_RAW
;
625 $paramtype = PARAM_AUTH
;
629 $paramtype = PARAM_TEXT
;
632 // Send back a warning that this search key is not supported in this version.
633 // This warning will make the function extandable without breaking clients.
635 'item' => $criteria['key'],
636 'warningcode' => 'invalidfieldparameter',
638 'The search key \'' . $criteria['key'] . '\' is not supported, look at the web service documentation'
640 // Do not add this invalid criteria to the created SQL request.
641 $invalidcriteria = true;
642 unset($params['criteria'][$criteriaindex]);
646 if (!$invalidcriteria) {
647 $cleanedvalue = clean_param($criteria['value'], $paramtype);
652 switch ($criteria['key']) {
657 $sql .= $criteria['key'] . ' = :' . $criteria['key'];
658 $sqlparams[$criteria['key']] = $cleanedvalue;
663 $sql .= $DB->sql_like($criteria['key'], ':' . $criteria['key'], false);
664 $sqlparams[$criteria['key']] = $cleanedvalue;
672 $users = $DB->get_records_select('user', $sql, $sqlparams, 'id ASC');
674 // Finally retrieve each users information.
675 $returnedusers = array();
676 foreach ($users as $user) {
677 $userdetails = user_get_user_details_courses($user);
679 // Return the user only if all the searched fields are returned.
680 // Otherwise it means that the $USER was not allowed to search the returned user.
681 if (!empty($userdetails)) {
684 foreach ($params['criteria'] as $criteria) {
685 if (empty($userdetails[$criteria['key']])) {
691 $returnedusers[] = $userdetails;
696 return array('users' => $returnedusers, 'warnings' => $warnings);
700 * Returns description of get_users result value.
702 * @return external_description
705 public static function get_users_returns() {
706 return new external_single_structure(
707 array('users' => new external_multiple_structure(
708 self
::user_description()
710 'warnings' => new external_warnings('always set to \'key\'', 'faulty key name')
716 * Returns description of method parameters
718 * @return external_function_parameters
720 * @deprecated Moodle 2.5 MDL-38030 - Please do not call this function any more.
721 * @see core_user_external::get_users_by_field_parameters()
723 public static function get_users_by_id_parameters() {
724 return new external_function_parameters(
726 'userids' => new external_multiple_structure(new external_value(PARAM_INT
, 'user ID')),
732 * Get user information
733 * - This function is matching the permissions of /user/profil.php
734 * - It is also matching some permissions from /user/editadvanced.php for the following fields:
735 * auth, confirmed, idnumber, lang, theme, timezone, mailformat
737 * @param array $userids array of user ids
738 * @return array An array of arrays describing users
740 * @deprecated Moodle 2.5 MDL-38030 - Please do not call this function any more.
741 * @see core_user_external::get_users_by_field()
743 public static function get_users_by_id($userids) {
744 global $CFG, $USER, $DB;
745 require_once($CFG->dirroot
. "/user/lib.php");
747 $params = self
::validate_parameters(self
::get_users_by_id_parameters(),
748 array('userids' => $userids));
750 list($sqluserids, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED
);
751 $uselect = ', ' . context_helper
::get_preload_record_columns_sql('ctx');
752 $ujoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
753 $params['contextlevel'] = CONTEXT_USER
;
754 $usersql = "SELECT u.* $uselect
756 WHERE u.id $sqluserids";
757 $users = $DB->get_recordset_sql($usersql, $params);
760 $hasuserupdatecap = has_capability('moodle/user:update', context_system
::instance());
761 foreach ($users as $user) {
762 if (!empty($user->deleted
)) {
765 context_helper
::preload_from_record($user);
766 $usercontext = context_user
::instance($user->id
, IGNORE_MISSING
);
767 self
::validate_context($usercontext);
768 $currentuser = ($user->id
== $USER->id
);
770 if ($userarray = user_get_user_details($user)) {
771 // Fields matching permissions from /user/editadvanced.php.
772 if ($currentuser or $hasuserupdatecap) {
773 $userarray['auth'] = $user->auth
;
774 $userarray['confirmed'] = $user->confirmed
;
775 $userarray['idnumber'] = $user->idnumber
;
776 $userarray['lang'] = $user->lang
;
777 $userarray['theme'] = $user->theme
;
778 $userarray['timezone'] = $user->timezone
;
779 $userarray['mailformat'] = $user->mailformat
;
781 $result[] = $userarray;
790 * Returns description of method result value
792 * @return external_description
794 * @deprecated Moodle 2.5 MDL-38030 - Please do not call this function any more.
795 * @see core_user_external::get_users_by_field_returns()
797 public static function get_users_by_id_returns() {
798 $additionalfields = array (
799 'enrolledcourses' => new external_multiple_structure(
800 new external_single_structure(
802 'id' => new external_value(PARAM_INT
, 'Id of the course'),
803 'fullname' => new external_value(PARAM_RAW
, 'Fullname of the course'),
804 'shortname' => new external_value(PARAM_RAW
, 'Shortname of the course')
806 ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL
));
807 return new external_multiple_structure(self
::user_description($additionalfields));
811 * Marking the method as deprecated.
815 public static function get_users_by_id_is_deprecated() {
820 * Returns description of method parameters
822 * @return external_function_parameters
825 public static function get_course_user_profiles_parameters() {
826 return new external_function_parameters(
828 'userlist' => new external_multiple_structure(
829 new external_single_structure(
831 'userid' => new external_value(PARAM_INT
, 'userid'),
832 'courseid' => new external_value(PARAM_INT
, 'courseid'),
841 * Get course participant's details
843 * @param array $userlist array of user ids and according course ids
844 * @return array An array of arrays describing course participants
847 public static function get_course_user_profiles($userlist) {
848 global $CFG, $USER, $DB;
849 require_once($CFG->dirroot
. "/user/lib.php");
850 $params = self
::validate_parameters(self
::get_course_user_profiles_parameters(), array('userlist' => $userlist));
853 $courseids = array();
854 foreach ($params['userlist'] as $value) {
855 $userids[] = $value['userid'];
856 $courseids[$value['userid']] = $value['courseid'];
859 // Cache all courses.
861 list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids), SQL_PARAMS_NAMED
);
862 $cselect = ', ' . context_helper
::get_preload_record_columns_sql('ctx');
863 $cjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
864 $params['contextlevel'] = CONTEXT_COURSE
;
865 $coursesql = "SELECT c.* $cselect
866 FROM {course} c $cjoin
867 WHERE c.id $sqlcourseids";
868 $rs = $DB->get_recordset_sql($coursesql, $params);
869 foreach ($rs as $course) {
870 // Adding course contexts to cache.
871 context_helper
::preload_from_record($course);
873 $courses[$course->id
] = $course;
877 list($sqluserids, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED
);
878 $uselect = ', ' . context_helper
::get_preload_record_columns_sql('ctx');
879 $ujoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
880 $params['contextlevel'] = CONTEXT_USER
;
881 $usersql = "SELECT u.* $uselect
883 WHERE u.id $sqluserids";
884 $users = $DB->get_recordset_sql($usersql, $params);
886 foreach ($users as $user) {
887 if (!empty($user->deleted
)) {
890 context_helper
::preload_from_record($user);
891 $course = $courses[$courseids[$user->id
]];
892 $context = context_course
::instance($courseids[$user->id
], IGNORE_MISSING
);
893 self
::validate_context($context);
894 if ($userarray = user_get_user_details($user, $course)) {
895 $result[] = $userarray;
905 * Returns description of method result value
907 * @return external_description
910 public static function get_course_user_profiles_returns() {
911 $additionalfields = array(
912 'groups' => new external_multiple_structure(
913 new external_single_structure(
915 'id' => new external_value(PARAM_INT
, 'group id'),
916 'name' => new external_value(PARAM_RAW
, 'group name'),
917 'description' => new external_value(PARAM_RAW
, 'group description'),
918 'descriptionformat' => new external_format_value('description'),
920 ), 'user groups', VALUE_OPTIONAL
),
921 'roles' => new external_multiple_structure(
922 new external_single_structure(
924 'roleid' => new external_value(PARAM_INT
, 'role id'),
925 'name' => new external_value(PARAM_RAW
, 'role name'),
926 'shortname' => new external_value(PARAM_ALPHANUMEXT
, 'role shortname'),
927 'sortorder' => new external_value(PARAM_INT
, 'role sortorder')
929 ), 'user roles', VALUE_OPTIONAL
),
930 'enrolledcourses' => new external_multiple_structure(
931 new external_single_structure(
933 'id' => new external_value(PARAM_INT
, 'Id of the course'),
934 'fullname' => new external_value(PARAM_RAW
, 'Fullname of the course'),
935 'shortname' => new external_value(PARAM_RAW
, 'Shortname of the course')
937 ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL
)
940 return new external_multiple_structure(self
::user_description($additionalfields));
944 * Create user return value description.
946 * @param array $additionalfields some additional field
947 * @return single_structure_description
949 public static function user_description($additionalfields = array()) {
951 'id' => new external_value(PARAM_INT
, 'ID of the user'),
952 'username' => new external_value(PARAM_RAW
, 'The username', VALUE_OPTIONAL
),
953 'firstname' => new external_value(PARAM_NOTAGS
, 'The first name(s) of the user', VALUE_OPTIONAL
),
954 'lastname' => new external_value(PARAM_NOTAGS
, 'The family name of the user', VALUE_OPTIONAL
),
955 'fullname' => new external_value(PARAM_NOTAGS
, 'The fullname of the user'),
956 'email' => new external_value(PARAM_TEXT
, 'An email address - allow email as root@localhost', VALUE_OPTIONAL
),
957 'address' => new external_value(PARAM_TEXT
, 'Postal address', VALUE_OPTIONAL
),
958 'phone1' => new external_value(PARAM_NOTAGS
, 'Phone 1', VALUE_OPTIONAL
),
959 'phone2' => new external_value(PARAM_NOTAGS
, 'Phone 2', VALUE_OPTIONAL
),
960 'icq' => new external_value(PARAM_NOTAGS
, 'icq number', VALUE_OPTIONAL
),
961 'skype' => new external_value(PARAM_NOTAGS
, 'skype id', VALUE_OPTIONAL
),
962 'yahoo' => new external_value(PARAM_NOTAGS
, 'yahoo id', VALUE_OPTIONAL
),
963 'aim' => new external_value(PARAM_NOTAGS
, 'aim id', VALUE_OPTIONAL
),
964 'msn' => new external_value(PARAM_NOTAGS
, 'msn number', VALUE_OPTIONAL
),
965 'department' => new external_value(PARAM_TEXT
, 'department', VALUE_OPTIONAL
),
966 'institution' => new external_value(PARAM_TEXT
, 'institution', VALUE_OPTIONAL
),
967 'idnumber' => new external_value(PARAM_RAW
, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL
),
968 'interests' => new external_value(PARAM_TEXT
, 'user interests (separated by commas)', VALUE_OPTIONAL
),
969 'firstaccess' => new external_value(PARAM_INT
, 'first access to the site (0 if never)', VALUE_OPTIONAL
),
970 'lastaccess' => new external_value(PARAM_INT
, 'last access to the site (0 if never)', VALUE_OPTIONAL
),
971 'auth' => new external_value(PARAM_PLUGIN
, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL
),
972 'confirmed' => new external_value(PARAM_INT
, 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL
),
973 'lang' => new external_value(PARAM_SAFEDIR
, 'Language code such as "en", must exist on server', VALUE_OPTIONAL
),
974 'calendartype' => new external_value(PARAM_PLUGIN
, 'Calendar type such as "gregorian", must exist on server', VALUE_OPTIONAL
),
975 'theme' => new external_value(PARAM_PLUGIN
, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL
),
976 'timezone' => new external_value(PARAM_TIMEZONE
, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL
),
977 'mailformat' => new external_value(PARAM_INT
, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL
),
978 'description' => new external_value(PARAM_RAW
, 'User profile description', VALUE_OPTIONAL
),
979 'descriptionformat' => new external_format_value('description', VALUE_OPTIONAL
),
980 'city' => new external_value(PARAM_NOTAGS
, 'Home city of the user', VALUE_OPTIONAL
),
981 'url' => new external_value(PARAM_URL
, 'URL of the user', VALUE_OPTIONAL
),
982 'country' => new external_value(PARAM_ALPHA
, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL
),
983 'profileimageurlsmall' => new external_value(PARAM_URL
, 'User image profile URL - small version'),
984 'profileimageurl' => new external_value(PARAM_URL
, 'User image profile URL - big version'),
985 'customfields' => new external_multiple_structure(
986 new external_single_structure(
988 'type' => new external_value(PARAM_ALPHANUMEXT
, 'The type of the custom field - text field, checkbox...'),
989 'value' => new external_value(PARAM_RAW
, 'The value of the custom field'),
990 'name' => new external_value(PARAM_RAW
, 'The name of the custom field'),
991 'shortname' => new external_value(PARAM_RAW
, 'The shortname of the custom field - to be able to build the field class in the code'),
993 ), 'User custom fields (also known as user profile fields)', VALUE_OPTIONAL
),
994 'preferences' => new external_multiple_structure(
995 new external_single_structure(
997 'name' => new external_value(PARAM_ALPHANUMEXT
, 'The name of the preferences'),
998 'value' => new external_value(PARAM_RAW
, 'The value of the custom field'),
1000 ), 'Users preferences', VALUE_OPTIONAL
)
1002 if (!empty($additionalfields)) {
1003 $userfields = array_merge($userfields, $additionalfields);
1005 return new external_single_structure($userfields);
1009 * Returns description of method parameters
1011 * @return external_function_parameters
1014 public static function add_user_private_files_parameters() {
1015 return new external_function_parameters(
1017 'draftid' => new external_value(PARAM_INT
, 'draft area id')
1023 * Copy files from a draft area to users private files area.
1025 * @throws invalid_parameter_exception
1026 * @param int $draftid Id of a draft area containing files.
1027 * @return array An array of warnings
1030 public static function add_user_private_files($draftid) {
1031 global $CFG, $USER, $DB;
1033 require_once($CFG->dirroot
. "/user/lib.php");
1034 $params = self
::validate_parameters(self
::add_user_private_files_parameters(), array('draftid' => $draftid));
1036 if (isguestuser()) {
1037 throw new invalid_parameter_exception('Guest users cannot upload files');
1040 $context = context_user
::instance($USER->id
);
1041 require_capability('moodle/user:manageownfiles', $context);
1043 $maxbytes = $CFG->userquota
;
1044 $maxareabytes = $CFG->userquota
;
1045 if (has_capability('moodle/user:ignoreuserquota', $context)) {
1046 $maxbytes = USER_CAN_IGNORE_FILE_SIZE_LIMITS
;
1047 $maxareabytes = FILE_AREA_MAX_BYTES_UNLIMITED
;
1050 $options = array('subdirs' => 1,
1051 'maxbytes' => $maxbytes,
1053 'accepted_types' => '*',
1054 'areamaxbytes' => $maxareabytes);
1056 file_save_draft_area_files($draftid, $context->id
, 'user', 'private', 0, $options);
1062 * Returns description of method result value
1064 * @return external_description
1067 public static function add_user_private_files_returns() {
1072 * Returns description of method parameters.
1074 * @return external_function_parameters
1077 public static function add_user_device_parameters() {
1078 return new external_function_parameters(
1080 'appid' => new external_value(PARAM_NOTAGS
, 'the app id, usually something like com.moodle.moodlemobile'),
1081 'name' => new external_value(PARAM_NOTAGS
, 'the device name, \'occam\' or \'iPhone\' etc.'),
1082 'model' => new external_value(PARAM_NOTAGS
, 'the device model \'Nexus4\' or \'iPad1,1\' etc.'),
1083 'platform' => new external_value(PARAM_NOTAGS
, 'the device platform \'iOS\' or \'Android\' etc.'),
1084 'version' => new external_value(PARAM_NOTAGS
, 'the device version \'6.1.2\' or \'4.2.2\' etc.'),
1085 'pushid' => new external_value(PARAM_RAW
, 'the device PUSH token/key/identifier/registration id'),
1086 'uuid' => new external_value(PARAM_RAW
, 'the device UUID')
1092 * Add a user device in Moodle database (for PUSH notifications usually).
1094 * @throws moodle_exception
1095 * @param string $appid The app id, usually something like com.moodle.moodlemobile.
1096 * @param string $name The device name, occam or iPhone etc.
1097 * @param string $model The device model Nexus4 or iPad1.1 etc.
1098 * @param string $platform The device platform iOs or Android etc.
1099 * @param string $version The device version 6.1.2 or 4.2.2 etc.
1100 * @param string $pushid The device PUSH token/key/identifier/registration id.
1101 * @param string $uuid The device UUID.
1102 * @return array List of possible warnings.
1105 public static function add_user_device($appid, $name, $model, $platform, $version, $pushid, $uuid) {
1106 global $CFG, $USER, $DB;
1107 require_once($CFG->dirroot
. "/user/lib.php");
1109 $params = self
::validate_parameters(self
::add_user_device_parameters(),
1110 array('appid' => $appid,
1113 'platform' => $platform,
1114 'version' => $version,
1115 'pushid' => $pushid,
1119 $warnings = array();
1121 // Prevent duplicate keys for users.
1122 if ($DB->get_record('user_devices', array('pushid' => $params['pushid'], 'userid' => $USER->id
))) {
1123 $warnings['warning'][] = array(
1124 'item' => $params['pushid'],
1125 'warningcode' => 'existingkeyforthisuser',
1126 'message' => 'This key is already stored for this user'
1131 // Notice that we can have multiple devices because previously it was allowed to have repeated ones.
1132 // Since we don't have a clear way to decide which one is the more appropiate, we update all.
1133 if ($userdevices = $DB->get_records('user_devices', array('uuid' => $params['uuid'],
1134 'appid' => $params['appid'], 'userid' => $USER->id
))) {
1136 foreach ($userdevices as $userdevice) {
1137 $userdevice->version
= $params['version']; // Maybe the user upgraded the device.
1138 $userdevice->pushid
= $params['pushid'];
1139 $userdevice->timemodified
= time();
1140 $DB->update_record('user_devices', $userdevice);
1144 $userdevice = new stdclass
;
1145 $userdevice->userid
= $USER->id
;
1146 $userdevice->appid
= $params['appid'];
1147 $userdevice->name
= $params['name'];
1148 $userdevice->model
= $params['model'];
1149 $userdevice->platform
= $params['platform'];
1150 $userdevice->version
= $params['version'];
1151 $userdevice->pushid
= $params['pushid'];
1152 $userdevice->uuid
= $params['uuid'];
1153 $userdevice->timecreated
= time();
1154 $userdevice->timemodified
= $userdevice->timecreated
;
1156 if (!$DB->insert_record('user_devices', $userdevice)) {
1157 throw new moodle_exception("There was a problem saving in the database the device with key: " . $params['pushid']);
1165 * Returns description of method result value.
1167 * @return external_multiple_structure
1170 public static function add_user_device_returns() {
1171 return new external_multiple_structure(
1172 new external_warnings()
1177 * Returns description of method parameters.
1179 * @return external_function_parameters
1182 public static function remove_user_device_parameters() {
1183 return new external_function_parameters(
1185 'uuid' => new external_value(PARAM_RAW
, 'the device UUID'),
1186 'appid' => new external_value(PARAM_NOTAGS
,
1187 'the app id, if empty devices matching the UUID for the user will be removed',
1194 * Remove a user device from the Moodle database (for PUSH notifications usually).
1196 * @param string $uuid The device UUID.
1197 * @param string $appid The app id, opitonal parameter. If empty all the devices fmatching the UUID or the user will be removed.
1198 * @return array List of possible warnings and removal status.
1201 public static function remove_user_device($uuid, $appid = "") {
1203 require_once($CFG->dirroot
. "/user/lib.php");
1205 $params = self
::validate_parameters(self
::remove_user_device_parameters(), array('uuid' => $uuid, 'appid' => $appid));
1207 $context = context_system
::instance();
1208 self
::validate_context($context);
1210 // Warnings array, it can be empty at the end but is mandatory.
1211 $warnings = array();
1213 $removed = user_remove_user_device($params['uuid'], $params['appid']);
1216 $warnings[] = array(
1217 'item' => $params['uuid'],
1218 'warningcode' => 'devicedoesnotexist',
1219 'message' => 'The device doesn\'t exists in the database'
1224 'removed' => $removed,
1225 'warnings' => $warnings
1232 * Returns description of method result value.
1234 * @return external_multiple_structure
1237 public static function remove_user_device_returns() {
1238 return new external_single_structure(
1240 'removed' => new external_value(PARAM_BOOL
, 'True if removed, false if not removed because it doesn\'t exists'),
1241 'warnings' => new external_warnings(),
1247 * Returns description of method parameters
1249 * @return external_function_parameters
1252 public static function view_user_list_parameters() {
1253 return new external_function_parameters(
1255 'courseid' => new external_value(PARAM_INT
, 'id of the course, 0 for site')
1261 * Trigger the user_list_viewed event.
1263 * @param int $courseid id of course
1264 * @return array of warnings and status result
1266 * @throws moodle_exception
1268 public static function view_user_list($courseid) {
1270 require_once($CFG->dirroot
. "/user/lib.php");
1272 $params = self
::validate_parameters(self
::view_user_list_parameters(),
1274 'courseid' => $courseid
1277 $warnings = array();
1279 if (empty($params['courseid'])) {
1280 $params['courseid'] = SITEID
;
1283 $course = get_course($params['courseid']);
1285 if ($course->id
== SITEID
) {
1286 $context = context_system
::instance();
1288 $context = context_course
::instance($course->id
);
1290 self
::validate_context($context);
1292 if ($course->id
== SITEID
) {
1293 require_capability('moodle/site:viewparticipants', $context);
1295 require_capability('moodle/course:viewparticipants', $context);
1298 user_list_view($course, $context);
1301 $result['status'] = true;
1302 $result['warnings'] = $warnings;
1307 * Returns description of method result value
1309 * @return external_description
1312 public static function view_user_list_returns() {
1313 return new external_single_structure(
1315 'status' => new external_value(PARAM_BOOL
, 'status: true if success'),
1316 'warnings' => new external_warnings()
1322 * Returns description of method parameters
1324 * @return external_function_parameters
1327 public static function view_user_profile_parameters() {
1328 return new external_function_parameters(
1330 'userid' => new external_value(PARAM_INT
, 'id of the user, 0 for current user', VALUE_REQUIRED
),
1331 'courseid' => new external_value(PARAM_INT
, 'id of the course, default site course', VALUE_DEFAULT
, 0)
1337 * Trigger the user profile viewed event.
1339 * @param int $userid id of user
1340 * @param int $courseid id of course
1341 * @return array of warnings and status result
1343 * @throws moodle_exception
1345 public static function view_user_profile($userid, $courseid = 0) {
1347 require_once($CFG->dirroot
. "/user/profile/lib.php");
1349 $params = self
::validate_parameters(self
::view_user_profile_parameters(),
1351 'userid' => $userid,
1352 'courseid' => $courseid
1355 $warnings = array();
1357 if (empty($params['userid'])) {
1358 $params['userid'] = $USER->id
;
1361 if (empty($params['courseid'])) {
1362 $params['courseid'] = SITEID
;
1365 $course = get_course($params['courseid']);
1366 $user = core_user
::get_user($params['userid'], '*', MUST_EXIST
);
1368 if ($user->deleted
) {
1369 throw new moodle_exception('userdeleted');
1371 if (isguestuser($user)) {
1372 // Can not view profile of guest - thre is nothing to see there.
1373 throw new moodle_exception('invaliduserid');
1376 if ($course->id
== SITEID
) {
1377 $coursecontext = context_system
::instance();;
1379 $coursecontext = context_course
::instance($course->id
);
1381 self
::validate_context($coursecontext);
1383 $currentuser = $USER->id
== $user->id
;
1384 $usercontext = context_user
::instance($user->id
);
1386 if (!$currentuser and
1387 !has_capability('moodle/user:viewdetails', $coursecontext) and
1388 !has_capability('moodle/user:viewdetails', $usercontext)) {
1389 throw new moodle_exception('cannotviewprofile');
1392 // Case like user/profile.php.
1393 if ($course->id
== SITEID
) {
1394 profile_view($user, $usercontext);
1396 // Case like user/view.php.
1397 if (!$currentuser and !is_enrolled($coursecontext, $user->id
)) {
1398 throw new moodle_exception('notenrolledprofile');
1401 profile_view($user, $coursecontext, $course);
1405 $result['status'] = true;
1406 $result['warnings'] = $warnings;
1411 * Returns description of method result value
1413 * @return external_description
1416 public static function view_user_profile_returns() {
1417 return new external_single_structure(
1419 'status' => new external_value(PARAM_BOOL
, 'status: true if success'),
1420 'warnings' => new external_warnings()
1428 * Deprecated user external functions
1430 * @package core_user
1431 * @copyright 2009 Petr Skodak
1432 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1434 * @deprecated Moodle 2.2 MDL-29106 - Please do not use this class any more.
1435 * @see core_user_external
1437 class moodle_user_external
extends external_api
{
1440 * Returns description of method parameters
1442 * @return external_function_parameters
1444 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1445 * @see core_user_external::create_users_parameters()
1447 public static function create_users_parameters() {
1448 return core_user_external
::create_users_parameters();
1452 * Create one or more users
1454 * @param array $users An array of users to create.
1455 * @return array An array of arrays
1457 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1458 * @see core_user_external::create_users()
1460 public static function create_users($users) {
1461 return core_user_external
::create_users($users);
1465 * Returns description of method result value
1467 * @return external_description
1469 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1470 * @see core_user_external::create_users_returns()
1472 public static function create_users_returns() {
1473 return core_user_external
::create_users_returns();
1477 * Marking the method as deprecated.
1481 public static function create_users_is_deprecated() {
1486 * Returns description of method parameters
1488 * @return external_function_parameters
1490 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1491 * @see core_user_external::delete_users_parameters()
1493 public static function delete_users_parameters() {
1494 return core_user_external
::delete_users_parameters();
1500 * @param array $userids
1503 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1504 * @see core_user_external::delete_users()
1506 public static function delete_users($userids) {
1507 return core_user_external
::delete_users($userids);
1511 * Returns description of method result value
1515 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1516 * @see core_user_external::delete_users_returns()
1518 public static function delete_users_returns() {
1519 return core_user_external
::delete_users_returns();
1523 * Marking the method as deprecated.
1527 public static function delete_users_is_deprecated() {
1532 * Returns description of method parameters
1534 * @return external_function_parameters
1536 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1537 * @see core_user_external::update_users_parameters()
1539 public static function update_users_parameters() {
1540 return core_user_external
::update_users_parameters();
1546 * @param array $users
1549 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1550 * @see core_user_external::update_users()
1552 public static function update_users($users) {
1553 return core_user_external
::update_users($users);
1557 * Returns description of method result value
1561 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1562 * @see core_user_external::update_users_returns()
1564 public static function update_users_returns() {
1565 return core_user_external
::update_users_returns();
1569 * Marking the method as deprecated.
1573 public static function update_users_is_deprecated() {
1578 * Returns description of method parameters
1580 * @return external_function_parameters
1582 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1583 * @see core_user_external::get_users_by_id_parameters()
1585 public static function get_users_by_id_parameters() {
1586 return core_user_external
::get_users_by_id_parameters();
1590 * Get user information
1591 * - This function is matching the permissions of /user/profil.php
1592 * - It is also matching some permissions from /user/editadvanced.php for the following fields:
1593 * auth, confirmed, idnumber, lang, theme, timezone, mailformat
1595 * @param array $userids array of user ids
1596 * @return array An array of arrays describing users
1598 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1599 * @see core_user_external::get_users_by_id()
1601 public static function get_users_by_id($userids) {
1602 return core_user_external
::get_users_by_id($userids);
1606 * Returns description of method result value
1608 * @return external_description
1610 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1611 * @see core_user_external::get_users_by_id_returns()
1613 public static function get_users_by_id_returns() {
1614 return core_user_external
::get_users_by_id_returns();
1618 * Marking the method as deprecated.
1622 public static function get_users_by_id_is_deprecated() {
1627 * Returns description of method parameters
1629 * @return external_function_parameters
1631 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1632 * @see core_user_external::get_course_user_profiles_parameters()
1634 public static function get_course_participants_by_id_parameters() {
1635 return core_user_external
::get_course_user_profiles_parameters();
1639 * Get course participant's details
1641 * @param array $userlist array of user ids and according course ids
1642 * @return array An array of arrays describing course participants
1644 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1645 * @see core_user_external::get_course_user_profiles()
1647 public static function get_course_participants_by_id($userlist) {
1648 return core_user_external
::get_course_user_profiles($userlist);
1652 * Returns description of method result value
1654 * @return external_description
1656 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1657 * @see core_user_external::get_course_user_profiles_returns()
1659 public static function get_course_participants_by_id_returns() {
1660 return core_user_external
::get_course_user_profiles_returns();
1664 * Marking the method as deprecated.
1668 public static function get_course_participants_by_id_is_deprecated() {
1673 * Returns description of method parameters
1675 * @return external_function_parameters
1677 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1678 * @see core_enrol_external::get_enrolled_users_parameters()
1680 public static function get_users_by_courseid_parameters() {
1682 require_once($CFG->dirroot
. '/enrol/externallib.php');
1683 return core_enrol_external
::get_enrolled_users_parameters();
1687 * Get course participants details
1689 * @param int $courseid course id
1690 * @param array $options options {
1691 * 'name' => option name
1692 * 'value' => option value
1694 * @return array An array of users
1696 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1697 * @see core_enrol_external::get_enrolled_users()
1699 public static function get_users_by_courseid($courseid, $options = array()) {
1701 require_once($CFG->dirroot
. '/enrol/externallib.php');
1702 return core_enrol_external
::get_enrolled_users($courseid, $options);
1705 * Returns description of method result value
1707 * @return external_description
1709 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1710 * @see core_enrol_external::get_enrolled_users_returns()
1712 public static function get_users_by_courseid_returns() {
1714 require_once($CFG->dirroot
. '/enrol/externallib.php');
1715 return core_enrol_external
::get_enrolled_users_returns();
1719 * Marking the method as deprecated.
1723 public static function get_users_by_courseid_is_deprecated() {