Skip to content

Instantly share code, notes, and snippets.

@jleyva
Created May 7, 2014 11:44
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/c83f2d042bdd744815bf to your computer and use it in GitHub Desktop.
Save jleyva/c83f2d042bdd744815bf to your computer and use it in GitHub Desktop.
get_messages.php
<?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 = '493d2e785f81515296cf09e05f1f8179';
$domainname = 'http://localhost/moodlebugs';
$functionname = 'core_message_get_messages';
// 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(
'useridto' => 0,
'useridfrom' => 3, // It can be also -10 or -20 (norepply and supportusers)
'type' => 'both', // It can be both, conversations or notifications.
'read' => 0, // 1 or 0 for true or false
'newestfirst' => 1, // 1 or 0 for true or false
'limitfrom' => 0,
'limitnum' => 0,
);
/// 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