2 ///////////////////////////////////////////////////////////////////////////
4 // This file is part of Moodle - http://moodle.org/ //
5 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // Moodle is free software: you can redistribute it and/or modify //
8 // it under the terms of the GNU General Public License as published by //
9 // the Free Software Foundation, either version 3 of the License, or //
10 // (at your option) any later version. //
12 // Moodle is distributed in the hope that it will be useful, //
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15 // GNU General Public License for more details. //
17 // You should have received a copy of the GNU General Public License //
18 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
20 ///////////////////////////////////////////////////////////////////////////
22 // TODO: this needs to be rewritten to use the new description format
23 // the problem here is that the list of functions is different for each use or even token
24 // I guess this should ne moved to server itself and it should require user auth
28 * This file generate a web service documentation in HTML
29 * This documentation describe how to call a Moodle Web Service
31 require_once('../config.php');
32 require_once('lib.php');
33 $protocol = optional_param('protocol',"soap",PARAM_ALPHA);
34 $username = optional_param('username',"",PARAM_ALPHA);
35 $password = optional_param('password',"",PARAM_ALPHA);
37 /// TODO Retrieve user (authentication)
41 $PAGE->set_course($COURSE);
42 $PAGE->set_url('webservice/wsdoc.php');
43 $PAGE->set_title(get_string('wspagetitle', 'webservice'));
44 $PAGE->set_heading(get_string('wspagetitle', 'webservice'));
45 $PAGE->set_generaltype("form");
47 // Display the documentation
48 echo $OUTPUT->header();
49 generate_documentation($protocol); //documentation relatif to the protocol
50 generate_functionlist($protocol, $user); //documentation relatif to the available function
51 echo $OUTPUT->footer();
54 function generate_functionlist($protocol, $user) {
56 /// retrieve all function that the user can access
58 /// retrieve all function that are available into enable services that
59 /// have (no restriction user or the user is into the restricted user list)
60 /// and (no required capability or the user has the required capability)
62 // do SQL request here
64 /// load once all externallib.php of the retrieved functions
66 /// foreach retrieved functions display the description
68 // in order to display the description we need to use an algo similar to the validation
69 // every time we get a scalar value, we need to convert it into a human readable value as
70 // PARAM_INT => 'integer' or PARAM_TEXT => 'string' or PARAM_BOOL => 'boolean' ...
76 * Generate documentation specific to a protocol
77 * @param string $protocol
79 function generate_documentation($protocol) {
83 $documentation = get_string('soapdocumentation','webservice');
86 $documentation = get_string('xmlrpcdocumentation','webservice');
92 echo "<strong style=\"color:orange\">".get_string('wsuserreminder','webservice')."</strong>";
98 * Convert a Moodle type (PARAM_ALPHA, PARAM_NUMBER,...) as a SOAP type (string, interger,...)
99 * @param integer $moodleparam
100 * @return string SOAP type
102 function converterMoodleParamIntoWsParam($moodleparam) {
103 switch ($moodleparam) {
122 case PARAM_ALPHANUMEXT: