2009-09-15 22:52:49 +00:00
< ? php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
2012-01-18 10:52:25 +08:00
2009-09-15 22:52:49 +00:00
/**
* External user API
*
2012-01-18 10:52:25 +08:00
* @ package core_user
* @ category external
* @ copyright 2009 Petr Skodak
2009-09-15 22:52:49 +00:00
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
*/
require_once ( " $CFG->libdir /externallib.php " );
2011-10-18 12:57:33 +08:00
/**
2012-01-18 10:52:25 +08:00
* User external functions
*
* @ package core_user
* @ category external
* @ copyright 2011 Jerome Mouneyrac
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
* @ since Moodle 2.2
2011-10-18 12:57:33 +08:00
*/
class core_user_external extends external_api {
2009-09-15 22:52:49 +00:00
2009-11-05 22:54:48 +00:00
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2009-11-05 22:54:48 +00:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2009-11-05 22:54:48 +00:00
*/
2009-09-16 19:00:12 +00:00
public static function create_users_parameters () {
2009-11-06 12:28:50 +00:00
global $CFG ;
2009-10-09 09:57:07 +00:00
return new external_function_parameters (
array (
'users' => new external_multiple_structure (
new external_single_structure (
array (
2012-04-13 14:09:25 +08:00
'username' => new external_value ( PARAM_USERNAME , 'Username policy is defined in Moodle security config. Must be lowercase.' ),
2009-11-06 12:28:50 +00:00
'password' => new external_value ( PARAM_RAW , 'Plain text password consisting of any characters' ),
2009-11-05 22:54:48 +00:00
'firstname' => new external_value ( PARAM_NOTAGS , 'The first name(s) of the user' ),
'lastname' => new external_value ( PARAM_NOTAGS , 'The family name of the user' ),
'email' => new external_value ( PARAM_EMAIL , 'A valid and unique email address' ),
2011-09-24 15:07:27 +02:00
'auth' => new external_value ( PARAM_PLUGIN , 'Auth plugins include manual, ldap, imap, etc' , VALUE_DEFAULT , 'manual' , NULL_NOT_ALLOWED ),
2010-03-31 09:25:59 +00:00
'idnumber' => new external_value ( PARAM_RAW , 'An arbitrary ID code number perhaps from the institution' , VALUE_DEFAULT , '' ),
2010-04-10 07:24:56 +00:00
'lang' => new external_value ( PARAM_SAFEDIR , 'Language code such as "en", must exist on server' , VALUE_DEFAULT , $CFG -> lang , NULL_NOT_ALLOWED ),
2011-09-24 15:07:27 +02:00
'theme' => new external_value ( PARAM_PLUGIN , 'Theme name such as "standard", must exist on server' , VALUE_OPTIONAL ),
2011-06-09 11:29:43 +08:00
'timezone' => new external_value ( PARAM_TIMEZONE , 'Timezone code such as Australia/Perth, or 99 for default' , VALUE_OPTIONAL ),
2012-05-11 10:49:51 +08:00
'mailformat' => new external_value ( PARAM_INT , 'Mail format code is 0 for plain text, 1 for HTML etc' , VALUE_OPTIONAL ),
2010-07-08 08:40:21 +00:00
'description' => new external_value ( PARAM_TEXT , 'User profile description, no HTML' , VALUE_OPTIONAL ),
2010-02-11 04:02:04 +00:00
'city' => new external_value ( PARAM_NOTAGS , 'Home city of the user' , VALUE_OPTIONAL ),
'country' => new external_value ( PARAM_ALPHA , 'Home country code of the user, such as AU or CZ' , VALUE_OPTIONAL ),
2009-10-09 09:57:07 +00:00
'preferences' => new external_multiple_structure (
new external_single_structure (
array (
2009-11-05 22:54:48 +00:00
'type' => new external_value ( PARAM_ALPHANUMEXT , 'The name of the preference' ),
2009-10-09 09:57:07 +00:00
'value' => new external_value ( PARAM_RAW , 'The value of the preference' )
)
2010-02-11 04:02:04 +00:00
), 'User preferences' , VALUE_OPTIONAL ),
2009-10-09 09:57:07 +00:00
'customfields' => new external_multiple_structure (
new external_single_structure (
array (
2009-11-05 22:54:48 +00:00
'type' => new external_value ( PARAM_ALPHANUMEXT , 'The name of the custom field' ),
2009-10-09 09:57:07 +00:00
'value' => new external_value ( PARAM_RAW , 'The value of the custom field' )
)
2010-08-06 15:22:27 +00:00
), 'User custom fields (also known as user profil fields)' , VALUE_OPTIONAL )
2009-10-09 09:57:07 +00:00
)
)
)
)
);
2009-09-16 07:22:22 +00:00
}
2009-09-16 19:00:12 +00:00
/**
2009-09-16 06:50:31 +00:00
* Create one or more users
*
2012-01-18 10:52:25 +08:00
* @ param array $users An array of users to create .
2009-11-05 23:03:33 +00:00
* @ return array An array of arrays
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2009-09-16 06:50:31 +00:00
*/
2009-11-05 22:54:48 +00:00
public static function create_users ( $users ) {
2009-09-15 22:52:49 +00:00
global $CFG , $DB ;
2012-02-21 15:23:57 +08:00
require_once ( $CFG -> dirroot . " /lib/weblib.php " );
2010-02-11 04:02:04 +00:00
require_once ( $CFG -> dirroot . " /user/lib.php " );
2010-05-25 03:44:29 +00:00
require_once ( $CFG -> dirroot . " /user/profile/lib.php " ); //required for customfields related function
2010-07-27 09:07:24 +00:00
2009-09-16 06:50:31 +00:00
// Ensure the current user is allowed to run this function
2012-07-26 11:38:02 +08:00
$context = context_system :: instance ();
2009-09-15 22:52:49 +00:00
self :: validate_context ( $context );
2010-02-11 04:02:04 +00:00
require_capability ( 'moodle/user:create' , $context );
2010-07-08 08:40:21 +00:00
2009-09-16 06:50:31 +00:00
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
2009-11-05 22:54:48 +00:00
$params = self :: validate_parameters ( self :: create_users_parameters (), array ( 'users' => $users ));
2010-07-27 09:07:24 +00:00
2009-11-06 12:28:50 +00:00
$availableauths = get_plugin_list ( 'auth' );
unset ( $availableauths [ 'mnet' ]); // these would need mnethostid too
unset ( $availableauths [ 'webservice' ]); // we do not want new webservice users for now
$availablethemes = get_plugin_list ( 'theme' );
2010-04-14 09:45:49 +00:00
$availablelangs = get_string_manager () -> get_list_of_translations ();
2009-09-16 06:50:31 +00:00
2009-11-08 21:57:01 +00:00
$transaction = $DB -> start_delegated_transaction ();
2009-09-16 06:50:31 +00:00
2010-02-11 04:02:04 +00:00
$userids = array ();
2009-11-05 22:54:48 +00:00
foreach ( $params [ 'users' ] as $user ) {
2009-11-06 12:28:50 +00:00
// Make sure that the username doesn't already exist
if ( $DB -> record_exists ( 'user' , array ( 'username' => $user [ 'username' ], 'mnethostid' => $CFG -> mnet_localhost_id ))) {
throw new invalid_parameter_exception ( 'Username already exists: ' . $user [ 'username' ]);
2009-09-15 22:52:49 +00:00
}
2009-11-06 12:28:50 +00:00
// Make sure auth is valid
if ( empty ( $availableauths [ $user [ 'auth' ]])) {
throw new invalid_parameter_exception ( 'Invalid authentication type: ' . $user [ 'auth' ]);
2009-09-15 22:52:49 +00:00
}
2009-11-06 12:28:50 +00:00
// Make sure lang is valid
if ( empty ( $availablelangs [ $user [ 'lang' ]])) {
throw new invalid_parameter_exception ( 'Invalid language code: ' . $user [ 'lang' ]);
2009-09-15 22:52:49 +00:00
}
2009-11-06 12:28:50 +00:00
// Make sure lang is valid
2010-02-11 04:02:04 +00:00
if ( ! empty ( $user [ 'theme' ]) && empty ( $availablethemes [ $user [ 'theme' ]])) { //theme is VALUE_OPTIONAL,
// so no default value.
// We need to test if the client sent it
// => !empty($user['theme'])
2009-11-06 12:28:50 +00:00
throw new invalid_parameter_exception ( 'Invalid theme: ' . $user [ 'theme' ]);
2009-09-15 22:52:49 +00:00
}
2009-09-16 06:50:31 +00:00
2010-02-11 04:02:04 +00:00
$user [ 'confirmed' ] = true ;
2010-07-05 06:01:08 +00:00
$user [ 'mnethostid' ] = $CFG -> mnet_localhost_id ;
2010-05-25 03:44:29 +00:00
2012-02-21 15:23:57 +08:00
// Start of user info validation.
// Lets make sure we validate current user info as handled by current GUI. see user/editadvanced_form.php function validation()
if ( ! validate_email ( $user [ 'email' ])) {
throw new invalid_parameter_exception ( 'Email address is invalid: ' . $user [ 'email' ]);
} else if ( $DB -> record_exists ( 'user' , array ( 'email' => $user [ 'email' ], 'mnethostid' => $user [ 'mnethostid' ]))) {
throw new invalid_parameter_exception ( 'Email address already exists: ' . $user [ 'email' ]);
}
// End of user info validation.
2012-02-29 14:39:14 +08:00
// create the user data now!
$user [ 'id' ] = user_create_user ( $user );
2012-02-21 15:23:57 +08:00
2010-05-25 03:44:29 +00:00
// custom fields
if ( ! empty ( $user [ 'customfields' ])) {
foreach ( $user [ 'customfields' ] as $customfield ) {
$user [ " profile_field_ " . $customfield [ 'type' ]] = $customfield [ 'value' ]; //profile_save_data() saves profile file
//it's expecting a user with the correct id,
//and custom field to be named profile_field_"shortname"
}
profile_save_data (( object ) $user );
}
2009-11-06 12:28:50 +00:00
2010-07-08 08:40:21 +00:00
//preferences
if ( ! empty ( $user [ 'preferences' ])) {
foreach ( $user [ 'preferences' ] as $preference ) {
set_user_preference ( $preference [ 'type' ], $preference [ 'value' ], $user [ 'id' ]);
}
}
2009-09-16 19:00:12 +00:00
2010-05-27 07:33:36 +00:00
$userids [] = array ( 'id' => $user [ 'id' ], 'username' => $user [ 'username' ]);
2009-09-15 22:52:49 +00:00
}
2009-11-08 21:57:01 +00:00
$transaction -> allow_commit ();
2009-11-06 12:28:50 +00:00
2010-02-11 04:02:04 +00:00
return $userids ;
2009-09-15 22:52:49 +00:00
}
2009-11-05 22:54:48 +00:00
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
2009-11-05 22:54:48 +00:00
* @ return external_description
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2009-11-05 22:54:48 +00:00
*/
public static function create_users_returns () {
return new external_multiple_structure (
new external_single_structure (
array (
'id' => new external_value ( PARAM_INT , 'user id' ),
2012-04-13 14:09:25 +08:00
'username' => new external_value ( PARAM_USERNAME , 'user name' ),
2009-11-05 22:54:48 +00:00
)
)
);
2009-09-16 19:00:12 +00:00
}
2009-11-05 23:05:26 +00:00
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2009-11-05 23:05:26 +00:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2009-11-05 23:05:26 +00:00
*/
2009-09-16 19:00:12 +00:00
public static function delete_users_parameters () {
2009-11-05 23:05:26 +00:00
return new external_function_parameters (
array (
'userids' => new external_multiple_structure ( new external_value ( PARAM_INT , 'user ID' )),
)
);
2009-09-16 19:00:12 +00:00
}
2009-11-05 23:05:26 +00:00
2011-10-18 12:57:33 +08:00
/**
* Delete users
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ param array $userids
2011-10-25 15:28:52 +13:00
* @ return null
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2011-10-18 12:57:33 +08:00
*/
2009-11-08 21:57:01 +00:00
public static function delete_users ( $userids ) {
2010-08-12 08:12:46 +00:00
global $CFG , $DB , $USER ;
2010-02-11 04:02:04 +00:00
require_once ( $CFG -> dirroot . " /user/lib.php " );
2009-11-08 21:57:01 +00:00
// Ensure the current user is allowed to run this function
2012-07-26 11:38:02 +08:00
$context = context_system :: instance ();
2009-11-08 21:57:01 +00:00
require_capability ( 'moodle/user:delete' , $context );
self :: validate_context ( $context );
2010-02-11 04:02:04 +00:00
$params = self :: validate_parameters ( self :: delete_users_parameters (), array ( 'userids' => $userids ));
2009-11-08 21:57:01 +00:00
$transaction = $DB -> start_delegated_transaction ();
foreach ( $params [ 'userids' ] as $userid ) {
$user = $DB -> get_record ( 'user' , array ( 'id' => $userid , 'deleted' => 0 ), '*' , MUST_EXIST );
2010-08-12 08:12:46 +00:00
// must not allow deleting of admins or self!!!
2010-08-12 09:44:28 +00:00
if ( is_siteadmin ( $user )) {
throw new moodle_exception ( 'useradminodelete' , 'error' );
}
if ( $USER -> id == $user -> id ) {
throw new moodle_exception ( 'usernotdeletederror' , 'error' );
2010-08-12 08:12:46 +00:00
}
2010-02-11 04:02:04 +00:00
user_delete_user ( $user );
2009-11-08 21:57:01 +00:00
}
$transaction -> allow_commit ();
return null ;
2009-09-15 22:52:49 +00:00
}
2009-11-05 23:05:26 +00:00
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
* @ return null
* @ since Moodle 2.2
2009-11-05 23:05:26 +00:00
*/
2009-09-16 19:00:12 +00:00
public static function delete_users_returns () {
2009-11-05 23:05:26 +00:00
return null ;
2009-09-16 19:00:12 +00:00
}
2009-09-15 22:52:49 +00:00
2009-11-05 23:05:26 +00:00
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2009-11-05 23:05:26 +00:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2009-11-05 23:05:26 +00:00
*/
2009-09-16 19:00:12 +00:00
public static function update_users_parameters () {
2010-02-11 04:02:04 +00:00
global $CFG ;
2011-10-25 11:43:53 +13:00
return new external_function_parameters (
2010-02-11 04:02:04 +00:00
array (
'users' => new external_multiple_structure (
new external_single_structure (
array (
2012-05-11 11:34:34 +08:00
'id' => new external_value ( PARAM_INT , 'ID of the user' ),
2012-04-13 14:09:25 +08:00
'username' => new external_value ( PARAM_USERNAME , 'Username policy is defined in Moodle security config. Must be lowercase.' , VALUE_OPTIONAL , '' , NULL_NOT_ALLOWED ),
2010-02-11 04:02:04 +00:00
'password' => new external_value ( PARAM_RAW , 'Plain text password consisting of any characters' , VALUE_OPTIONAL , '' , NULL_NOT_ALLOWED ),
'firstname' => new external_value ( PARAM_NOTAGS , 'The first name(s) of the user' , VALUE_OPTIONAL , '' , NULL_NOT_ALLOWED ),
'lastname' => new external_value ( PARAM_NOTAGS , 'The family name of the user' , VALUE_OPTIONAL ),
'email' => new external_value ( PARAM_EMAIL , 'A valid and unique email address' , VALUE_OPTIONAL , '' , NULL_NOT_ALLOWED ),
2011-09-24 15:07:27 +02:00
'auth' => new external_value ( PARAM_PLUGIN , 'Auth plugins include manual, ldap, imap, etc' , VALUE_OPTIONAL , '' , NULL_NOT_ALLOWED ),
2010-02-11 04:02:04 +00:00
'idnumber' => new external_value ( PARAM_RAW , 'An arbitrary ID code number perhaps from the institution' , VALUE_OPTIONAL ),
2010-04-10 07:24:56 +00:00
'lang' => new external_value ( PARAM_SAFEDIR , 'Language code such as "en", must exist on server' , VALUE_OPTIONAL , '' , NULL_NOT_ALLOWED ),
2011-09-24 15:07:27 +02:00
'theme' => new external_value ( PARAM_PLUGIN , 'Theme name such as "standard", must exist on server' , VALUE_OPTIONAL ),
2011-06-09 11:29:43 +08:00
'timezone' => new external_value ( PARAM_TIMEZONE , 'Timezone code such as Australia/Perth, or 99 for default' , VALUE_OPTIONAL ),
2012-05-11 10:49:51 +08:00
'mailformat' => new external_value ( PARAM_INT , 'Mail format code is 0 for plain text, 1 for HTML etc' , VALUE_OPTIONAL ),
2010-07-08 08:40:21 +00:00
'description' => new external_value ( PARAM_TEXT , 'User profile description, no HTML' , VALUE_OPTIONAL ),
2010-02-11 04:02:04 +00:00
'city' => new external_value ( PARAM_NOTAGS , 'Home city of the user' , VALUE_OPTIONAL ),
'country' => new external_value ( PARAM_ALPHA , 'Home country code of the user, such as AU or CZ' , VALUE_OPTIONAL ),
'customfields' => new external_multiple_structure (
new external_single_structure (
array (
'type' => new external_value ( PARAM_ALPHANUMEXT , 'The name of the custom field' ),
'value' => new external_value ( PARAM_RAW , 'The value of the custom field' )
)
2010-08-06 15:22:27 +00:00
), 'User custom fields (also known as user profil fields)' , VALUE_OPTIONAL ),
2010-07-08 08:40:21 +00:00
'preferences' => new external_multiple_structure (
new external_single_structure (
array (
'type' => new external_value ( PARAM_ALPHANUMEXT , 'The name of the preference' ),
'value' => new external_value ( PARAM_RAW , 'The value of the preference' )
)
), 'User preferences' , VALUE_OPTIONAL ),
2010-02-11 04:02:04 +00:00
)
)
)
)
);
2009-09-16 19:00:12 +00:00
}
2009-11-08 21:57:01 +00:00
2011-10-18 12:57:33 +08:00
/**
* Update users
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ param array $users
2011-10-25 15:28:52 +13:00
* @ return null
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2011-10-18 12:57:33 +08:00
*/
2009-11-08 21:57:01 +00:00
public static function update_users ( $users ) {
global $CFG , $DB ;
2010-02-11 04:02:04 +00:00
require_once ( $CFG -> dirroot . " /user/lib.php " );
2010-02-15 08:56:51 +00:00
require_once ( $CFG -> dirroot . " /user/profile/lib.php " ); //required for customfields related function
2009-11-08 21:57:01 +00:00
// Ensure the current user is allowed to run this function
2012-07-26 11:38:02 +08:00
$context = context_system :: instance ();
2009-11-08 21:57:01 +00:00
require_capability ( 'moodle/user:update' , $context );
self :: validate_context ( $context );
$params = self :: validate_parameters ( self :: update_users_parameters (), array ( 'users' => $users ));
$transaction = $DB -> start_delegated_transaction ();
foreach ( $params [ 'users' ] as $user ) {
2010-02-11 04:02:04 +00:00
user_update_user ( $user );
2010-02-15 08:56:51 +00:00
//update user custom fields
if ( ! empty ( $user [ 'customfields' ])) {
foreach ( $user [ 'customfields' ] as $customfield ) {
$user [ " profile_field_ " . $customfield [ 'type' ]] = $customfield [ 'value' ]; //profile_save_data() saves profile file
//it's expecting a user with the correct id,
//and custom field to be named profile_field_"shortname"
}
profile_save_data (( object ) $user );
}
2010-07-08 08:40:21 +00:00
//preferences
if ( ! empty ( $user [ 'preferences' ])) {
foreach ( $user [ 'preferences' ] as $preference ) {
set_user_preference ( $preference [ 'type' ], $preference [ 'value' ], $user [ 'id' ]);
}
}
2009-11-08 21:57:01 +00:00
}
$transaction -> allow_commit ();
return null ;
2009-09-15 22:52:49 +00:00
}
2009-11-05 23:05:26 +00:00
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
* @ return null
* @ since Moodle 2.2
2009-11-05 23:05:26 +00:00
*/
2009-09-16 19:00:12 +00:00
public static function update_users_returns () {
2009-11-05 23:05:26 +00:00
return null ;
2009-09-16 19:00:12 +00:00
}
2009-11-05 22:54:48 +00:00
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2009-11-05 22:54:48 +00:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2009-11-05 22:54:48 +00:00
*/
2010-02-11 04:02:04 +00:00
public static function get_users_by_id_parameters () {
2009-11-05 23:03:33 +00:00
return new external_function_parameters (
2010-07-27 09:07:24 +00:00
array (
'userids' => new external_multiple_structure ( new external_value ( PARAM_INT , 'user ID' )),
)
2009-11-05 23:03:33 +00:00
);
2009-09-16 19:00:12 +00:00
}
2009-11-05 22:54:48 +00:00
2009-11-05 23:03:33 +00:00
/**
* Get user information
2011-06-08 16:07:12 +08:00
* - This function is matching the permissions of / user / profil . php
* - It is also matching some permissions from / user / editadvanced . php for the following fields :
* auth , confirmed , idnumber , lang , theme , timezone , mailformat
2012-01-18 10:52:25 +08:00
*
2009-11-05 23:03:33 +00:00
* @ param array $userids array of user ids
* @ return array An array of arrays describing users
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2009-11-05 23:03:33 +00:00
*/
2010-02-11 04:02:04 +00:00
public static function get_users_by_id ( $userids ) {
2011-06-08 16:07:12 +08:00
global $CFG , $USER , $DB ;
2010-07-27 09:07:24 +00:00
require_once ( $CFG -> dirroot . " /user/lib.php " );
2010-02-11 04:02:04 +00:00
2010-07-27 09:07:24 +00:00
$params = self :: validate_parameters ( self :: get_users_by_id_parameters (),
array ( 'userids' => $userids ));
2009-09-16 06:50:31 +00:00
2011-06-20 13:46:47 +08:00
list ( $uselect , $ujoin ) = context_instance_preload_sql ( 'u.id' , CONTEXT_USER , 'ctx' );
list ( $sqluserids , $params ) = $DB -> get_in_or_equal ( $userids );
$usersql = " SELECT u.* $uselect
FROM { user } u $ujoin
WHERE u . id $sqluserids " ;
$users = $DB -> get_recordset_sql ( $usersql , $params );
2009-09-16 19:00:12 +00:00
2010-07-27 09:07:24 +00:00
$result = array ();
2011-06-29 15:41:31 +08:00
$hasuserupdatecap = has_capability ( 'moodle/user:update' , get_system_context ());
2009-09-16 19:00:12 +00:00
foreach ( $users as $user ) {
2011-06-20 13:46:47 +08:00
if ( ! empty ( $user -> deleted )) {
continue ;
}
context_instance_preload ( $user );
2012-07-26 11:38:02 +08:00
$usercontext = context_user :: instance ( $user -> id , IGNORE_MISSING );
2011-06-29 15:41:31 +08:00
self :: validate_context ( $usercontext );
2011-06-08 16:07:12 +08:00
$currentuser = ( $user -> id == $USER -> id );
2011-06-29 15:41:31 +08:00
if ( $userarray = user_get_user_details ( $user )) {
//fields matching permissions from /user/editadvanced.php
if ( $currentuser or $hasuserupdatecap ) {
$userarray [ 'auth' ] = $user -> auth ;
$userarray [ 'confirmed' ] = $user -> confirmed ;
$userarray [ 'idnumber' ] = $user -> idnumber ;
$userarray [ 'lang' ] = $user -> lang ;
$userarray [ 'theme' ] = $user -> theme ;
$userarray [ 'timezone' ] = $user -> timezone ;
$userarray [ 'mailformat' ] = $user -> mailformat ;
2011-06-08 16:07:12 +08:00
}
2011-06-29 15:41:31 +08:00
$result [] = $userarray ;
2011-06-20 13:46:47 +08:00
}
2010-02-11 04:02:04 +00:00
}
2011-06-20 13:46:47 +08:00
$users -> close ();
2009-11-05 23:03:33 +00:00
return $result ;
2009-09-16 19:00:12 +00:00
}
2009-11-05 22:54:48 +00:00
2010-07-27 09:07:24 +00:00
/**
2009-11-05 22:54:48 +00:00
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
2009-11-05 22:54:48 +00:00
* @ return external_description
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2009-11-05 22:54:48 +00:00
*/
2010-02-11 04:02:04 +00:00
public static function get_users_by_id_returns () {
2009-11-05 23:03:33 +00:00
return new external_multiple_structure (
2011-06-20 13:46:47 +08:00
new external_single_structure (
array (
2012-05-11 11:34:34 +08:00
'id' => new external_value ( PARAM_INT , 'ID of the user' ),
2011-06-08 16:07:12 +08:00
'username' => new external_value ( PARAM_RAW , 'Username policy is defined in Moodle security config' , VALUE_OPTIONAL ),
'firstname' => new external_value ( PARAM_NOTAGS , 'The first name(s) of the user' , VALUE_OPTIONAL ),
'lastname' => new external_value ( PARAM_NOTAGS , 'The family name of the user' , VALUE_OPTIONAL ),
'fullname' => new external_value ( PARAM_NOTAGS , 'The fullname of the user' ),
'email' => new external_value ( PARAM_TEXT , 'An email address - allow email as root@localhost' , VALUE_OPTIONAL ),
2012-05-11 15:50:09 +08:00
'address' => new external_value ( PARAM_TEXT , 'Postal address' , VALUE_OPTIONAL ),
2011-06-08 16:07:12 +08:00
'phone1' => new external_value ( PARAM_NOTAGS , 'Phone 1' , VALUE_OPTIONAL ),
'phone2' => new external_value ( PARAM_NOTAGS , 'Phone 2' , VALUE_OPTIONAL ),
'icq' => new external_value ( PARAM_NOTAGS , 'icq number' , VALUE_OPTIONAL ),
'skype' => new external_value ( PARAM_NOTAGS , 'skype id' , VALUE_OPTIONAL ),
'yahoo' => new external_value ( PARAM_NOTAGS , 'yahoo id' , VALUE_OPTIONAL ),
'aim' => new external_value ( PARAM_NOTAGS , 'aim id' , VALUE_OPTIONAL ),
'msn' => new external_value ( PARAM_NOTAGS , 'msn number' , VALUE_OPTIONAL ),
'department' => new external_value ( PARAM_TEXT , 'department' , VALUE_OPTIONAL ),
'institution' => new external_value ( PARAM_TEXT , 'institution' , VALUE_OPTIONAL ),
'interests' => new external_value ( PARAM_TEXT , 'user interests (separated by commas)' , VALUE_OPTIONAL ),
'firstaccess' => new external_value ( PARAM_INT , 'first access to the site (0 if never)' , VALUE_OPTIONAL ),
'lastaccess' => new external_value ( PARAM_INT , 'last access to the site (0 if never)' , VALUE_OPTIONAL ),
2011-09-24 15:07:27 +02:00
'auth' => new external_value ( PARAM_PLUGIN , 'Auth plugins include manual, ldap, imap, etc' , VALUE_OPTIONAL ),
2012-05-11 11:34:34 +08:00
'confirmed' => new external_value ( PARAM_INT , 'Active user: 1 if confirmed, 0 otherwise' , VALUE_OPTIONAL ),
2011-06-08 16:07:12 +08:00
'idnumber' => new external_value ( PARAM_RAW , 'An arbitrary ID code number perhaps from the institution' , VALUE_OPTIONAL ),
'lang' => new external_value ( PARAM_SAFEDIR , 'Language code such as "en", must exist on server' , VALUE_OPTIONAL ),
2011-09-24 15:07:27 +02:00
'theme' => new external_value ( PARAM_PLUGIN , 'Theme name such as "standard", must exist on server' , VALUE_OPTIONAL ),
2011-06-14 10:45:03 +08:00
'timezone' => new external_value ( PARAM_TIMEZONE , 'Timezone code such as Australia/Perth, or 99 for default' , VALUE_OPTIONAL ),
2012-05-11 10:49:51 +08:00
'mailformat' => new external_value ( PARAM_INT , 'Mail format code is 0 for plain text, 1 for HTML etc' , VALUE_OPTIONAL ),
2011-06-08 16:07:12 +08:00
'description' => new external_value ( PARAM_RAW , 'User profile description' , VALUE_OPTIONAL ),
2012-05-31 12:31:27 +08:00
'descriptionformat' => new external_format_value ( 'description' , VALUE_OPTIONAL ),
2011-06-08 16:07:12 +08:00
'city' => new external_value ( PARAM_NOTAGS , 'Home city of the user' , VALUE_OPTIONAL ),
'url' => new external_value ( PARAM_URL , 'URL of the user' , VALUE_OPTIONAL ),
'country' => new external_value ( PARAM_ALPHA , 'Home country code of the user, such as AU or CZ' , VALUE_OPTIONAL ),
'profileimageurlsmall' => new external_value ( PARAM_URL , 'User image profile URL - small version' ),
'profileimageurl' => new external_value ( PARAM_URL , 'User image profile URL - big version' ),
2009-11-05 23:03:33 +00:00
'customfields' => new external_multiple_structure (
2011-06-20 13:46:47 +08:00
new external_single_structure (
array (
'type' => new external_value ( PARAM_ALPHANUMEXT , 'The type of the custom field - text field, checkbox...' ),
'value' => new external_value ( PARAM_RAW , 'The value of the custom field' ),
'name' => new external_value ( PARAM_RAW , 'The name of the custom field' ),
'shortname' => new external_value ( PARAM_RAW , 'The shortname of the custom field - to be able to build the field class in the code' ),
)
), 'User custom fields (also known as user profil fields)' , VALUE_OPTIONAL ),
2011-06-08 16:07:12 +08:00
'preferences' => new external_multiple_structure (
2011-06-20 13:46:47 +08:00
new external_single_structure (
array (
'name' => new external_value ( PARAM_ALPHANUMEXT , 'The name of the preferences' ),
'value' => new external_value ( PARAM_RAW , 'The value of the custom field' ),
)
), 'User preferences' , VALUE_OPTIONAL ),
2011-06-08 16:07:12 +08:00
'enrolledcourses' => new external_multiple_structure (
2011-06-20 13:46:47 +08:00
new external_single_structure (
array (
'id' => new external_value ( PARAM_INT , 'Id of the course' ),
2011-06-29 15:41:31 +08:00
'fullname' => new external_value ( PARAM_RAW , 'Fullname of the course' ),
'shortname' => new external_value ( PARAM_RAW , 'Shortname of the course' )
2011-06-20 13:46:47 +08:00
)
), 'Courses where the user is enrolled - limited by which courses the user is able to see' , VALUE_OPTIONAL )
)
)
);
}
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2011-06-20 13:46:47 +08:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2011-06-20 13:46:47 +08:00
*/
2011-10-18 12:57:33 +08:00
public static function get_course_user_profiles_parameters () {
2011-06-20 13:46:47 +08:00
return new external_function_parameters (
array (
'userlist' => new external_multiple_structure (
new external_single_structure (
array (
'userid' => new external_value ( PARAM_INT , 'userid' ),
'courseid' => new external_value ( PARAM_INT , 'courseid' ),
2010-07-27 09:07:24 +00:00
)
2011-06-20 13:46:47 +08:00
)
2009-11-05 23:03:33 +00:00
)
2011-06-20 13:46:47 +08:00
)
);
}
/**
* Get course participant ' s details
2012-01-18 10:52:25 +08:00
*
2011-06-20 13:46:47 +08:00
* @ param array $userlist array of user ids and according course ids
* @ return array An array of arrays describing course participants
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2011-06-20 13:46:47 +08:00
*/
2011-10-18 12:57:33 +08:00
public static function get_course_user_profiles ( $userlist ) {
2011-06-20 13:46:47 +08:00
global $CFG , $USER , $DB ;
require_once ( $CFG -> dirroot . " /user/lib.php " );
2011-10-18 12:57:33 +08:00
$params = self :: validate_parameters ( self :: get_course_user_profiles_parameters (), array ( 'userlist' => $userlist ));
2011-06-20 13:46:47 +08:00
$userids = array ();
$courseids = array ();
foreach ( $params [ 'userlist' ] as $value ) {
$userids [] = $value [ 'userid' ];
$courseids [ $value [ 'userid' ]] = $value [ 'courseid' ];
}
// cache all courses
$courses = array ();
list ( $cselect , $cjoin ) = context_instance_preload_sql ( 'c.id' , CONTEXT_COURSE , 'ctx' );
list ( $sqlcourseids , $params ) = $DB -> get_in_or_equal ( array_unique ( $courseids ));
2012-01-21 16:08:25 +01:00
$coursesql = " SELECT c.* $cselect
2011-06-20 13:46:47 +08:00
FROM { course } c $cjoin
WHERE c . id $sqlcourseids " ;
$rs = $DB -> get_recordset_sql ( $coursesql , $params );
foreach ( $rs as $course ) {
// adding course contexts to cache
context_instance_preload ( $course );
// cache courses
$courses [ $course -> id ] = $course ;
}
$rs -> close ();
list ( $uselect , $ujoin ) = context_instance_preload_sql ( 'u.id' , CONTEXT_USER , 'ctx' );
list ( $sqluserids , $params ) = $DB -> get_in_or_equal ( $userids );
$usersql = " SELECT u.* $uselect
FROM { user } u $ujoin
WHERE u . id $sqluserids " ;
$users = $DB -> get_recordset_sql ( $usersql , $params );
$result = array ();
foreach ( $users as $user ) {
if ( ! empty ( $user -> deleted )) {
continue ;
}
context_instance_preload ( $user );
$course = $courses [ $courseids [ $user -> id ]];
2012-07-26 11:38:02 +08:00
$context = context_course :: instance ( $courseids [ $user -> id ], IGNORE_MISSING );
2011-06-20 13:46:47 +08:00
self :: validate_context ( $context );
2011-06-29 15:41:31 +08:00
if ( $userarray = user_get_user_details ( $user , $course )) {
$result [] = $userarray ;
2011-06-20 13:46:47 +08:00
}
2011-06-29 15:41:31 +08:00
}
2011-06-20 13:46:47 +08:00
2011-06-29 15:41:31 +08:00
$users -> close ();
2011-06-20 13:46:47 +08:00
2011-06-29 15:41:31 +08:00
return $result ;
}
2011-06-20 13:46:47 +08:00
2011-06-29 15:41:31 +08:00
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
2011-06-29 15:41:31 +08:00
* @ return external_description
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.2
2011-06-29 15:41:31 +08:00
*/
2011-10-18 12:57:33 +08:00
public static function get_course_user_profiles_returns () {
2011-06-29 15:41:31 +08:00
return new external_multiple_structure (
new external_single_structure (
array (
2012-05-11 11:34:34 +08:00
'id' => new external_value ( PARAM_INT , 'ID of the user' ),
2011-06-29 15:41:31 +08:00
'username' => new external_value ( PARAM_RAW , 'Username policy is defined in Moodle security config' , VALUE_OPTIONAL ),
'firstname' => new external_value ( PARAM_NOTAGS , 'The first name(s) of the user' , VALUE_OPTIONAL ),
'lastname' => new external_value ( PARAM_NOTAGS , 'The family name of the user' , VALUE_OPTIONAL ),
'fullname' => new external_value ( PARAM_NOTAGS , 'The fullname of the user' ),
'email' => new external_value ( PARAM_TEXT , 'An email address - allow email as root@localhost' , VALUE_OPTIONAL ),
2012-05-11 15:50:09 +08:00
'address' => new external_value ( PARAM_TEXT , 'Postal address' , VALUE_OPTIONAL ),
2011-06-29 15:41:31 +08:00
'phone1' => new external_value ( PARAM_NOTAGS , 'Phone 1' , VALUE_OPTIONAL ),
'phone2' => new external_value ( PARAM_NOTAGS , 'Phone 2' , VALUE_OPTIONAL ),
'icq' => new external_value ( PARAM_NOTAGS , 'icq number' , VALUE_OPTIONAL ),
'skype' => new external_value ( PARAM_NOTAGS , 'skype id' , VALUE_OPTIONAL ),
'yahoo' => new external_value ( PARAM_NOTAGS , 'yahoo id' , VALUE_OPTIONAL ),
'aim' => new external_value ( PARAM_NOTAGS , 'aim id' , VALUE_OPTIONAL ),
'msn' => new external_value ( PARAM_NOTAGS , 'msn number' , VALUE_OPTIONAL ),
'department' => new external_value ( PARAM_TEXT , 'department' , VALUE_OPTIONAL ),
'institution' => new external_value ( PARAM_TEXT , 'institution' , VALUE_OPTIONAL ),
2012-06-21 12:59:21 -05:00
'idnumber' => new external_value ( PARAM_RAW , 'An arbitrary ID code number perhaps from the institution' , VALUE_OPTIONAL ),
2011-06-29 15:41:31 +08:00
'interests' => new external_value ( PARAM_TEXT , 'user interests (separated by commas)' , VALUE_OPTIONAL ),
'firstaccess' => new external_value ( PARAM_INT , 'first access to the site (0 if never)' , VALUE_OPTIONAL ),
'lastaccess' => new external_value ( PARAM_INT , 'last access to the site (0 if never)' , VALUE_OPTIONAL ),
'description' => new external_value ( PARAM_RAW , 'User profile description' , VALUE_OPTIONAL ),
2012-05-31 12:31:27 +08:00
'descriptionformat' => new external_format_value ( 'description' , VALUE_OPTIONAL ),
2011-06-29 15:41:31 +08:00
'city' => new external_value ( PARAM_NOTAGS , 'Home city of the user' , VALUE_OPTIONAL ),
'url' => new external_value ( PARAM_URL , 'URL of the user' , VALUE_OPTIONAL ),
'country' => new external_value ( PARAM_ALPHA , 'Home country code of the user, such as AU or CZ' , VALUE_OPTIONAL ),
'profileimageurlsmall' => new external_value ( PARAM_URL , 'User image profile URL - small version' ),
'profileimageurl' => new external_value ( PARAM_URL , 'User image profile URL - big version' ),
'customfields' => new external_multiple_structure (
new external_single_structure (
array (
'type' => new external_value ( PARAM_ALPHANUMEXT , 'The type of the custom field - text field, checkbox...' ),
'value' => new external_value ( PARAM_RAW , 'The value of the custom field' ),
'name' => new external_value ( PARAM_RAW , 'The name of the custom field' ),
'shortname' => new external_value ( PARAM_RAW , 'The shortname of the custom field - to be able to build the field class in the code' ),
)
), 'User custom fields (also known as user profil fields)' , VALUE_OPTIONAL ),
'groups' => new external_multiple_structure (
new external_single_structure (
array (
'id' => new external_value ( PARAM_INT , 'group id' ),
'name' => new external_value ( PARAM_RAW , 'group name' ),
'description' => new external_value ( PARAM_RAW , 'group description' ),
2012-05-31 12:31:27 +08:00
'descriptionformat' => new external_format_value ( 'description' ),
2011-06-29 15:41:31 +08:00
)
), 'user groups' , VALUE_OPTIONAL ),
'roles' => new external_multiple_structure (
new external_single_structure (
array (
'roleid' => new external_value ( PARAM_INT , 'role id' ),
'name' => new external_value ( PARAM_RAW , 'role name' ),
'shortname' => new external_value ( PARAM_ALPHANUMEXT , 'role shortname' ),
'sortorder' => new external_value ( PARAM_INT , 'role sortorder' )
)
), 'user roles' , VALUE_OPTIONAL ),
'preferences' => new external_multiple_structure (
new external_single_structure (
array (
'name' => new external_value ( PARAM_ALPHANUMEXT , 'The name of the preferences' ),
'value' => new external_value ( PARAM_RAW , 'The value of the custom field' ),
)
), 'User preferences' , VALUE_OPTIONAL ),
'enrolledcourses' => new external_multiple_structure (
new external_single_structure (
array (
'id' => new external_value ( PARAM_INT , 'Id of the course' ),
'fullname' => new external_value ( PARAM_RAW , 'Fullname of the course' ),
'shortname' => new external_value ( PARAM_RAW , 'Shortname of the course' )
)
), 'Courses where the user is enrolled - limited by which courses the user is able to see' , VALUE_OPTIONAL )
)
)
);
}
2011-10-18 12:57:33 +08:00
}
2012-01-18 10:52:25 +08:00
/**
* Deprecated user external functions
*
* @ package core_user
* @ copyright 2009 Petr Skodak
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not use this class any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external
2011-10-18 12:57:33 +08:00
*/
class moodle_user_external extends external_api {
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: create_users_parameters ()
2011-10-18 12:57:33 +08:00
*/
public static function create_users_parameters () {
return core_user_external :: create_users_parameters ();
}
/**
* Create one or more users
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ param array $users An array of users to create .
* @ return array An array of arrays
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: create_users ()
2011-10-18 12:57:33 +08:00
*/
public static function create_users ( $users ) {
return core_user_external :: create_users ( $users );
}
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ return external_description
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: create_users_returns ()
2011-10-18 12:57:33 +08:00
*/
public static function create_users_returns () {
return core_user_external :: create_users_returns ();
}
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: delete_users_parameters ()
2011-10-18 12:57:33 +08:00
*/
public static function delete_users_parameters () {
return core_user_external :: delete_users_parameters ();
}
/**
* Delete users
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ param array $userids
2011-10-25 15:28:52 +13:00
* @ return null
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: delete_users ()
2011-10-18 12:57:33 +08:00
*/
public static function delete_users ( $userids ) {
return core_user_external :: delete_users ( $userids );
}
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
* @ return null
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: delete_users_returns ()
2011-10-18 12:57:33 +08:00
*/
public static function delete_users_returns () {
return core_user_external :: delete_users_returns ();
}
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: update_users_parameters ()
2011-10-18 12:57:33 +08:00
*/
public static function update_users_parameters () {
return core_user_external :: update_users_parameters ();
}
/**
* Update users
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ param array $users
2011-10-25 15:28:52 +13:00
* @ return null
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: update_users ()
2011-10-18 12:57:33 +08:00
*/
public static function update_users ( $users ) {
return core_user_external :: update_users ( $users );
}
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
* @ return null
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: update_users_returns ()
2011-10-18 12:57:33 +08:00
*/
public static function update_users_returns () {
return core_user_external :: update_users_returns ();
}
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: get_users_by_id_parameters ()
2011-10-18 12:57:33 +08:00
*/
public static function get_users_by_id_parameters () {
return core_user_external :: get_users_by_id_parameters ();
}
/**
* Get user information
* - This function is matching the permissions of / user / profil . php
* - It is also matching some permissions from / user / editadvanced . php for the following fields :
* auth , confirmed , idnumber , lang , theme , timezone , mailformat
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ param array $userids array of user ids
* @ return array An array of arrays describing users
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: get_users_by_id ()
2011-10-18 12:57:33 +08:00
*/
public static function get_users_by_id ( $userids ) {
return core_user_external :: get_users_by_id ( $userids );
}
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ return external_description
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.0
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: get_users_by_id_returns ()
2011-10-18 12:57:33 +08:00
*/
public static function get_users_by_id_returns () {
return core_user_external :: get_users_by_id_returns ();
}
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.1
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: get_course_user_profiles_parameters ()
2011-10-18 12:57:33 +08:00
*/
public static function get_course_participants_by_id_parameters () {
return core_user_external :: get_course_user_profiles_parameters ();
}
/**
* Get course participant ' s details
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ param array $userlist array of user ids and according course ids
* @ return array An array of arrays describing course participants
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.1
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: get_course_user_profiles ()
2011-10-18 12:57:33 +08:00
*/
public static function get_course_participants_by_id ( $userlist ) {
return core_user_external :: get_course_user_profiles ( $userlist );
}
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
2011-10-18 12:57:33 +08:00
* @ return external_description
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.1
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_user_external :: get_course_user_profiles_returns ()
2011-10-18 12:57:33 +08:00
*/
public static function get_course_participants_by_id_returns () {
return core_user_external :: get_course_user_profiles_returns ();
}
2011-06-20 13:46:47 +08:00
2011-06-29 15:41:31 +08:00
/**
* Returns description of method parameters
2012-01-18 10:52:25 +08:00
*
2011-06-29 15:41:31 +08:00
* @ return external_function_parameters
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.1
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_enrol_external :: get_enrolled_users_parameters ()
2011-06-29 15:41:31 +08:00
*/
public static function get_users_by_courseid_parameters () {
2011-10-18 12:57:33 +08:00
global $CFG ;
require_once ( $CFG -> dirroot . '/enrol/externallib.php' );
return core_enrol_external :: get_enrolled_users_parameters ();
2011-06-29 15:41:31 +08:00
}
2011-06-20 13:46:47 +08:00
2011-06-29 15:41:31 +08:00
/**
* Get course participants details
2012-01-18 10:52:25 +08:00
*
2011-06-29 15:41:31 +08:00
* @ param int $courseid course id
* @ param array $options options {
2012-01-18 10:52:25 +08:00
* 'name' => option name
* 'value' => option value
* }
2011-06-29 15:41:31 +08:00
* @ return array An array of users
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.1
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_enrol_external :: get_enrolled_users ()
2011-06-29 15:41:31 +08:00
*/
public static function get_users_by_courseid ( $courseid , $options ) {
2011-10-18 12:57:33 +08:00
global $CFG ;
require_once ( $CFG -> dirroot . '/enrol/externallib.php' );
return core_enrol_external :: get_enrolled_users ( $courseid , $options );
2011-06-20 13:46:47 +08:00
}
/**
* Returns description of method result value
2012-01-18 10:52:25 +08:00
*
2011-06-20 13:46:47 +08:00
* @ return external_description
2012-01-18 10:52:25 +08:00
* @ since Moodle 2.1
* @ deprecated Moodle 2.2 MDL - 29106 - Please do not call this function any more .
* @ todo MDL - 31194 This will be deleted in Moodle 2.5 .
* @ see core_enrol_external :: get_enrolled_users_returns ()
2011-06-20 13:46:47 +08:00
*/
2011-06-29 15:41:31 +08:00
public static function get_users_by_courseid_returns () {
2011-10-18 12:57:33 +08:00
global $CFG ;
require_once ( $CFG -> dirroot . '/enrol/externallib.php' );
return core_enrol_external :: get_enrolled_users_returns ();
2009-09-16 06:50:31 +00:00
}
}