Skip to content

Instantly share code, notes, and snippets.

@jleyva
Created April 30, 2012 15:11
Show Gist options
  • Save jleyva/2559110 to your computer and use it in GitHub Desktop.
Save jleyva/2559110 to your computer and use it in GitHub Desktop.
Groupings test
<?php
// This client for local_illl 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.
//
/**
* XMLRPC client for Moodle 2 - local_illl
*
* This script does not depend of any Moodle code,
* and it can be called from a browser.
*
* @author Jerome Mouneyrac, Juan Leyva
*/
ini_set('display_errors', 'On');
error_reporting(E_ALL);
ini_set('max_execution_time', 0);
/// SETUP - NEED TO BE CHANGED
$domainname = 'http://localhost/moodle22/';
$wsusername = 'wsusername';
$wspassword = 'wspassword';
// CHANGE THIS
$courseid = 24;
$group = array(7,8);
// Extra Get params for some functions
$ids = array_fill(0, 50, 0);
if (!empty($_GET['ids'])) {
$ids = explode(',', $_GET['ids']);
}
$callers = array(
'create_groupings' => array(array(array(
'courseid' => $courseid,
'name' => 'My grouping 1'.rand(),
'description' => '<b>Description</b>'
),
array(
'courseid' => $courseid,
'name' => 'My second grouping'.rand(),
'description' => '<h2></h2><p><b>HTML description</b></p>'
))),
'update_groupings' => array(array(array(
'id' => $ids[0],
'name' => 'My grouping 1 (updated)'.rand(),
'description' => '<b>Description</b>'
),
array(
'id' => $ids[1],
'name' => 'My second grouping (updated)'.rand(),
'description' => '<h2></h2><p><b>HTML description</b></p>'
))),
'get_groupings' => array($ids),
'get_course_groupings' => array($courseid),
'assign_grouping' => array(array(array(
'groupingid' => $ids[0],
'groupid' => $group[0]
),
array(
'groupingid' => $ids[1],
'groupid' => $group[1]
))),
'unassign_grouping' => array(array(array(
'groupingid' => $ids[0],
'groupid' => $group[0]
),
array(
'groupingid' => $ids[1],
'groupid' => $group[1]
))),
'delete_groupings' => array($ids),
);
//header('Content-Type: text/plain');
if (!empty($callers[$_GET['method']])) {
///// XML-RPC CALL
$serverurl = $domainname . '/webservice/xmlrpc/simpleserver.php'. '?wsusername=' . $wsusername . '&wspassword=' . $wspassword;
require_once('./curl.php');
echo "Calling ".$_GET['method'];
print_r($callers[$_GET['method']]);
$curl = new curl;
$post = xmlrpc_encode_request('local_illl_'.$_GET['method'], $callers[$_GET['method']]);
$resp = $curl->post($serverurl, $post);
echo "<br>\n<br>\n<h2>Plain HTTP response</h2><br>\n";
echo htmlentities(var_export($resp, true));
$resp = xmlrpc_decode($resp);
echo "<br>\n<br>\n<h2>XML response</h2><br>\n";
echo htmlentities(var_export($resp, true));
if (is_array($resp) and !isset($resp['faultCode'])) {
$ids = array();
foreach ($resp as $grouping) {
$ids[] = $grouping['id'];
}
}
if (is_array($ids)) {
$ids = implode(',', $ids);
}
echo "End client";
}
foreach ($callers as $method => $params) {
echo "<p><a href='client_groupings.php?method=$method&ids=$ids'>$method</a></p>\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment