//METHODS
THE CALL AND THE RESPONSE
/// method 1 REST CALL
header(‘Content-Type: text/plain’);
$serverurl = $domainname . ‘/webservice/rest/server.php’. ‘?wstoken=’ . $token . ‘&wsfunction=’.$functionname;
require_once(‘./curl.php’);
$curl = new curl;
//if rest format == ‘xml’, then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = ($restformat == ‘json’)?’&moodlewsrestformat=’ . $restformat:»;
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);
///method 2 XML-RPC CALL
/// XML-RPC CALL
header(‘Content-Type: text/plain’);
$serverurl = $domainname . ‘/webservice/xmlrpc/server.php’. ‘?wstoken=’ . $token;
require_once(‘./curl.php’);
$curl = new curl;
$post = xmlrpc_encode_request($functionname, array($params));
$resp = xmlrpc_decode($curl->post($serverurl, $post));
print_r($resp);
// Method SOAP
///another methods
//API REST , SLIM PHP framework +moodle
//API REST ,ZEND 2 PHP framework +moodle
THE RESPONSE
/* This parses a string containing the XML returned by
functions such as core_course_get_courses,
core_user_get_users_by_id, or core_enrol_get_enrolled_users.
These strings contain name-value pairs encoded thus:
<RESPONSE>
<MULTIPLE>
<SINGLE>
<KEY name="id"><VALUE>169</VALUE>
</KEY>
<KEY name="username"><VALUE>testusername32</VALUE>
</KEY>
</SINGLE>
</MULTIPLE>
</RESPONSE>
The function returns an object with the corresponding
keys and values.
Does not yet convert strings to integers where they
ought to be converted.
*/