MNET: MyCourses block enriched with links to remote Moodles when roaming

This commit is contained in:
donal72 2007-01-16 05:00:18 +00:00
parent 43f853c908
commit 4d8c087e02
3 changed files with 76 additions and 18 deletions

View File

@ -75,8 +75,7 @@ class auth_plugin_mnet
* @return array $userdata Array of user info for remote host
*/
function user_authorise($token, $useragent) {
global $CFG;
global $MNET;
global $CFG, $MNET, $SITE, $MNET_REMOTE_CLIENT;
require_once $CFG->dirroot . '/mnet/xmlrpc/server.php';
$mnet_session = get_record('mnet_session', 'token', $token, 'useragent', $useragent);
@ -123,6 +122,37 @@ class auth_plugin_mnet
$userdata['imagehash'] = sha1(file_get_contents($imagefile));
}
}
$userdata['myhosts'] = array();
if($courses = get_my_courses($user->id, 'id', 'id, visible')) {
$userdata['myhosts'][] = array('name'=> $SITE->shortname, 'url' => $CFG->wwwroot, 'count' => count($courses));
}
$sql = "
SELECT
h.name as hostname,
h.wwwroot,
h.id as hostid,
count(c.id) as count
FROM
{$CFG->prefix}mnet_enrol_course c,
{$CFG->prefix}mnet_enrol_assignments a,
{$CFG->prefix}mnet_host h
WHERE
c.id = a.courseid AND
c.hostid = h.id AND
a.userid = '{$user->id}' AND
c.hostid != '{$MNET_REMOTE_CLIENT->id}'
GROUP BY
h.name,
h.id,
h.wwwroot";
if ($courses = get_records_sql($sql)) {
foreach($courses as $course) {
$userdata['myhosts'][] = array('name'=> $course->hostname, 'url' => $CFG->wwwroot.'/auth/mnet/jump.php?hostid='.$course->hostid, 'count' => $course->count);
}
}
return $userdata;
}
@ -209,7 +239,7 @@ class auth_plugin_mnet
* @returns array The local user record.
*/
function confirm_mnet_session($token, $remotewwwroot) {
global $CFG, $MNET;
global $CFG, $MNET, $SESSION;
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
// verify the remote host is configured locally before attempting RPC call
@ -312,6 +342,19 @@ class auth_plugin_mnet
}
}
if($key == 'myhosts') {
$SESSION->mnet_foreign_host_array = array();
foreach($val as $somecourse) {
$name = clean_param($somecourse['name'], PARAM_ALPHANUM);
$url = clean_param($somecourse['url'], PARAM_URL);
$count = clean_param($somecourse['count'], PARAM_INT);
$url_is_local = stristr($url , $CFG->wwwroot);
if (!empty($name) && !empty($count) && empty($url_is_local)) {
$SESSION->mnet_foreign_host_array[] = array('name' => $name, 'url' => $url, 'count' => $count);
}
}
}
$localuser->{$key} = $val;
}

View File

@ -99,23 +99,35 @@ class block_course_list extends block_list {
}
function get_remote_courses() {
global $THEME, $CFG, $USER;
$sql = "SELECT c.remoteid, c.shortname, c.fullname, c.hostid
FROM {$CFG->prefix}mnet_enrol_course c
JOIN {$CFG->prefix}mnet_enrol_assignments a ON c.id=a.courseid
WHERE a.userid={$USER->id}";
if ($courses = get_records_sql($sql)) {
$icon = "<img src=\"$CFG->pixpath/i/mnethost.png\"".
" class=\"icon\" alt=\"".get_string("course")."\" />";
$this->content->items[] = 'Remote Courses';
$this->content->icons[] = '';
foreach ($courses as $course) {
$this->content->items[]="<a title=\"$course->shortname\" ".
"href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname</a>";
$this->content->icons[]=$icon;
global $THEME, $CFG, $USER, $SESSION;
$icon = '<img src="'.$CFG->pixpath.'/i/mnethost.png" class="icon" alt="'.get_string('course').'" />';
if ($USER->mnethostid != $CFG->mnet_localhost_id) {
if (!empty($SESSION->mnet_foreign_host_array) && is_array($SESSION->mnet_foreign_host_array)) {
$this->content->items[] = get_string('remotemoodles','mnet');
$this->content->icons[] = '';
foreach($SESSION->mnet_foreign_host_array as $somehost) {
$this->content->items[] = $somehost['count'].get_string('courseson','mnet').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$somehost['name'].'</a>';
$this->content->icons[] = $icon;
}
} else {
return false;
}
} else {
return false;
$sql = "SELECT c.remoteid, c.shortname, c.fullname, c.hostid
FROM {$CFG->prefix}mnet_enrol_course c
JOIN {$CFG->prefix}mnet_enrol_assignments a ON c.id=a.courseid
WHERE a.userid={$USER->id}";
if ($courses = get_records_sql($sql)) {
$this->content->items[] = get_string('remotecourses','mnet');
$this->content->icons[] = '';
foreach ($courses as $course) {
$this->content->items[]="<a title=\"$course->shortname\" ".
"href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname</a>";
$this->content->icons[]=$icon;
}
} else {
return false;
}
}
return true;
}

View File

@ -116,6 +116,9 @@ $string['RPC_HTTP_VERIFIED'] = 'HTTP (signed)';
$string['RPC_HTTP_SELF_SIGNED'] = 'HTTP (self-signed)';
$string['RPC_HTTP_PLAINTEXT'] = 'HTTP unencrypted';
$string['remotehosts'] = 'Remote hosts';
$string['remotemoodles'] = 'Remote Moodles';
$string['remotecourses'] = 'Remote Courses';
$string['courseson'] = ' courses on ';
$string['permittedtransports'] = 'Permitted transports';
$string['current_transport'] = 'Current transport';
$string['system'] = 'System';