From db4b12eb70a7568703cefe7f1093f609828e04d4 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Fri, 19 Jan 2007 08:57:13 +0000 Subject: [PATCH] mnet: introducing get_my_remotecourses() and get_my_remotehosts() -- use them too --- blocks/course_list/block_course_list.php | 47 +++++++++++------------- lib/datalib.php | 40 ++++++++++++++++++++ 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/blocks/course_list/block_course_list.php b/blocks/course_list/block_course_list.php index 3b71c692a8..3e9a2ba5db 100644 --- a/blocks/course_list/block_course_list.php +++ b/blocks/course_list/block_course_list.php @@ -110,35 +110,30 @@ class block_course_list extends block_list { return false; } - if ($USER->mnethostid != $CFG->mnet_localhost_id) { - if (!empty($USER->mnet_foreign_host_array) && is_array($USER->mnet_foreign_host_array)) { - $this->content->items[] = get_string('remotemoodles','mnet'); - $this->content->icons[] = ''; - foreach($USER->mnet_foreign_host_array as $somehost) { - $this->content->items[] = $somehost['count'].get_string('courseson','mnet').''.$somehost['name'].''; - $this->content->icons[] = $icon; - } - } else { - return false; + if ($courses = get_my_remotecourses()) { + $this->content->items[] = get_string('remotecourses','mnet'); + $this->content->icons[] = ''; + foreach ($courses as $course) { + $this->content->items[]="shortname\" ". + "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname"; + $this->content->icons[]=$icon; } - } else { - $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[]="shortname\" ". - "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname"; - $this->content->icons[]=$icon; - } - } else { - return false; + // if we listed courses, we are done + return true; + } + + if ($hosts = get_my_remotehosts()) { + $this->content->items[] = get_string('remotemoodles','mnet'); + $this->content->icons[] = ''; + foreach($USER->mnet_foreign_host_array as $somehost) { + $this->content->items[] = $somehost['count'].get_string('courseson','mnet').''.$somehost['name'].''; + $this->content->icons[] = $icon; } + // if we listed hosts, done + return true; } - return true; + + return false; } } diff --git a/lib/datalib.php b/lib/datalib.php index 76357f956a..d5a3258d6e 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1002,6 +1002,46 @@ function fix_course_sortorder($categoryid=0, $n=0, $safe=0, $depth=0, $path='') return $n+1; } +/** + * List of remote courses that a user has access to via MNET. + * Works only on the IDP + * + * @uses $CFG, $USER + * @return array {@link $COURSE} of course objects + */ +function get_my_remotecourses($userid=0) { + global $CFG, $USER; + + if (empty($userid)) { + $userid = $USER->id; + } + + $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={$userid}"; + + return get_records_sql($sql); +} + +/** + * List of remote hosts that a user has access to via MNET. + * Works on the SP + * + * @uses $CFG, $USER + * @return array of host objects + */ +function get_my_remotehosts() { + global $CFG, $USER; + + if ($USER->mnethostid == $CFG->mnet_localhost_id) { + return false; // Return nothing on the IDP + } + if (!empty($USER->mnet_foreign_host_array) && is_array($USER->mnet_foreign_host_array)) { + return $USER->mnet_foreign_host_array; + } + return false; +} /** * This function creates a default separated/connected scale -- 2.39.5