Skip to content

Instantly share code, notes, and snippets.

@jleyva
Last active August 29, 2015 13:57
Show Gist options
  • Save jleyva/9347596 to your computer and use it in GitHub Desktop.
Save jleyva/9347596 to your computer and use it in GitHub Desktop.
Test client for forum_get_posts MDL-30106
<?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.
//
/**
* REST client for Moodle 2
* Return JSON or XML format
*
* @author Jerome Mouneyrac
*/
/// SETUP - NEED TO BE CHANGED
$token = '200283ba9395030324317216862ae274';
//$token = '1bf9fbe8f592e895ba7dc27de75a1a73';
$domainname = 'http://localhost/moodlebugs';
//$domainname = 'http://localhost/m/stable_24';
$functionname = 'mod_forum_get_forum_discussion_posts';
// 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
$params = array('discussionid' => 6, 'sortby' => 'id', 'sortdirection' => 'ASC');
/// 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment