Skip to content

Commit

Permalink
web service MDL-12886 create lib.php in user folder (need create_user…
Browse files Browse the repository at this point in the history
… and update_user)
  • Loading branch information
jerome committed Jan 28, 2009
1 parent f26cc1a commit 194985d
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions user/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ function __construct () {
* @return object user
*/
static function tmp_get_users($params) {
return get_users(true, $params['search'], false, null, 'firstname ASC','', '', '', '', 'id, auth, confirmed, username, idnumber, firstname, lastname, email, emailstop, lang, theme, timezone, mailformat');
global $USER;
if (has_capability('moodle/user:viewdetails', get_context_instance(CONTEXT_SYSTEM))) {
return get_users(true, $params['search'], false, null, 'firstname ASC','', '', '', '', 'id, auth, confirmed, username, idnumber, firstname, lastname, email, emailstop, lang, theme, timezone, mailformat');

}
else {
throw new moodle_exception('couldnotvieweuser');
}
}

/**
Expand All @@ -73,9 +80,6 @@ static function tmp_create_user($params) {
$user['lastname'] = $params['lastname'];
$user['email'] = $params['email'];
$user['password'] = $params['password'];
///
/// TODO: implement a core function (look at some code into editadvanced.php)
///
return user_lib::tmp_create_user($user);
}
else {
Expand Down Expand Up @@ -115,20 +119,22 @@ static function tmp_delete_user($params) {
* @return bool true if success
*/
static function tmp_update_user($params) {
global $DB;
$user = $DB->get_record('user', array('username'=>$params['username'], 'mnethostid'=>$params['mnethostid']));
global $DB,$USER;
if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
$user = $DB->get_record('user', array('username'=>$params['username'], 'mnethostid'=>$params['mnethostid']));

if (!empty($params['newusername'])) {
$user->username = $params['newusername'];
if (!empty($params['newusername'])) {
$user->username = $params['newusername'];
}
if (!empty($params['firstname'])) {
$user->firstname = $params['firstname'];
}
return user_lib::tmp_update_user($user);
}
if (!empty($params['firstname'])) {
$user->firstname = $params['firstname'];
else {
throw new moodle_exception('couldnotupdateuser');
}

///
/// TODO: implement a core function (look at some code into edit.php/editadvanced.php)
///
return user_lib::tmp_update_user($user);

}

}
Expand Down

0 comments on commit 194985d

Please sign in to comment.