|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require_once("$CFG->libdir/externallib.php"); 00028 00032 class core_user_external extends external_api { 00033 00038 public static function create_users_parameters() { 00039 global $CFG; 00040 00041 return new external_function_parameters( 00042 array( 00043 'users' => new external_multiple_structure( 00044 new external_single_structure( 00045 array( 00046 'username' => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config'), 00047 'password' => new external_value(PARAM_RAW, 'Plain text password consisting of any characters'), 00048 'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user'), 00049 'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user'), 00050 'email' => new external_value(PARAM_EMAIL, 'A valid and unique email address'), 00051 'auth' => new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT, 'manual', NULL_NOT_ALLOWED), 00052 'idnumber' => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_DEFAULT, ''), 00053 'lang' => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_DEFAULT, $CFG->lang, NULL_NOT_ALLOWED), 00054 'theme' => new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL), 00055 'timezone' => new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL), 00056 'mailformat' => new external_value(PARAM_INTEGER, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL), 00057 'description' => new external_value(PARAM_TEXT, 'User profile description, no HTML', VALUE_OPTIONAL), 00058 'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL), 00059 'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL), 00060 'preferences' => new external_multiple_structure( 00061 new external_single_structure( 00062 array( 00063 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preference'), 00064 'value' => new external_value(PARAM_RAW, 'The value of the preference') 00065 ) 00066 ), 'User preferences', VALUE_OPTIONAL), 00067 'customfields' => new external_multiple_structure( 00068 new external_single_structure( 00069 array( 00070 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'), 00071 'value' => new external_value(PARAM_RAW, 'The value of the custom field') 00072 ) 00073 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL) 00074 ) 00075 ) 00076 ) 00077 ) 00078 ); 00079 } 00080 00087 public static function create_users($users) { 00088 global $CFG, $DB; 00089 require_once($CFG->dirroot."/user/lib.php"); 00090 require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function 00091 //TODO: move the functions somewhere else as 00092 //they are "user" related 00093 00094 // Ensure the current user is allowed to run this function 00095 $context = get_context_instance(CONTEXT_SYSTEM); 00096 self::validate_context($context); 00097 require_capability('moodle/user:create', $context); 00098 00099 // Do basic automatic PARAM checks on incoming data, using params description 00100 // If any problems are found then exceptions are thrown with helpful error messages 00101 $params = self::validate_parameters(self::create_users_parameters(), array('users'=>$users)); 00102 00103 $availableauths = get_plugin_list('auth'); 00104 unset($availableauths['mnet']); // these would need mnethostid too 00105 unset($availableauths['webservice']); // we do not want new webservice users for now 00106 00107 $availablethemes = get_plugin_list('theme'); 00108 $availablelangs = get_string_manager()->get_list_of_translations(); 00109 00110 $transaction = $DB->start_delegated_transaction(); 00111 00112 $userids = array(); 00113 foreach ($params['users'] as $user) { 00114 // Make sure that the username doesn't already exist 00115 if ($DB->record_exists('user', array('username'=>$user['username'], 'mnethostid'=>$CFG->mnet_localhost_id))) { 00116 throw new invalid_parameter_exception('Username already exists: '.$user['username']); 00117 } 00118 00119 // Make sure auth is valid 00120 if (empty($availableauths[$user['auth']])) { 00121 throw new invalid_parameter_exception('Invalid authentication type: '.$user['auth']); 00122 } 00123 00124 // Make sure lang is valid 00125 if (empty($availablelangs[$user['lang']])) { 00126 throw new invalid_parameter_exception('Invalid language code: '.$user['lang']); 00127 } 00128 00129 // Make sure lang is valid 00130 if (!empty($user['theme']) && empty($availablethemes[$user['theme']])) { //theme is VALUE_OPTIONAL, 00131 // so no default value. 00132 // We need to test if the client sent it 00133 // => !empty($user['theme']) 00134 throw new invalid_parameter_exception('Invalid theme: '.$user['theme']); 00135 } 00136 00137 // make sure there is no data loss during truncation 00138 $truncated = truncate_userinfo($user); 00139 foreach ($truncated as $key=>$value) { 00140 if ($truncated[$key] !== $user[$key]) { 00141 throw new invalid_parameter_exception('Property: '.$key.' is too long: '.$user[$key]); 00142 } 00143 } 00144 00145 $user['confirmed'] = true; 00146 $user['mnethostid'] = $CFG->mnet_localhost_id; 00147 $user['id'] = user_create_user($user); 00148 00149 // custom fields 00150 if(!empty($user['customfields'])) { 00151 foreach($user['customfields'] as $customfield) { 00152 $user["profile_field_".$customfield['type']] = $customfield['value']; //profile_save_data() saves profile file 00153 //it's expecting a user with the correct id, 00154 //and custom field to be named profile_field_"shortname" 00155 } 00156 profile_save_data((object) $user); 00157 } 00158 00159 //preferences 00160 if (!empty($user['preferences'])) { 00161 foreach($user['preferences'] as $preference) { 00162 set_user_preference($preference['type'], $preference['value'],$user['id']); 00163 } 00164 } 00165 00166 $userids[] = array('id'=>$user['id'], 'username'=>$user['username']); 00167 } 00168 00169 $transaction->allow_commit(); 00170 00171 return $userids; 00172 } 00173 00178 public static function create_users_returns() { 00179 return new external_multiple_structure( 00180 new external_single_structure( 00181 array( 00182 'id' => new external_value(PARAM_INT, 'user id'), 00183 'username' => new external_value(PARAM_RAW, 'user name'), 00184 ) 00185 ) 00186 ); 00187 } 00188 00189 00194 public static function delete_users_parameters() { 00195 return new external_function_parameters( 00196 array( 00197 'userids' => new external_multiple_structure(new external_value(PARAM_INT, 'user ID')), 00198 ) 00199 ); 00200 } 00201 00207 public static function delete_users($userids) { 00208 global $CFG, $DB, $USER; 00209 require_once($CFG->dirroot."/user/lib.php"); 00210 00211 // Ensure the current user is allowed to run this function 00212 $context = get_context_instance(CONTEXT_SYSTEM); 00213 require_capability('moodle/user:delete', $context); 00214 self::validate_context($context); 00215 00216 $params = self::validate_parameters(self::delete_users_parameters(), array('userids'=>$userids)); 00217 00218 $transaction = $DB->start_delegated_transaction(); 00219 00220 foreach ($params['userids'] as $userid) { 00221 $user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST); 00222 // must not allow deleting of admins or self!!! 00223 if (is_siteadmin($user)) { 00224 throw new moodle_exception('useradminodelete', 'error'); 00225 } 00226 if ($USER->id == $user->id) { 00227 throw new moodle_exception('usernotdeletederror', 'error'); 00228 } 00229 user_delete_user($user); 00230 } 00231 00232 $transaction->allow_commit(); 00233 00234 return null; 00235 } 00236 00241 public static function delete_users_returns() { 00242 return null; 00243 } 00244 00245 00250 public static function update_users_parameters() { 00251 global $CFG; 00252 return new external_function_parameters( 00253 array( 00254 'users' => new external_multiple_structure( 00255 new external_single_structure( 00256 array( 00257 'id' => new external_value(PARAM_NUMBER, 'ID of the user'), 00258 'username' => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED), 00259 'password' => new external_value(PARAM_RAW, 'Plain text password consisting of any characters', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED), 00260 'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED), 00261 'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL), 00262 'email' => new external_value(PARAM_EMAIL, 'A valid and unique email address', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED), 00263 'auth' => new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL, '', NULL_NOT_ALLOWED), 00264 'idnumber' => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL), 00265 'lang' => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_OPTIONAL, '', NULL_NOT_ALLOWED), 00266 'theme' => new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL), 00267 'timezone' => new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL), 00268 'mailformat' => new external_value(PARAM_INTEGER, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL), 00269 'description' => new external_value(PARAM_TEXT, 'User profile description, no HTML', VALUE_OPTIONAL), 00270 'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL), 00271 'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL), 00272 'customfields' => new external_multiple_structure( 00273 new external_single_structure( 00274 array( 00275 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'), 00276 'value' => new external_value(PARAM_RAW, 'The value of the custom field') 00277 ) 00278 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL), 00279 'preferences' => new external_multiple_structure( 00280 new external_single_structure( 00281 array( 00282 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preference'), 00283 'value' => new external_value(PARAM_RAW, 'The value of the preference') 00284 ) 00285 ), 'User preferences', VALUE_OPTIONAL), 00286 ) 00287 ) 00288 ) 00289 ) 00290 ); 00291 } 00292 00298 public static function update_users($users) { 00299 global $CFG, $DB; 00300 require_once($CFG->dirroot."/user/lib.php"); 00301 require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function 00302 //TODO: move the functions somewhere else as 00303 //they are "user" related 00304 00305 // Ensure the current user is allowed to run this function 00306 $context = get_context_instance(CONTEXT_SYSTEM); 00307 require_capability('moodle/user:update', $context); 00308 self::validate_context($context); 00309 00310 $params = self::validate_parameters(self::update_users_parameters(), array('users'=>$users)); 00311 00312 $transaction = $DB->start_delegated_transaction(); 00313 00314 foreach ($params['users'] as $user) { 00315 user_update_user($user); 00316 //update user custom fields 00317 if(!empty($user['customfields'])) { 00318 00319 foreach($user['customfields'] as $customfield) { 00320 $user["profile_field_".$customfield['type']] = $customfield['value']; //profile_save_data() saves profile file 00321 //it's expecting a user with the correct id, 00322 //and custom field to be named profile_field_"shortname" 00323 } 00324 profile_save_data((object) $user); 00325 } 00326 00327 //preferences 00328 if (!empty($user['preferences'])) { 00329 foreach($user['preferences'] as $preference) { 00330 set_user_preference($preference['type'], $preference['value'],$user['id']); 00331 } 00332 } 00333 } 00334 00335 $transaction->allow_commit(); 00336 00337 return null; 00338 } 00339 00344 public static function update_users_returns() { 00345 return null; 00346 } 00347 00352 public static function get_users_by_id_parameters() { 00353 return new external_function_parameters( 00354 array( 00355 'userids' => new external_multiple_structure(new external_value(PARAM_INT, 'user ID')), 00356 ) 00357 ); 00358 } 00359 00368 public static function get_users_by_id($userids) { 00369 global $CFG, $USER, $DB; 00370 require_once($CFG->dirroot . "/user/lib.php"); 00371 00372 $params = self::validate_parameters(self::get_users_by_id_parameters(), 00373 array('userids'=>$userids)); 00374 00375 list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx'); 00376 list($sqluserids, $params) = $DB->get_in_or_equal($userids); 00377 $usersql = "SELECT u.* $uselect 00378 FROM {user} u $ujoin 00379 WHERE u.id $sqluserids"; 00380 $users = $DB->get_recordset_sql($usersql, $params); 00381 00382 $result = array(); 00383 $hasuserupdatecap = has_capability('moodle/user:update', get_system_context()); 00384 foreach ($users as $user) { 00385 if (!empty($user->deleted)) { 00386 continue; 00387 } 00388 context_instance_preload($user); 00389 $usercontext = get_context_instance(CONTEXT_USER, $user->id); 00390 self::validate_context($usercontext); 00391 $currentuser = ($user->id == $USER->id); 00392 00393 if ($userarray = user_get_user_details($user)) { 00394 //fields matching permissions from /user/editadvanced.php 00395 if ($currentuser or $hasuserupdatecap) { 00396 $userarray['auth'] = $user->auth; 00397 $userarray['confirmed'] = $user->confirmed; 00398 $userarray['idnumber'] = $user->idnumber; 00399 $userarray['lang'] = $user->lang; 00400 $userarray['theme'] = $user->theme; 00401 $userarray['timezone'] = $user->timezone; 00402 $userarray['mailformat'] = $user->mailformat; 00403 } 00404 $result[] = $userarray; 00405 } 00406 } 00407 $users->close(); 00408 00409 return $result; 00410 } 00411 00416 public static function get_users_by_id_returns() { 00417 return new external_multiple_structure( 00418 new external_single_structure( 00419 array( 00420 'id' => new external_value(PARAM_NUMBER, 'ID of the user'), 00421 'username' => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL), 00422 'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL), 00423 'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL), 00424 'fullname' => new external_value(PARAM_NOTAGS, 'The fullname of the user'), 00425 'email' => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost', VALUE_OPTIONAL), 00426 'address' => new external_value(PARAM_MULTILANG, 'Postal address', VALUE_OPTIONAL), 00427 'phone1' => new external_value(PARAM_NOTAGS, 'Phone 1', VALUE_OPTIONAL), 00428 'phone2' => new external_value(PARAM_NOTAGS, 'Phone 2', VALUE_OPTIONAL), 00429 'icq' => new external_value(PARAM_NOTAGS, 'icq number', VALUE_OPTIONAL), 00430 'skype' => new external_value(PARAM_NOTAGS, 'skype id', VALUE_OPTIONAL), 00431 'yahoo' => new external_value(PARAM_NOTAGS, 'yahoo id', VALUE_OPTIONAL), 00432 'aim' => new external_value(PARAM_NOTAGS, 'aim id', VALUE_OPTIONAL), 00433 'msn' => new external_value(PARAM_NOTAGS, 'msn number', VALUE_OPTIONAL), 00434 'department' => new external_value(PARAM_TEXT, 'department', VALUE_OPTIONAL), 00435 'institution' => new external_value(PARAM_TEXT, 'institution', VALUE_OPTIONAL), 00436 'interests' => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL), 00437 'firstaccess' => new external_value(PARAM_INT, 'first access to the site (0 if never)', VALUE_OPTIONAL), 00438 'lastaccess' => new external_value(PARAM_INT, 'last access to the site (0 if never)', VALUE_OPTIONAL), 00439 'auth' => new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL), 00440 'confirmed' => new external_value(PARAM_NUMBER, 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL), 00441 'idnumber' => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL), 00442 'lang' => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_OPTIONAL), 00443 'theme' => new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL), 00444 'timezone' => new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL), 00445 'mailformat' => new external_value(PARAM_INTEGER, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL), 00446 'description' => new external_value(PARAM_RAW, 'User profile description', VALUE_OPTIONAL), 00447 'descriptionformat' => new external_value(PARAM_INT, 'User profile description format', VALUE_OPTIONAL), 00448 'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL), 00449 'url' => new external_value(PARAM_URL, 'URL of the user', VALUE_OPTIONAL), 00450 'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL), 00451 'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'), 00452 'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'), 00453 'customfields' => new external_multiple_structure( 00454 new external_single_structure( 00455 array( 00456 'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'), 00457 'value' => new external_value(PARAM_RAW, 'The value of the custom field'), 00458 'name' => new external_value(PARAM_RAW, 'The name of the custom field'), 00459 'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'), 00460 ) 00461 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL), 00462 'preferences' => new external_multiple_structure( 00463 new external_single_structure( 00464 array( 00465 'name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preferences'), 00466 'value' => new external_value(PARAM_RAW, 'The value of the custom field'), 00467 ) 00468 ), 'User preferences', VALUE_OPTIONAL), 00469 'enrolledcourses' => new external_multiple_structure( 00470 new external_single_structure( 00471 array( 00472 'id' => new external_value(PARAM_INT, 'Id of the course'), 00473 'fullname' => new external_value(PARAM_RAW, 'Fullname of the course'), 00474 'shortname' => new external_value(PARAM_RAW, 'Shortname of the course') 00475 ) 00476 ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL) 00477 ) 00478 ) 00479 ); 00480 } 00485 public static function get_course_user_profiles_parameters() { 00486 return new external_function_parameters( 00487 array( 00488 'userlist' => new external_multiple_structure( 00489 new external_single_structure( 00490 array( 00491 'userid' => new external_value(PARAM_INT, 'userid'), 00492 'courseid' => new external_value(PARAM_INT, 'courseid'), 00493 ) 00494 ) 00495 ) 00496 ) 00497 ); 00498 } 00499 00505 public static function get_course_user_profiles($userlist) { 00506 global $CFG, $USER, $DB; 00507 require_once($CFG->dirroot . "/user/lib.php"); 00508 $params = self::validate_parameters(self::get_course_user_profiles_parameters(), array('userlist'=>$userlist)); 00509 00510 $userids = array(); 00511 $courseids = array(); 00512 foreach ($params['userlist'] as $value) { 00513 $userids[] = $value['userid']; 00514 $courseids[$value['userid']] = $value['courseid']; 00515 } 00516 00517 // cache all courses 00518 $courses = array(); 00519 list($cselect, $cjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); 00520 list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids)); 00521 $coursesql = "SELECT c.* $cselect 00522 FROM {course} c $cjoin 00523 WHERE c.id $sqlcourseids"; 00524 $rs = $DB->get_recordset_sql($coursesql, $params); 00525 foreach ($rs as $course) { 00526 // adding course contexts to cache 00527 context_instance_preload($course); 00528 // cache courses 00529 $courses[$course->id] = $course; 00530 } 00531 $rs->close(); 00532 00533 list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx'); 00534 list($sqluserids, $params) = $DB->get_in_or_equal($userids); 00535 $usersql = "SELECT u.* $uselect 00536 FROM {user} u $ujoin 00537 WHERE u.id $sqluserids"; 00538 $users = $DB->get_recordset_sql($usersql, $params); 00539 $result = array(); 00540 foreach ($users as $user) { 00541 if (!empty($user->deleted)) { 00542 continue; 00543 } 00544 context_instance_preload($user); 00545 $course = $courses[$courseids[$user->id]]; 00546 $context = get_context_instance(CONTEXT_COURSE, $courseids[$user->id]); 00547 self::validate_context($context); 00548 if ($userarray = user_get_user_details($user, $course)) { 00549 $result[] = $userarray; 00550 } 00551 } 00552 00553 $users->close(); 00554 00555 return $result; 00556 } 00557 00562 public static function get_course_user_profiles_returns() { 00563 return new external_multiple_structure( 00564 new external_single_structure( 00565 array( 00566 'id' => new external_value(PARAM_NUMBER, 'ID of the user'), 00567 'username' => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL), 00568 'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL), 00569 'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL), 00570 'fullname' => new external_value(PARAM_NOTAGS, 'The fullname of the user'), 00571 'email' => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost', VALUE_OPTIONAL), 00572 'address' => new external_value(PARAM_MULTILANG, 'Postal address', VALUE_OPTIONAL), 00573 'phone1' => new external_value(PARAM_NOTAGS, 'Phone 1', VALUE_OPTIONAL), 00574 'phone2' => new external_value(PARAM_NOTAGS, 'Phone 2', VALUE_OPTIONAL), 00575 'icq' => new external_value(PARAM_NOTAGS, 'icq number', VALUE_OPTIONAL), 00576 'skype' => new external_value(PARAM_NOTAGS, 'skype id', VALUE_OPTIONAL), 00577 'yahoo' => new external_value(PARAM_NOTAGS, 'yahoo id', VALUE_OPTIONAL), 00578 'aim' => new external_value(PARAM_NOTAGS, 'aim id', VALUE_OPTIONAL), 00579 'msn' => new external_value(PARAM_NOTAGS, 'msn number', VALUE_OPTIONAL), 00580 'department' => new external_value(PARAM_TEXT, 'department', VALUE_OPTIONAL), 00581 'institution' => new external_value(PARAM_TEXT, 'institution', VALUE_OPTIONAL), 00582 'interests' => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL), 00583 'firstaccess' => new external_value(PARAM_INT, 'first access to the site (0 if never)', VALUE_OPTIONAL), 00584 'lastaccess' => new external_value(PARAM_INT, 'last access to the site (0 if never)', VALUE_OPTIONAL), 00585 'description' => new external_value(PARAM_RAW, 'User profile description', VALUE_OPTIONAL), 00586 'descriptionformat' => new external_value(PARAM_INT, 'User profile description format', VALUE_OPTIONAL), 00587 'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL), 00588 'url' => new external_value(PARAM_URL, 'URL of the user', VALUE_OPTIONAL), 00589 'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL), 00590 'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'), 00591 'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'), 00592 'customfields' => new external_multiple_structure( 00593 new external_single_structure( 00594 array( 00595 'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'), 00596 'value' => new external_value(PARAM_RAW, 'The value of the custom field'), 00597 'name' => new external_value(PARAM_RAW, 'The name of the custom field'), 00598 'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'), 00599 ) 00600 ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL), 00601 'groups' => new external_multiple_structure( 00602 new external_single_structure( 00603 array( 00604 'id' => new external_value(PARAM_INT, 'group id'), 00605 'name' => new external_value(PARAM_RAW, 'group name'), 00606 'description' => new external_value(PARAM_RAW, 'group description'), 00607 ) 00608 ), 'user groups', VALUE_OPTIONAL), 00609 'roles' => new external_multiple_structure( 00610 new external_single_structure( 00611 array( 00612 'roleid' => new external_value(PARAM_INT, 'role id'), 00613 'name' => new external_value(PARAM_RAW, 'role name'), 00614 'shortname' => new external_value(PARAM_ALPHANUMEXT, 'role shortname'), 00615 'sortorder' => new external_value(PARAM_INT, 'role sortorder') 00616 ) 00617 ), 'user roles', VALUE_OPTIONAL), 00618 'preferences' => new external_multiple_structure( 00619 new external_single_structure( 00620 array( 00621 'name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preferences'), 00622 'value' => new external_value(PARAM_RAW, 'The value of the custom field'), 00623 ) 00624 ), 'User preferences', VALUE_OPTIONAL), 00625 'enrolledcourses' => new external_multiple_structure( 00626 new external_single_structure( 00627 array( 00628 'id' => new external_value(PARAM_INT, 'Id of the course'), 00629 'fullname' => new external_value(PARAM_RAW, 'Fullname of the course'), 00630 'shortname' => new external_value(PARAM_RAW, 'Shortname of the course') 00631 ) 00632 ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL) 00633 ) 00634 ) 00635 ); 00636 } 00637 } 00638 00643 class moodle_user_external extends external_api { 00644 00650 public static function create_users_parameters() { 00651 return core_user_external::create_users_parameters(); 00652 } 00653 00660 public static function create_users($users) { 00661 return core_user_external::create_users($users); 00662 } 00663 00669 public static function create_users_returns() { 00670 return core_user_external::create_users_returns(); 00671 } 00672 00673 00679 public static function delete_users_parameters() { 00680 return core_user_external::delete_users_parameters(); 00681 } 00682 00689 public static function delete_users($userids) { 00690 return core_user_external::delete_users($userids); 00691 } 00692 00698 public static function delete_users_returns() { 00699 return core_user_external::delete_users_returns(); 00700 } 00701 00702 00708 public static function update_users_parameters() { 00709 return core_user_external::update_users_parameters(); 00710 } 00711 00718 public static function update_users($users) { 00719 return core_user_external::update_users($users); 00720 } 00721 00727 public static function update_users_returns() { 00728 return core_user_external::update_users_returns(); 00729 } 00730 00736 public static function get_users_by_id_parameters() { 00737 return core_user_external::get_users_by_id_parameters(); 00738 } 00739 00749 public static function get_users_by_id($userids) { 00750 return core_user_external::get_users_by_id($userids); 00751 } 00752 00758 public static function get_users_by_id_returns() { 00759 return core_user_external::get_users_by_id_returns(); 00760 } 00766 public static function get_course_participants_by_id_parameters() { 00767 return core_user_external::get_course_user_profiles_parameters(); 00768 } 00769 00776 public static function get_course_participants_by_id($userlist) { 00777 return core_user_external::get_course_user_profiles($userlist); 00778 } 00779 00785 public static function get_course_participants_by_id_returns() { 00786 return core_user_external::get_course_user_profiles_returns(); 00787 } 00788 00794 public static function get_users_by_courseid_parameters() { 00795 global $CFG; 00796 require_once($CFG->dirroot . '/enrol/externallib.php'); 00797 return core_enrol_external::get_enrolled_users_parameters(); 00798 } 00799 00810 public static function get_users_by_courseid($courseid, $options) { 00811 global $CFG; 00812 require_once($CFG->dirroot . '/enrol/externallib.php'); 00813 return core_enrol_external::get_enrolled_users($courseid, $options); 00814 } 00820 public static function get_users_by_courseid_returns() { 00821 global $CFG; 00822 require_once($CFG->dirroot . '/enrol/externallib.php'); 00823 return core_enrol_external::get_enrolled_users_returns(); 00824 } 00825 }