3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
23 * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 * @param object $user user to create
31 * @return int id of the newly created user
33 function user_create_user($user) {
36 /// set the timecreate field to the current time
37 if (!is_object($user)) {
38 $user = (object)$user;
42 $user->password
= hash_internal_user_password($user->password
);
44 $user->timecreated
= time();
45 $user->timemodified
= $user->timecreated
;
47 /// insert the user into the database
48 $newuserid = $DB->insert_record('user', $user);
50 /// create USER context for this user
51 get_context_instance(CONTEXT_USER
, $newuserid);
58 * Update a user with a user object (will compare against the ID)
59 * @param object $user - the user to update
61 function user_update_user($user) {
64 /// set the timecreate field to the current time
65 if (!is_object($user)) {
66 $user = (object)$user;
70 $user->password
= hash_internal_user_password($user->password
);
72 $user->timemodified
= time();
73 $DB->update_record('user', $user);
78 * Marks user deleted in internal user database and notifies the auth plugin.
79 * Also unenrols user from all roles and does other cleanup.
81 * @todo Decide if this transaction is really needed (look for internal TODO:)
82 * @param object $user Userobject before delete (without system magic quotes)
83 * @return boolean success
85 function user_delete_user($user) {
86 return delete_user($user);
91 * @param array $userids id of users to retrieve
94 function user_get_users_by_id($userids) {
96 return $DB->get_records_list('user', 'id', $userids);