]> git.mjollnir.org Git - moodle.git/commitdiff
web service MDL-12886 rename wsapi.php as external.php, function tmp_delete_user...
authorjerome <jerome>
Thu, 22 Jan 2009 04:58:50 +0000 (04:58 +0000)
committerjerome <jerome>
Thu, 22 Jan 2009 04:58:50 +0000 (04:58 +0000)
lib/moodleexternal.php [new file with mode: 0644]
user/external.php [new file with mode: 0644]
webservice/rest/lib.php
webservice/soap/generatewsdl.php
webservice/soap/moodle.wsdl
webservice/soap/server.php

diff --git a/lib/moodleexternal.php b/lib/moodleexternal.php
new file mode 100644 (file)
index 0000000..c3802aa
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/* 
+* Created on 01/12/2008
+ *
+ * Moodle base webservice api
+ *
+ * @author Jerome Mouneyrac
+ */
+
+/**
+ * DO NOT USE ANYTHING FROM THIS FILE - WORK IN PROGRESS
+ */
+abstract class moodle_external {
+
+ protected $descriptions;
+ protected $user;
+
+    /**
+     * Constructor - We set the description of this API in order to be access by Web service
+     */
+    function __construct ($user = null) {
+        $this->descriptions = array();
+    }
+
+     /**
+     *
+     *  @param <type> $functionname
+     */
+    public function get_function_webservice_description($functionname) {
+        if (key_exists($functionname, $this->descriptions)) {
+            return $this->descriptions[$functionname];
+        }
+        else {
+            return false;
+        }
+    }
+
+    /**
+     *
+     * @return <type> 
+     */
+    public function get_descriptions() {
+        return $this->descriptions;
+    }
+
+}
+?>
diff --git a/user/external.php b/user/external.php
new file mode 100644 (file)
index 0000000..d7f08b7
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Created on 05/03/2008
+ *
+ * users webservice api
+ *
+ * @author Jerome Mouneyrac
+ */
+require_once(dirname(dirname(__FILE__)) . '/lib/moodleexternal.php');
+require_once(dirname(dirname(__FILE__)) . '/user/api.php');
+
+/**
+ * WORK IN PROGRESS, DO NOT USE IT
+ */
+final class user_external extends moodle_external {
+
+    /**
+     * Constructor - We set the description of this API in order to be access by Web service
+     */
+    function __construct () {
+          $this->descriptions = array();
+       ///The desciption of the web service
+       ///
+       ///'wsparams' and 'return' are used to described the web services to the end user (can build WSDL file from these information)
+       ///
+       ///Note: web services param names have not importance. However 'paramorder' must match the function params order.
+       ///And all web services param names defined into 'wsparams' should be included into 'paramorder' (otherwise they will not be used)
+          $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_get_users']   = array( 'wsparams' => array('search'=> PARAM_ALPHANUM),
+                                                      '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)));
+    
+          $this->descriptions['tmp_delete_user']   = array( 'wsparams' => array('username'=> PARAM_ALPHANUM, 'mnethostid'=> PARAM_NUMBER),
+                                                      'return' => array('result' => PARAM_BOOL));
+
+          $this->descriptions['tmp_update_user']   = array( 'wsparams' => array('username'=> PARAM_ALPHANUM, 'mnethostid'=> PARAM_NUMBER, 'newusername' => PARAM_ALPHANUM, 'firstname' => PARAM_ALPHANUM),
+                                                      'return' => array('result' => PARAM_BOOL));
+    }
+
+    /**
+     * Retrieve all user
+     * @param string $search
+     * @return object user
+     */
+    static function tmp_get_users($search) {
+        $selectioncriteria = new stdClass();
+        $selectioncriteria->search = $search;
+        return user_api::tmp_get_users('firstname ASC', 999999, 0, 'id, auth, confirmed, username, idnumber, firstname, lastname, email, emailstop, lang, theme, timezone, mailformat', $selectioncriteria);
+    }
+
+    /**
+     * Create a user
+     * @param string $username
+     * @param string $firstname
+     * @param string $lastname
+     * @param string $email
+     * @param string $password
+     * @return integer id of new user
+     */
+    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);    
+    }
+
+    /**
+     * Delete a user
+     * @global object $DB
+     * @param string $username
+     * @param integer $mnethostid
+     * @return boolean true if success
+     */
+    static function tmp_delete_user($username, $mnethostid) {
+        global $DB;
+        $user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$mnethostid));
+    /// PLEASE UNCOMMENT HERE ONCE AUTHENTICATION IS IMPLEMENTED - $USER/context need to be set here
+        //if (require_capability('moodle/user:delete', get_context_instance(CONTEXT_SYSTEM))) {
+            return delete_user($user); //this function is in moodlelib.php
+        //}
+        //else {
+        //    throw new moodle_exception('couldnotdeleteuser');
+        //}
+    }
+
+    /**
+     * Update some user information
+     * @global object $DB
+     * @param string $username
+     * @param integer $mnethostid
+     * @param string $newusername
+     * @param string $firstname
+     * @return boolean true if success
+     */
+    static function tmp_update_user($username, $mnethostid, $newusername, $firstname) {
+        global $DB;
+        $user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$mnethostid));
+        $user->username = $newusername;
+        $user->firstname = $firstname;
+       
+        return user_api::tmp_update_user($user);
+    }
+
+}
+
+?>
index 661ffefe4f716fff3b4dac211ec435eb3d08da14..d5848133f4ce90da194278f2a0da38f5ea3661c6 100644 (file)
@@ -22,13 +22,11 @@ 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)
-    $classname .= 'ws_api';
+    $classname .= 'external';
 
