]> git.mjollnir.org Git - moodle.git/commitdiff
mnet: introducing get_my_remotecourses() and get_my_remotehosts() -- use them too
authormartinlanghoff <martinlanghoff>
Fri, 19 Jan 2007 08:57:13 +0000 (08:57 +0000)
committermartinlanghoff <martinlanghoff>
Fri, 19 Jan 2007 08:57:13 +0000 (08:57 +0000)
blocks/course_list/block_course_list.php
lib/datalib.php

index 3b71c692a81deaa0aa267b320afae595715167ed..3e9a2ba5db17b283e0ebbf42fde07adbb70abc44 100644 (file)
@@ -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').'<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;
     }
 
 }
index 76357f956ac8dc23c1a8e75c36cc1f76d74013bc..d5a3258d6e34f78be06b37be40b38fcbf2e0c53b 100644 (file)
@@ -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