mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MNET: MyCourses block enriched with links to remote Moodles when roaming
This commit is contained in:
parent
43f853c908
commit
4d8c087e02
@ -75,8 +75,7 @@ class auth_plugin_mnet
|
|||||||
* @return array $userdata Array of user info for remote host
|
* @return array $userdata Array of user info for remote host
|
||||||
*/
|
*/
|
||||||
function user_authorise($token, $useragent) {
|
function user_authorise($token, $useragent) {
|
||||||
global $CFG;
|
global $CFG, $MNET, $SITE, $MNET_REMOTE_CLIENT;
|
||||||
global $MNET;
|
|
||||||
require_once $CFG->dirroot . '/mnet/xmlrpc/server.php';
|
require_once $CFG->dirroot . '/mnet/xmlrpc/server.php';
|
||||||
|
|
||||||
$mnet_session = get_record('mnet_session', 'token', $token, 'useragent', $useragent);
|
$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['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;
|
return $userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +239,7 @@ class auth_plugin_mnet
|
|||||||
* @returns array The local user record.
|
* @returns array The local user record.
|
||||||
*/
|
*/
|
||||||
function confirm_mnet_session($token, $remotewwwroot) {
|
function confirm_mnet_session($token, $remotewwwroot) {
|
||||||
global $CFG, $MNET;
|
global $CFG, $MNET, $SESSION;
|
||||||
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
|
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
|
||||||
|
|
||||||
// verify the remote host is configured locally before attempting RPC call
|
// 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;
|
$localuser->{$key} = $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,23 +99,35 @@ class block_course_list extends block_list {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_remote_courses() {
|
function get_remote_courses() {
|
||||||
global $THEME, $CFG, $USER;
|
global $THEME, $CFG, $USER, $SESSION;
|
||||||
$sql = "SELECT c.remoteid, c.shortname, c.fullname, c.hostid
|
$icon = '<img src="'.$CFG->pixpath.'/i/mnethost.png" class="icon" alt="'.get_string('course').'" />';
|
||||||
FROM {$CFG->prefix}mnet_enrol_course c
|
if ($USER->mnethostid != $CFG->mnet_localhost_id) {
|
||||||
JOIN {$CFG->prefix}mnet_enrol_assignments a ON c.id=a.courseid
|
if (!empty($SESSION->mnet_foreign_host_array) && is_array($SESSION->mnet_foreign_host_array)) {
|
||||||
WHERE a.userid={$USER->id}";
|
$this->content->items[] = get_string('remotemoodles','mnet');
|
||||||
if ($courses = get_records_sql($sql)) {
|
$this->content->icons[] = '';
|
||||||
$icon = "<img src=\"$CFG->pixpath/i/mnethost.png\"".
|
foreach($SESSION->mnet_foreign_host_array as $somehost) {
|
||||||
" class=\"icon\" alt=\"".get_string("course")."\" />";
|
$this->content->items[] = $somehost['count'].get_string('courseson','mnet').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$somehost['name'].'</a>';
|
||||||
$this->content->items[] = 'Remote Courses';
|
$this->content->icons[] = $icon;
|
||||||
$this->content->icons[] = '';
|
}
|
||||||
foreach ($courses as $course) {
|
} else {
|
||||||
$this->content->items[]="<a title=\"$course->shortname\" ".
|
return false;
|
||||||
"href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname</a>";
|
|
||||||
$this->content->icons[]=$icon;
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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}&wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname</a>";
|
||||||
|
$this->content->icons[]=$icon;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,9 @@ $string['RPC_HTTP_VERIFIED'] = 'HTTP (signed)';
|
|||||||
$string['RPC_HTTP_SELF_SIGNED'] = 'HTTP (self-signed)';
|
$string['RPC_HTTP_SELF_SIGNED'] = 'HTTP (self-signed)';
|
||||||
$string['RPC_HTTP_PLAINTEXT'] = 'HTTP unencrypted';
|
$string['RPC_HTTP_PLAINTEXT'] = 'HTTP unencrypted';
|
||||||
$string['remotehosts'] = 'Remote hosts';
|
$string['remotehosts'] = 'Remote hosts';
|
||||||
|
$string['remotemoodles'] = 'Remote Moodles';
|
||||||
|
$string['remotecourses'] = 'Remote Courses';
|
||||||
|
$string['courseson'] = ' courses on ';
|
||||||
$string['permittedtransports'] = 'Permitted transports';
|
$string['permittedtransports'] = 'Permitted transports';
|
||||||
$string['current_transport'] = 'Current transport';
|
$string['current_transport'] = 'Current transport';
|
||||||
$string['system'] = 'System';
|
$string['system'] = 'System';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user