I need to export grades from my moodle to another website, i sought online that you need to create a web service on moodle(i already did it) and now i need an web page with php code to consume my web service, i searched online for some examples (i'm new to web development), and find someone here talking about it, can someone explain me how this code work, how can i use to export my grades to my other website.
the code:
<?php
$token = 'meutoken';
$domainname = 'http://meumoodle';
$functionname = 'core_user_get_users';
$restformat = 'json'; //Also possible in Moodle 2.2 and later: 'json'
//Setting it to 'json' will fail all calls on earlier Moodle version
//////// moodle_user_create_users ////////
/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION
$user1 = new stdClass();
$user1->key = 'username';
$user1->value = 'myvalue';
$users = array($user1);
$params = array('criteria' => $users);
$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->get($serverurl . $restformat, $params);
$json = json_encode($resp);
$obj = json_decode($resp);
?>
CodePudding user response:
You can also export grades manually as a one off, or export grades via a URL without any development.
To export grades from a course, go to a course, then the course admin menu, then the gradebook, then export
To export via a URL see https://docs.moodle.org/400/en/Grade_export#Grade_publishing