* @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 {
$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 <type> $search
+ * @return <type>
+ */
+ 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 <type> $username
+ * @param <type> $firstname
+ * @param <type> $lastname
+ * @param <type> $email
+ * @param <type> $password
+ * @return <type>
+ */
+ 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);
+
+ }
+}
?>
$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
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]);
* @return <type>
*/
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;
}