SOAP Manual
1. Call the method tmp_get_token on "http://remotemoodle/webservice/soap/zend_soap_server.php?wsdl"
Function parameter is an array: in PHP it would be array('username' => "wsuser", 'password' => "wspassword")
Return value is a token (integer)
2. Then call a moodle web service method on "http://remotemoodle/webservice/soap/zend_soap_server.php?token=the_received_token&classpath=the_moodle_path&wsdl"
Every method has only one parameter which is an array.
For example in PHP for this specific function:
Moodle path: user
tmp_delete_user( string username, integer mnethostid, )
You will call something like:
your_client->tmp_delete_user(array('username' => "username_to_delete",'mnethostid' => 1))
EOF;
break;
case "xmlrpc":
$documentation = <<XMLRPC Manual
1. Call the method authentication.tmp_get_token on "http://remotemoodle/webservice/xmlrpc/zend_xmlrpc_server.php"
Function parameter is an array: in PHP it would be array('username' => "wsuser", 'password' => "wspassword")
Return value is a token (integer)
2. Then call a moodle web service method on "http://remotemoodle/webservice/xmlrpc/zend_xmlrpc_server.php?classpath=the_moodle_path&token=the_received_token"
Every method has only one parameter which is an array.
For example in PHP for this specific function:
Moodle path: user
tmp_delete_user( string username, integer mnethostid, )
You will call something like:
your_client->call('user.tmp_delete_user', array(array('username' => "username_to_delete",'mnethostid' => 1)))
EOF;
break;
default:
break;
}
echo $documentation;
}
function generate_functionlist () {
global $CFG;
$documentation = <<list of web services functions
EOF;
//retrieve all external file
$externalfiles = array();
$externalfunctions = array();
setListApiFiles($externalfiles, $CFG->dirroot);
foreach ($externalfiles as $file) {
require($file);
$classpath = substr($file,strlen($CFG->dirroot)+1); //remove the dir root + / from the file path
$classpath = substr($classpath,0,strlen($classpath) - 13); //remove /external.php from the classpath
$classpath = str_replace('/','_',$classpath); //convert all / into _
$classname = $classpath."_external";
$api = new $classname();
$documentation .= <<Moodle path: {$classpath}
EOF;
foreach($api->get_descriptions() as $functionname => $description) {
$documentation .= <<{$functionname}(
EOF;
foreach ($description['params'] as $param => $paramtype) {
$wsparamtype = converterMoodleParamIntoWsParam($paramtype);
$documentation .= <<
EOF;
foreach ($description['optionalparams'] as $param => $paramtype) {
$wsparamtype = converterMoodleParamIntoWsParam($paramtype);
$documentation .= <<
EOF;
$documentation .= <<
EOF;
}
}
echo $documentation;
}
/**
* Convert a Moodle type (PARAM_ALPHA, PARAM_NUMBER,...) as a SOAP type (string, interger,...)
* @param integer $moodleparam
* @return string SOAP type
*/
function converterMoodleParamIntoWsParam($moodleparam) {
switch ($moodleparam) {
case PARAM_NUMBER:
return "integer";
break;
case PARAM_INT:
return "integer";
break;
case PARAM_BOOL:
return "boolean";
break;
case PARAM_ALPHANUM:
return "string";
break;
case PARAM_RAW:
return "string";
break;
default:
return "object";
break;
}
}
/**
* Retrieve all external.php from Moodle
* @param $
* @param $directorypath
* @return boolean true if n
*/
function setListApiFiles( &$files, $directorypath )
{
if(is_dir($directorypath)){ //check that we are browsing a folder not a file
if( $dh = opendir($directorypath))
{
while( false !== ($file = readdir($dh)))
{
if( $file == '.' || $file == '..') { // Skip '.' and '..'
continue;
}
$path = $directorypath . '/' . $file;
///browse the subfolder
if( is_dir($path) ) {
setListApiFiles($files, $path);
}
///retrieve api.php file
else if ($file == "external.php") {
$files[] = $path;
}
}
closedir($dh);
}
}
}
?>