Skip to content

Commit

Permalink
MDL-22787 Various fixes of MNet remote enrolment service client
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Jul 17, 2010
1 parent c07e728 commit de5a205
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 10 deletions.
22 changes: 20 additions & 2 deletions mnet/service/enrol/host.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
/**
* Displays a list of remote courses offered by a given host for our students
*
* By default the courses information is cached in our local DB table. Parameter
* $usecache can be used to force re-fetching up to date state from remote
* hosts (session key required in such case).
*
* @package mnetservice
* @subpackage enrol
* @copyright 2010 David Mudrak <[email protected]>
Expand All @@ -28,7 +32,7 @@
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');

$hostid = required_param('id', PARAM_INT); // remote host id
$hostid = required_param('id', PARAM_INT); // remote host id
$usecache = optional_param('usecache', true, PARAM_BOOL); // use cached list of courses

admin_externalpage_setup('mnetenrol');
Expand All @@ -48,6 +52,10 @@
}
$host = $hosts[$hostid];

if (!$usecache) {
// our local database will be changed
require_sesskey();
}
$courses = $service->get_remote_courses($host->id, $usecache);
if (is_string($courses)) {
print_error('fetchingcourses', 'mnetservice_enrol', '', null, $service->format_error_message($courses));
Expand All @@ -58,6 +66,9 @@
if (empty($courses)) {
$a = (object)array('hostname' => s($host->hostname), 'hosturl' => s($host->hosturl));
echo $OUTPUT->box(get_string('availablecoursesonnone','mnetservice_enrol', $a), 'noticebox');
echo $OUTPUT->single_button(new moodle_url(new moodle_url('/mnet/service/enrol/host.php'),
array('id'=>$host->id, 'usecache'=>0, 'sesskey'=>sesskey())),
get_string('refetch', 'mnetservice_enrol'), 'get');
echo $OUTPUT->footer();
die();
}
Expand All @@ -84,7 +95,8 @@
$table->data[] = $row;
$prevcat = $course->categoryid;
}
$editbtn = $OUTPUT->single_button(new moodle_url('/mnet/service/enrol/course.php', array('host'=>$host->id, 'course'=>$course->remoteid)),
$editbtn = $OUTPUT->single_button(new moodle_url('/mnet/service/enrol/course.php',
array('host'=>$host->id, 'course'=>$course->id, 'sesskey'=>sesskey())),
get_string('editenrolments', 'mnetservice_enrol'), 'get');
$row = new html_table_row();
$row->cells = array(
Expand All @@ -97,4 +109,10 @@
}
echo html_writer::table($table);

if ($usecache) {
echo $OUTPUT->single_button(new moodle_url(new moodle_url('/mnet/service/enrol/host.php'),
array('id'=>$host->id, 'usecache'=>0, 'sesskey'=>sesskey())),
get_string('refetch', 'mnetservice_enrol'), 'get');
}

echo $OUTPUT->footer();
6 changes: 3 additions & 3 deletions mnet/service/enrol/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
);
foreach ($hosts as $host) {
$hostlink = html_writer::link(new moodle_url($host->hosturl), s($host->hosturl));
$editlink = html_writer::link(new moodle_url('/mnet/service/enrol/host.php', array('id'=>$host->id)),
get_string('editenrolments', 'mnetservice_enrol'));
$table->data[] = array(s($host->appname), s($host->hostname), $hostlink, $editlink);
$editbtn = $OUTPUT->single_button(new moodle_url('/mnet/service/enrol/host.php', array('id'=>$host->id)),
get_string('editenrolments', 'mnetservice_enrol'), 'get');
$table->data[] = array(s($host->appname), s($host->hostname), $hostlink, $editbtn);
}
echo html_writer::table($table);

Expand Down
1 change: 1 addition & 0 deletions mnet/service/enrol/lang/en/mnetservice_enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
$string['hosturl'] = 'Remote host URL';
$string['nopublishers'] = 'No remote peers available.';
$string['pluginname'] = 'Remote enrolment service';
$string['refetch'] = 'Re-fetch up to date state from remote hosts';
51 changes: 48 additions & 3 deletions mnet/service/enrol/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ public function get_remote_courses($mnethostid, $usecache=true) {

// do not use cache - fetch fresh list from remote MNet host
$peer = new mnet_peer();
$peer->set_id($mnethostid);
if (!$peer->set_id($mnethostid)) {
return serialize(array('unknown mnet peer'));
}

$request = new mnet_xmlrpc_client();
$request->set_method('enrol/mnet/enrol.php/available_courses');
Expand All @@ -187,10 +189,10 @@ public function get_remote_courses($mnethostid, $usecache=true) {
$course->shortname = substr($remote['shortname'], 0, 100);
$course->idnumber = substr($remote['idnumber'], 0, 100);
$course->summary = $remote['summary'];
$course->summaryformat = (int)$remote['summaryformat'];
$course->summaryformat = empty($remote['summaryformat']) ? FORMAT_MOODLE : (int)$remote['summaryformat'];
$course->startdate = (int)$remote['startdate'];
$course->roleid = (int)$remote['defaultroleid'];
$course->rolename = substr($remote['name'], 0, 255);
$course->rolename = substr($remote['defaultrolename'], 0, 255);
// We do not cache the following fields returned from peer in 2.0 any more
// not cached: cat_description
// not cached: cat_descriptionformat
Expand Down Expand Up @@ -232,6 +234,49 @@ public function get_remote_courses($mnethostid, $usecache=true) {
}
}

/**
* Returns the information about enrolments of our users in remote courses
*
* The remote course must allow enrolments via our Remote enrolment service client.
* Because of legacy design of data structure returned by XML-RPC code, only one
* user enrolment per course is returned by 1.9 MNet servers. This may be an issue
* if the user is enrolled multiple times by various enrolment plugins. MNet 2.0
* servers do not use user name as array keys - they do not need to due to side
* effect of MDL-19219.
*
* @param id $mnethostid MNet remote host id
* @param int $remotecourseid ID of the course at the remote host
* @param bool $usecache use cached data or invoke new XML-RPC?
* @uses mnet_xmlrpc_client Invokes XML-RPC request if the cache is not used
* @return array|string returned list or serialized array of mnet error messages
*/
public function get_remote_course_enrolments($mnethostid, $remotecourseid) {
global $CFG, $DB;
require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';

$peer = new mnet_peer();
if (!$peer->set_id($mnethostid)) {
return serialize(array('unknown mnet peer'));
}

if (!$DB->record_exists('mnetservice_enrol_courses', array('hostid'=>$mnethostid, 'remoteid'=>$remotecourseid))) {
return serialize(array('course not available for remote enrolments'));
}

$request = new mnet_xmlrpc_client();
$request->set_method('enrol/mnet/enrol.php/course_enrolments');
$request->add_param($remotecourseid, 'int');

if ($request->send($peer)) {
$list = array();
$response = $request->response;
return $response;

} else {
return serialize($request->error);
}
}

/**
* Prepares error messages returned by our XML-RPC requests to be send as debug info to {@link print_error()}
*
Expand Down
18 changes: 16 additions & 2 deletions mnet/service/enrol/styles.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
.singlebutton {
text-align: center;
}
table.remotehosts,
table.remotecourses {
margin: 0px auto;
margin: 0px auto 1em auto;
}

table.remotecourses th.categoryname {
text-align: left;
background-color: #f6f6f6;
Expand All @@ -13,3 +15,15 @@ table.remotecourses td.c1 {
table.remotecourses th.categoryname img {
margin-right: 1em;
}
.collapsibleregioncaption {
font-size: 110%;
font-weight: bold;
text-align: center;
}
.collapsibleregioninner {
border: 1px solid #ddd;
padding: 1em;
}
.collapsibleregion.remotecourse.summary {
margin: 0px 10em;
}

0 comments on commit de5a205

Please sign in to comment.