Skip to content

Instantly share code, notes, and snippets.

@nadavkav
Created May 17, 2017 14:56
Show Gist options
  • Save nadavkav/ea15b897367cb2e158dd9428a6d59721 to your computer and use it in GitHub Desktop.
Save nadavkav/ea15b897367cb2e158dd9428a6d59721 to your computer and use it in GitHub Desktop.
<?php
// This client for ws 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.
//
/// MOODLE ADMINISTRATION SETUP STEPS
// 2- Enable web service advance feature (Admin > Advanced features)
// 3- Enable REST protocol (Admin > Plugins > Web services > Manage protocols)
// 4- Create a token for a specific user and for the service 'My service' (Admin > Plugins > Web services > Manage tokens)
// 5- Run this script directly from your browser: you should see 'user grades'
// test: https://your-moodle-system/webservice/tests/client/client.php?action=get_grades
echo "Calling web service {$_GET['action']}...\n";
/// SETUP - NEED TO BE CHANGED
$token = '270660591c437ad224311f122252a2cf09252272bb23ada8';
$domainname = 'https://your-moodle-system';
//$domainname = '$CFG->wwwroot';
if (!empty($_GET['userids'])) {
$userids = array($_GET['userids']);
} else {
$userids = array('44');
}
if ($_GET['action']=='get_grades') {
$functionname = 'core_grades_get_grades';
$params = array('courseid' => '33', 'component'=>'mod_assign', 'activityid' => '123', 'userids' => $userids);
echo "core_grades_get_grades";
}
if ($_GET['action']=='set_grades') {
$functionname = 'core_grade_update_grades';
$params = array('courseid' => '33', 'component'=>'mod_assign', 'activityid' => '123', 'userids' => $userids);
echo "core_grade_update_grades";
}
///// REST CALL
header('Content-Type: text/plain');
$restformat = '&moodlewsrestformat=json';
echo "\n\n";
echo $serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname.$restformat;
echo "\n\n";
// get curl from: https://your-moodle-system/webservice/tests/client/curl.php
require_once('curl.php');
$curl = new custom_curl;
// use php or Moodle's curl
//$curl = new curl;
$resp = $curl->post($serverurl, $params);
//print_r($resp);
$decoded_jason = json_decode($resp);
print_r($decoded_jason);
//echo json_decode($resp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment