]> git.mjollnir.org Git - moodle.git/commitdiff
web service MDL-12886 remove paramsorder trick for real ws functions that call core...
authorjerome <jerome>
Wed, 14 Jan 2009 08:11:56 +0000 (08:11 +0000)
committerjerome <jerome>
Wed, 14 Jan 2009 08:11:56 +0000 (08:11 +0000)
user/wsapi.php
webservice/rest/lib.php
webservice/rest/testclient/createuser.php

index f34fc1b7f8d6fb722e0f9a4252fad4cb86ec0637..358e79bbda453b8d28c91528b8709d717b8631dd 100644 (file)
@@ -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 <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);
+    
+    }
 
+}
 
 ?>
index 23d14757e2cabf8f3460e9bed6d8c816041482ca..4e162ade171423be321f276baec74e0858489489 100644 (file)
@@ -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 <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;
 }
 
index 3b8425fe06e2c7adbda920d1d3bd74acbd969b53..5e564eba01cf74d4396d5a045d7a42f8f6b02b67 100644 (file)
@@ -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);