From: Petr Skoda Date: Thu, 5 Nov 2009 23:05:26 +0000 (+0000) Subject: MDL-12886 more external users api X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=930680cba27d42cde1085ef19fcc3b8ed07f7551;p=moodle.git MDL-12886 more external users api --- diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 57cf7f5c62..7ce6f43d55 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -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: \'$a->functionname()\' function of \'$a->classname\' class doesn\'t specify any \'service\' into its description'; -$string['wsdoesntextendbaseclass'] = 'Error during web service discovery process: \'$a\' class does not extend from moodle_external class'; $string['wwwrootmismatch'] = 'Incorrect access detected, this server may be accessed only through \"$a\" address, sorry.
Please notify server administrator.'; $string['wwwrootslash'] = 'Detected incorrect \$CFG->wwwroot in config.php, it must not contain trailing slash.
Please notify server administrator.'; $string['xmldberror'] = 'XMLDB error!'; diff --git a/user/external.php b/user/external.php deleted file mode 100644 index a6bacc356d..0000000000 --- a/user/external.php +++ /dev/null @@ -1,134 +0,0 @@ -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'); - } - - } - -} - - diff --git a/user/externallib.php b/user/externallib.php index ee8d84711d..eeddfe25f9 100644 --- a/user/externallib.php +++ b/user/externallib.php @@ -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 *