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').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$somehost['name'].'</a>';
- $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[]="<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 {
- $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;
+ // 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').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$somehost['name'].'</a>';
+ $this->content->icons[] = $icon;
}
+ // if we listed hosts, done
+ return true;
}
- return true;
+
+ return false;
}
}
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