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'); } } } ?>