From: jerome Date: Wed, 14 Jan 2009 08:11:56 +0000 (+0000) Subject: web service MDL-12886 remove paramsorder trick for real ws functions that call core... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=50c192729593460115b53979f22089826f8d710b;p=moodle.git web service MDL-12886 remove paramsorder trick for real ws functions that call core functions (make easier to understand + easier to implement soap protocol) --- diff --git a/user/wsapi.php b/user/wsapi.php index f34fc1b7f8..358e79bbda 100644 --- a/user/wsapi.php +++ b/user/wsapi.php @@ -7,9 +7,10 @@ * @author Jerome Mouneyrac */ require_once(dirname(dirname(__FILE__)) . '/lib/moodlewsapi.php'); +require_once(dirname(dirname(__FILE__)) . '/user/api.php'); /** - * WORK IN PROGRESS + * WORK IN PROGRESS, DO NOT USE IT */ final class user_ws_api extends moodle_ws_api { @@ -34,30 +35,48 @@ final class user_ws_api extends moodle_ws_api { $this->descriptions['tmp_get_users'] = array( 'wsparams' => array('search'=> PARAM_ALPHA), 'return' => array('user', array('id' => PARAM_RAW, 'auth' => PARAM_RAW, 'confirmed' => PARAM_RAW, 'username' => PARAM_RAW, 'idnumber' => PARAM_RAW, 'firstname' => PARAM_RAW, 'lastname' => PARAM_RAW, 'email' => PARAM_RAW, 'emailstop' => PARAM_RAW, - 'lang' => PARAM_RAW, 'theme' => PARAM_RAW, 'timezone' => PARAM_RAW, 'mailformat' => PARAM_RAW)), - 'paramorder' => array('get' => true, 'search' => '', 'confirmed' => false, 'exceptions' =>null, 'sort' => 'firstname ASC', - 'firstinitial' => '', 'lastinitial' => '', 'page' => '', 'recordsperpage' => '', - 'fields' => 'id, auth, confirmed, username, idnumber, firstname, lastname, email, emailstop, lang, theme, timezone, mailformat', - 'extraselect' => '', 'extraparams' => null)); + 'lang' => PARAM_RAW, 'theme' => PARAM_RAW, 'timezone' => PARAM_RAW, 'mailformat' => PARAM_RAW))); - $this->descriptions['tmp_create_user'] = array( 'wsparams' => array('user:username'=> PARAM_RAW, 'user:firstname'=> PARAM_RAW, 'user:lastname'=> PARAM_RAW, 'user:email'=> PARAM_RAW, 'user:password'=> PARAM_RAW), - 'return' => array('userid', PARAM_RAW), - 'paramorder' => array('user' => array('username' => null, 'firstname' => null, 'lastname'=> null, 'email'=> null, 'password'=>''))); + $this->descriptions['tmp_create_user'] = array( 'wsparams' => array('username'=> PARAM_RAW, 'firstname'=> PARAM_RAW, 'lastname'=> PARAM_RAW, 'email'=> PARAM_RAW, 'password'=> PARAM_RAW), + 'return' => array('userid', PARAM_RAW)); - $this->descriptions['tmp_namedparams_get_users'] = array( 'wsparams' => array('selectioncriteria:search'=> PARAM_RAW), + + $this->descriptions['tmp_namedparams_get_users'] = array( 'wsparams' => array('search'=> PARAM_RAW), 'return' => array('user', array('id' => PARAM_RAW, 'auth' => PARAM_RAW, 'confirmed' => PARAM_RAW, 'username' => PARAM_RAW, 'idnumber' => PARAM_RAW, 'firstname' => PARAM_RAW, 'lastname' => PARAM_RAW, 'email' => PARAM_RAW, 'emailstop' => PARAM_RAW, - 'lang' => PARAM_RAW, 'theme' => PARAM_RAW, 'timezone' => PARAM_RAW, 'mailformat' => PARAM_RAW)), - 'paramorder' => array('sort' => 'firstname ASC', '$recordsperpage' => 999999, 'page' => 0, - 'fields' => 'id, auth, confirmed, username, idnumber, firstname, lastname, email, emailstop, lang, theme, timezone, mailformat', - 'selectioncriteria' => array('search' => ''))); + 'lang' => PARAM_RAW, 'theme' => PARAM_RAW, 'timezone' => PARAM_RAW, 'mailformat' => PARAM_RAW))); } + /** + * + * @param $search + * @return + */ + static function tmp_get_users($search) { + return user_api::tmp_get_users( true, $search, false, null, 'firstname ASC','', '', '', '', + 'id, auth, confirmed, username, idnumber, firstname, lastname, email, emailstop, lang, theme, timezone, mailformat'); + } -} - - - + /** + * + * @param $username + * @param $firstname + * @param $lastname + * @param $email + * @param $password + * @return + */ + static function tmp_create_user($username, $firstname, $lastname, $email, $password) { + $user = array(); + $user['username'] = $username; + $user['firstname'] = $firstname; + $user['lastname'] = $lastname; + $user['email'] = $email; + $user['password'] = $password; + return user_api::tmp_create_user($user); + + } +} ?> diff --git a/webservice/rest/lib.php b/webservice/rest/lib.php index 23d14757e2..4e162ade17 100644 --- a/webservice/rest/lib.php +++ b/webservice/rest/lib.php @@ -22,7 +22,6 @@ function call_moodle_function ($rest_arguments) { $classname = str_replace('/', '_', $apipath); // convert '/' into '_' (e.g. /mod/forum/ => _mod_forum_) $classname = substr($classname,1, strlen($classname) - 1); //remove first _ (e.g. _mod_forum => mod_forum) - $coreclassname = $classname."api"; $classname .= 'ws_api'; ///these three next lines can be generic => create a function @@ -38,9 +37,9 @@ function call_moodle_function ($rest_arguments) { if ($params === false) { //return an error message, the REST params doesn't match with the web service description } - require_once($CFG->dirroot.$apipath.'api.php'); - $res = call_user_func_array ( $coreclassname.'::'.$functionname, $params); - + //require_once($CFG->dirroot.$apipath.'api.php'); + $res = call_user_func_array ( $classname.'::'.$functionname, $params); + ///Transform result into xml in order to send the REST response $return = mdl_conn_rest_object_to_xml ($res,$description['return'][0]); @@ -55,21 +54,16 @@ function call_moodle_function ($rest_arguments) { * @return */ function retrieve_params ($description) { - $params = $description['paramorder']; + $params = $description['wsparam']; //retrieve REST param matching the description foreach ($description['wsparams'] as $paramname => $paramtype) { $value = optional_param($paramname,null,$paramtype); if (!empty($value)) { - $fullstopposition = strrpos($paramname,":"); - //case: param is an object/array - if (!empty($fullstopposition)) { - $params[substr($paramname,0,$fullstopposition)][substr($paramname,$fullstopposition+1, strlen($paramname) - $fullstopposition)] = $value; - } else { - $params[$paramname] = $value; + $params[$paramname] = $value; } } - } + return $params; } diff --git a/webservice/rest/testclient/createuser.php b/webservice/rest/testclient/createuser.php index 3b8425fe06..5e564eba01 100644 --- a/webservice/rest/testclient/createuser.php +++ b/webservice/rest/testclient/createuser.php @@ -14,10 +14,10 @@ start_interface("Create A User"); $ch = curl_init(); -$data['user:username'] = "mockuser4"; -$data['user:firstname'] = "mockuser4"; -$data['user:lastname'] = "mockuser4"; -$data['user:email'] = "mockuser4@lastname.com"; +$data['username'] = "mockuser5"; +$data['firstname'] = "mockuser5"; +$data['lastname'] = "mockuser5"; +$data['email'] = "mockuser5@lastname.com"; var_dump($data);