Skip to content

Instantly share code, notes, and snippets.

@jleyva
Created July 23, 2014 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jleyva/3ccf5a8540b0e2609d29 to your computer and use it in GitHub Desktop.
Save jleyva/3ccf5a8540b0e2609d29 to your computer and use it in GitHub Desktop.
MDL-46459
<?php
// This file is NOT a part of Moodle - http://moodle.org/
//
// This client for Moodle 2 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
/// SETUP - NEED TO BE CHANGED
//
// Student token
$studenttoken = 'db0612aa7b726994f9e31df5637c7a39';
// Teacher Token.
$teachertoken = '298dee2e40eeac025a642e6231599917';
$domainname = 'http://localhost/moodlebugs';
//$domainname = 'http://localhost/m/stable_24';
$courseid = 2;
// Student id.
$userid = 3;
// the cmid
$activityid = 56;
// REST RETURNED VALUES FORMAT
$restformat = 'json'; //Also possible in Moodle 2.2 and later: 'json'
//Setting it to 'json' will fail all calls on earlier Moodle version
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
/// REST CALL
header('Content-Type: text/plain');
require_once('./curl.php');
$curl = new curl;
$functionname = 'core_grades_get_grades';
$params = array(
'courseid' => $courseid,
'component' => 'mod_assign',
'activityid' => $activityid,
'userids' => array($userid)
);
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $studenttoken . '&wsfunction='.$functionname;
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);
$resp = json_decode($resp);
echo "Current grade is: " . $resp->items[0]->grades[0]->grade;
echo "\n\n\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment