Adding plugin abstract class and adding a step to activities to generate their module.xml
[moodle.git] / user / lib.php
blob92ffdf7c2a211a426160cf9c07804c01155fc052
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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/>.
18 /**
19 * External user API
21 * @package moodlecore
22 * @subpackage user
23 * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 /**
29 * Creates a user
30 * @param object $user user to create
31 * @return int id of the newly created user
33 function user_create_user($user) {
34 global $DB;
36 /// set the timecreate field to the current time
37 if (!is_object($user)) {
38 $user = (object)$user;
41 /// hash the password
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);
53 return $newuserid;
57 /**
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) {
62 global $DB;
64 /// set the timecreate field to the current time
65 if (!is_object($user)) {
66 $user = (object)$user;
69 /// hash the password
70 $user->password = hash_internal_user_password($user->password);
72 $user->timemodified = time();
73 $DB->update_record('user', $user);
77 /**
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);
89 /**
90 * Get users by id
91 * @param array $userids id of users to retrieve
94 function user_get_users_by_id($userids) {
95 global $DB;
96 return $DB->get_records_list('user', 'id', $userids);