MDL-12886 more external users api

This commit is contained in:
Petr Skoda 2009-11-05 23:05:26 +00:00
parent 71864f15e5
commit 930680cba2
3 changed files with 27 additions and 146 deletions

View File

@ -481,15 +481,6 @@ $string['wrongsourcebase'] = 'Wrong source URL base';
$string['wrongusernamepassword'] = 'Wrong user/password';
$string['wrongzipfilename'] = 'Wrong ZIP file name';
$string['wscouldnotcreateecoursenopermission'] = 'WS - Could not create course - No permission';
$string['wscouldnotcreateeusernopermission'] = 'WS - Could not create a user - No permission';
$string['wscouldnotdeletenoexistinguser'] = 'WS - Could not delete a user - User doesn\'t exist';
$string['wscouldnotdeleteusernopermission'] = 'WS - Could not delete a user - No permission';
$string['wscouldnotupdatenoexistinguser'] = 'WS - Could not update a user - User doesn\'t exist';
$string['wscouldnotupdateuserindb'] = 'WS - Could not update a user';
$string['wscouldnotupdateusernopermission'] = 'WS - Could not update a user - No permission';
$string['wscouldnotvieweusernopermission'] = 'WS - Could not view a user - No permission';
$string['wsdescriptionserviceisempty'] = 'Error during web service discovery process: \'<b>$a->functionname()</b>\' function of \'<b>$a->classname</b>\' class doesn\'t specify any \'service\' into its description';
$string['wsdoesntextendbaseclass'] = 'Error during web service discovery process: \'<b>$a</b>\' class does not extend from moodle_external class';
$string['wwwrootmismatch'] = 'Incorrect access detected, this server may be accessed only through \"$a\" address, sorry.<br />Please notify server administrator.';
$string['wwwrootslash'] = 'Detected incorrect \$CFG->wwwroot in config.php, it must not contain trailing slash.<br />Please notify server administrator.';
$string['xmldberror'] = 'XMLDB error!';

View File

@ -1,134 +0,0 @@
<?php
/**
* Moodle - Modular Object-Oriented Dynamic Learning Environment
* http://moodle.com
*
* LICENSE
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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:
*
* http://www.gnu.org/copyleft/gpl.html
*
* @category Moodle
* @package user
* @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
*/
die('this file is being migrated to exxternallib.php right now...');
require_once(dirname(dirname(__FILE__)) . '/lib/moodleexternal.php');
require_once(dirname(dirname(__FILE__)) . '/user/lib.php');
/**
* users webservice api
*
* @author Jerome Mouneyrac
*/
final class user_external extends moodle_external {
/**
* Constructor - We set the description of this API in order to be access by Web service
*/
function __construct () {
$this->descriptions = array();
$params = new object();
$params->usernames = array(PARAM_ALPHANUMEXT);
$return = new object();
$return->result = PARAM_BOOL;
$this->descriptions['delete_users'] = array( 'params' => $params,
'optionalparams' => 'All params are not mandatory',
'return' => $return,
'service' => 'user',
'requiredlogin' => 0);
$user->newusername = PARAM_ALPHANUMEXT;
$params = new object();
$params->users = array($user);
$this->descriptions['update_users'] = array( 'params' => $params,
'optionalparams' => 'All params are not mandatory',
'return' => $return,
'service' => 'user',
'requiredlogin' => 0);
}
/**
* Delete multiple users
* @global object $DB
* @param object|struct $params - need to be define as struct for XMLRPC
* @return boolean result true if success
*/
public function delete_users($params) {
global $DB,$USER;
$deletionsuccessfull = true;
if (has_capability('moodle/user:delete', get_context_instance(CONTEXT_SYSTEM))) {
$this->clean_function_params('delete_users', $params);
foreach ($params->usernames as $username) {
$user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>1));
if (empty($user)) {
throw new moodle_exception('wscouldnotdeletenoexistinguser');
}
if (!delete_user($user)) {
$deletionsuccessfull = false; //this function is in moodlelib.php
}
}
return $deletionsuccessfull;
}
else {
throw new moodle_exception('wscouldnotdeleteusernopermission');
}
}
/**
* Update some users information
* @global object $DB
* @param object|struct $params - need to be define as struct for XMLRPC
* @return boolean result true if success
*/
public function update_users($params) {
global $DB,$USER;
if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
$updatesuccessfull = true;
$this->clean_function_params('update_users', $params);
foreach ($params->users as $paramuser) {
$user = $DB->get_record('user', array('username'=> $paramuser->username, 'mnethostid'=>1));
if (empty($user)) {
throw new moodle_exception('wscouldnotupdatenoexistinguser');
}
$user->username = $paramuser->newusername;
try {
$DB->update_record('user', $user);
}
catch (dml_write_exception $e) {
throw new moodle_exception('wscouldnotupdateuserindb');
}
}
return $updatesuccessfull;
}
else {
throw new moodle_exception('wscouldnotupdateusernopermission');
}
}
}

View File

@ -152,25 +152,48 @@ class moodle_user_external extends external_api {
}
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public static function delete_users_parameters() {
//TODO
return new external_function_parameters(
array(
'userids' => new external_multiple_structure(new external_value(PARAM_INT, 'user ID')),
)
);
}
public static function delete_users($params) {
//TODO
}
/**
* Returns description of method result value
* @return external_description
*/
public static function delete_users_returns() {
//TODO
return null;
}
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public static function update_users_parameters() {
//TODO
}
public static function update_users($params) {
//TODO
}
/**
* Returns description of method result value
* @return external_description
*/
public static function update_users_returns() {
//TODO
return null;
}
/**
@ -185,6 +208,7 @@ class moodle_user_external extends external_api {
);
}
/**
* Get user information
*