-///these three next lines can be generic => create a function
-    require_once($CFG->dirroot.$apipath.'wsapi.php');
-    $api = new $classname();
-
-    $description = $api->get_function_webservice_description($functionname); //retrieve the web service description for this function
+    require_once($CFG->dirroot.$apipath.'external.php');
+    $wsapi = new $classname();
+    $description = $wsapi->get_function_webservice_description($functionname); //retrieve the web service description for this function
 
 ///This following line is only REST protocol
     $params = retrieve_params ($description); //retrieve the REST params
@@ -37,7 +35,6 @@ 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  ( $classname.'::'.$functionname, $params);
     
 ///Transform result into xml in order to send the REST response
@@ -54,9 +51,7 @@ function call_moodle_function ($rest_arguments) {
  * @return <type>
  */
 function retrieve_params ($description) {
-//    $params = $description['wsparams'];
     //retrieve REST param matching the description (warning: PHP assign the first instanciation as the first position in the table)
-
     foreach ($description['wsparams'] as $paramname => $paramtype) {
         $value = optional_param($paramname,null,$paramtype);
         if (!empty($value)) {
index 2667c8f93886c1bb3229be25f5ae90bf4e710459..e7427eb7f19f6afbfc31825949194b5bf0eee76f 100644 (file)
@@ -20,8 +20,8 @@ class wsdl_generator {
 
     function __construct () {
         // The exception list
-        // if ever there is some wsapi.php file that are not a web service class, they need to be declared here
-        // example: $this->exceptionlist['/home/jerome/Projects/Moodle_HEAD/moodle/mod/scorm/wsapi.php'] = true;
+        // if ever there is some external.php file that are not a web service class, they need to be declared here
+        // example: $this->exceptionlist['/home/jerome/Projects/Moodle_HEAD/moodle/mod/scorm/external.php'] = true;
         $this->exceptionlist = array();
     }
 
@@ -75,9 +75,9 @@ EOF;
 
          ///load the class        
             $classpath = substr($fileapipath,strlen($CFG->dirroot)+1); //remove the dir root + / from the file path
-            $classpath = substr($classpath,0,strlen($classpath) - 10); //remove /wsapi.php from the classpath
+            $classpath = substr($classpath,0,strlen($classpath) - 10); //remove /external.php from the classpath
             $classpath = str_replace('/','_',$classpath); //convert all / into _
-            $classname = $classpath."_ws_api";
+            $classname = $classpath."_external";
             $api = new $classname();
 
              $wsdlporttype .= <<<EOF
@@ -208,7 +208,7 @@ EOF;
                          $this->setListApiFiles($files, $path);
                     }
                  ///retrieve api.php file
-                    else if ($file == "wsapi.php" && ! $this->inExceptionList($path)) {
+                    else if ($file == "external.php" && ! $this->inExceptionList($path)) {
                         $files[] = $path;
                     }
                 }
@@ -223,7 +223,7 @@ EOF;
 
     /**
      * Hacky function
-     * We need to define if we remove all wsapi.php file from Moodle when they do not really
+     * We need to define if we remove all external.php file from Moodle when they do not really
      * are ws api file for Moodle ws API
      * @param string $path
      * @return boolean true if the path if in the exception list
index 916d80b9b94a287ff0ac33a42b88284c9fdb8f68..5849f620b2197b0fbdcbcc7c77be94dcd9711199 100644 (file)
 <?xml version ='1.0' encoding ='UTF-8' ?>
-        <definitions name='User'
-          targetNamespace='http://example.org/User'
-          xmlns:tns=' http://example.org/User '
-          xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
-          xmlns:xsd='http://www.w3.org/2001/XMLSchema'
-          xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
-          xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
-          xmlns='http://schemas.xmlsoap.org/wsdl/'>
-
-          <types>
-         <xsd:schema
-             targetNamespace="http://example.org/User"
-             xmlns="http://www.w3.org/2001/XMLSchema">
-             <xsd:complexType name="user">
-             </xsd:complexType>
-          </xsd:schema>
-       </types>
-
-
-        <message name='getusersRequest'>
-          <part name='search' type='xsd:string'/>
+    <definitions name='User'
+                 targetNamespace='http://example.org/User'
+                 xmlns:tns=' http://example.org/User '
+                 xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
+                 xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+                 xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
+                 xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
+                 xmlns='http://schemas.xmlsoap.org/wsdl/'>
+
+        <types>
+            <xsd:schema targetNamespace="http://example.org/User"
+                        xmlns="http://www.w3.org/2001/XMLSchema">
+                <xsd:complexType name="object">
+                </xsd:complexType>
+            </xsd:schema>
+        </types>
+
+        <message name="tmp_get_usersRequest">
+            <part name="search" type="xsd:string"/>
+        </message>
+        <message name="tmp_get_usersResponse">
+            <part name="user" type="xsd:object"/>
         </message>
-        <message name='getusersResponse'>
-          <part name='user' type='xsd:user'/>
+        <message name="tmp_create_userRequest">
+            <part name="username" type="xsd:string"/>
+            <part name="firstname" type="xsd:string"/>
+
+            <part name="lastname" type="xsd:string"/>
+            <part name="email" type="xsd:string"/>
+            <part name="password" type="xsd:string"/>
+        </message>
+        <message name="tmp_create_userResponse">
+            <part name="userid" type="xsd:string"/>
         </message>
-        <message name='createuserRequest'>
-          <part name='username' type='xsd:string'/>
-          <part name='firstname' type='xsd:string'/>
-          <part name='lastname' type='xsd:string'/>
-          <part name='email' type='xsd:string'/>
-          <part name='password' type='xsd:string'/>
+        <message name="tmp_namedparams_get_usersRequest">
+            <part name="search" type="xsd:string"/>
+
         </message>
-        <message name='createuserResponse'>
-          <part name='useris' type='xsd:string'/>
+        <message name="tmp_namedparams_get_usersResponse">
+            <part name="user" type="xsd:object"/>
         </message>
-        <message name='deleteuserRequest'>
-          <part name='username' type='xsd:string'/>
-          <part name='mnethostid' type='xsd:string'/>
+        <message name="tmp_delete_userRequest">
+            <part name="username" type="xsd:string"/>
+            <part name="mnethostid" type="xsd:integer"/>
         </message>
-        <message name='deleteuserResponse'>
-          <part name='result' type='xsd:integer'/>
+        <message name="tmp_delete_userResponse">
+
+            <part name="result" type="xsd:object"/>
         </message>
-        <message name='updateuserRequest'>
-          <part name='username' type='xsd:string'/>
-          <part name='mnethostid' type='xsd:string'/>
-          <part name='newusername' type='xsd:string'/>
-          <part name='firstname' type='xsd:string'/>
+        <message name="tmp_update_userRequest">
+            <part name="username" type="xsd:string"/>
+            <part name="mnethostid" type="xsd:integer"/>
+            <part name="newusername" type="xsd:string"/>
+            <part name="firstname" type="xsd:string"/>
         </message>
-        <message name='updateuserResponse'>
-          <part name='result' type='xsd:integer'/>
+        <message name="tmp_update_userResponse">
+
+            <part name="result" type="xsd:object"/>
         </message>
+        <portType name='userPortType'>
+            <operation name='tmp_get_users'>
+                <input message='tns:tmp_get_usersRequest'/>
+                <output message='tns:tmp_get_usersResponse'/>
+            </operation>
+
+            <operation name='tmp_create_user'>
+
+                <input message='tns:tmp_create_userRequest'/>
+                <output message='tns:tmp_create_userResponse'/>
+            </operation>
+
+            <operation name='tmp_namedparams_get_users'>
+                <input message='tns:tmp_namedparams_get_usersRequest'/>
+                <output message='tns:tmp_namedparams_get_usersResponse'/>
+            </operation>
+
+            <operation name='tmp_delete_user'>
 
-        <portType name='UserPortType'>
-          <operation name='tmp_get_users'>
-            <input message='tns:getusersRequest'/>
-            <output message='tns:getusersResponse'/>
-          </operation>
-          <operation name='tmp_create_user'>
-            <input message='tns:createuserRequest'/>
-            <output message='tns:createuserResponse'/>
-          </operation>
-          <operation name='tmp_delete_user'>
-            <input message='tns:deleteuserRequest'/>
-            <output message='tns:deleteuserResponse'/>
-          </operation>
-          <operation name='tmp_update_user'>
-            <input message='tns:updateuserRequest'/>
-            <output message='tns:updateuserResponse'/>
-          </operation>
+                <input message='tns:tmp_delete_userRequest'/>
+                <output message='tns:tmp_delete_userResponse'/>
+            </operation>
+
+            <operation name='tmp_update_user'>
+                <input message='tns:tmp_update_userRequest'/>
+                <output message='tns:tmp_update_userResponse'/>
+            </operation>
         </portType>
 
-        <binding name='UserBinding' type='tns:UserPortType'>
-          <soap:binding style='rpc'
-            transport='http://schemas.xmlsoap.org/soap/http'/>
-          <operation name='tmp_get_users'>
-            <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_get_users'/>
-            <input>
-              <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
-                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
-            </input>
-            <output>
-              <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
-                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
-            </output>
-          </operation>
-          <operation name='tmp_create_user'>
-            <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_create_user'/>
-            <input>
-              <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
-                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
-            </input>
-            <output>
-              <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
-                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
-            </output>
-          </operation>
-          <operation name='tmp_delete_user'>
-            <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_delete_user'/>
-            <input>
-              <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
-                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
-            </input>
-            <output>
-              <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
-                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
-            </output>
-          </operation>
-          <operation name='tmp_update_user'>
-            <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_update_user'/>
-            <input>
-              <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
-                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
-            </input>
-            <output>
-              <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
-                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
-            </output>
-          </operation>
+        <binding name='userBinding' type='tns:userPortType'>
+            <soap:binding style='rpc'
+                          transport='http://schemas.xmlsoap.org/soap/http'/>
+
+            <operation name='tmp_get_users'>
+                <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_get_users'/>
+                <input>
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </input>
+                <output>
+
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </output>
+           </operation>
+
+            <operation name='tmp_create_user'>
+                <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_create_user'/>
+                <input>
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </input>
+
+                <output>
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </output>
+           </operation>
+
+            <operation name='tmp_namedparams_get_users'>
+                <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_namedparams_get_users'/>
+                <input>
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+
+                </input>
+                <output>
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </output>
+           </operation>
+
+            <operation name='tmp_delete_user'>
+                <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_delete_user'/>
+                <input>
+
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </input>
+                <output>
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </output>
+           </operation>
+
+            <operation name='tmp_update_user'>
+                <soap:operation soapAction='urn:xmethods-delayed-quotes#tmp_update_user'/>
+
+                <input>
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </input>
+                <output>
+                    <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
+                               encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
+                </output>
+           </operation>
         </binding>
 
-        <service name='UserService'>
-          <port name='UserPort' binding='UserBinding'>
-            <soap:address location='http://jerome.moodle.com/Moodle_HEAD/moodle/webservice/soap/server.php?classpath=user'/>
-          </port>
+        <service name='userService'>
+                <port name='userPort' binding='userBinding'>
+                    <soap:address location='http://jerome.moodle.com/Moodle_HEAD/moodle/webservice/soap/server.php?classpath=user'/>
+                </port>
         </service>
-        </definitions>
\ No newline at end of file
+    </definitions>
index 278d3c1619f355bd449f62d1c6fc63704dfc5af7..703cca879a56bde51d4c3d61f8b352bf8e03e5b4 100644 (file)
@@ -18,11 +18,11 @@ if (empty($CFG->enablewebservices)) {
 
 //retrieve the api name
 $classpath = optional_param(classpath,null,PARAM_ALPHA);
-require_once(dirname(__FILE__) . '/../../'.$classpath.'/wsapi.php');
+require_once(dirname(__FILE__) . '/../../'.$classpath.'/external.php');
 
 /// run the server
 $server = new SoapServer("moodle.wsdl");
-$server->setClass($classpath."_ws_api");
+$server->setClass($classpath."_external");
 $server->handle();
 
 ?>
\ No newline at end of file