Permalink
Browse files

mnet: introducing get_my_remotecourses() and get_my_remotehosts() -- …

…use them too
  • Loading branch information...
1 parent 0743661 commit db4b12eb70a7568703cefe7f1093f609828e04d4 martinlanghoff committed Jan 19, 2007
Showing with 61 additions and 26 deletions.
  1. +21 −26 blocks/course_list/block_course_list.php
  2. +40 −0 lib/datalib.php
@@ -110,35 +110,30 @@ function get_remote_courses() {
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}&amp;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}&amp;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;
}
}
View
@@ -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

0 comments on commit db4b12e

Please sign in to comment.