]> git.mjollnir.org Git - moodle.git/commitdiff
MNET: MyCourses block enriched with links to remote Moodles when roaming
authordonal72 <donal72>
Tue, 16 Jan 2007 05:00:18 +0000 (05:00 +0000)
committerdonal72 <donal72>
Tue, 16 Jan 2007 05:00:18 +0000 (05:00 +0000)
auth/mnet/auth.php
blocks/course_list/block_course_list.php
lang/en_utf8/mnet.php

index ba3fbb0c3fbc815f650a49065ef26f13599bde30..b02c74e2b71c24b983f451f74af06bc83d6876d5 100644 (file)
@@ -75,8 +75,7 @@ class auth_plugin_mnet
      * @return array  $userdata Array of user info for remote host
      */
     function user_authorise($token, $useragent) {
-        global $CFG;
-        global $MNET;
+        global $CFG, $MNET, $SITE, $MNET_REMOTE_CLIENT;
         require_once $CFG->dirroot . '/mnet/xmlrpc/server.php';
 
         $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['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;
     }
 
@@ -209,7 +239,7 @@ class auth_plugin_mnet
      *   @returns array The local user record.
      */
     function confirm_mnet_session($token, $remotewwwroot) {
-        global $CFG, $MNET;
+        global $CFG, $MNET, $SESSION;
         require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
 
         // 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;
         }
 
index 0a59406469cc487a9a7f505376919bd3d4cf8f82..ce08b2655ab438cae6fec91eba595a1d0a4035ad 100644 (file)
@@ -99,23 +99,35 @@ class block_course_list extends block_list {
     }
 
     function get_remote_courses() {
-        global $THEME, $CFG, $USER;
-        $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)) {
-            $icon  = "<img src=\"$CFG->pixpath/i/mnethost.png\"".
-                " class=\"icon\" alt=\"".get_string("course")."\" />";
-            $this->content->items[] = 'Remote Courses';
-            $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;
+        global $THEME, $CFG, $USER, $SESSION;
+        $icon  = '<img src="'.$CFG->pixpath.'/i/mnethost.png" class="icon" alt="'.get_string('course').'" />';
+        if ($USER->mnethostid != $CFG->mnet_localhost_id) {
+            if (!empty($SESSION->mnet_foreign_host_array) && is_array($SESSION->mnet_foreign_host_array)) {
+                $this->content->items[] = get_string('remotemoodles','mnet'); 
+                $this->content->icons[] = '';
+                foreach($SESSION->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;
             }
         } 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}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname</a>";
+                    $this->content->icons[]=$icon;
+                }
+            } else {
+                return false;
+            }
         }
         return true;
     }
index 676394c93d6c23c6a66574a712e212b13f720bc0..18183e0d9966e71a9f75390ab9fba6ae594e1be8 100644 (file)
@@ -116,6 +116,9 @@ $string['RPC_HTTP_VERIFIED']            = 'HTTP (signed)';
 $string['RPC_HTTP_SELF_SIGNED']         = 'HTTP (self-signed)';
 $string['RPC_HTTP_PLAINTEXT']           = 'HTTP unencrypted';
 $string['remotehosts']                  = 'Remote hosts';
+$string['remotemoodles']                = 'Remote Moodles';
+$string['remotecourses']                = 'Remote Courses';
+$string['courseson']                    = ' courses on ';
 $string['permittedtransports']          = 'Permitted transports';
 $string['current_transport']            = 'Current transport';
 $string['system']                       = 'System';