From 45e87759112cb777e3cca151500fad3021485c98 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Tue, 16 Nov 2010 13:40:34 +0000 Subject: [PATCH] MDL-13379 mnet: course overview at my home page displays remote courses, too The patch submitted by Hubert Chathi. I just changed it a bit to use moodle_url instead of string URLs and to use s() instead of format_string() when putting the course fullname into title="" attribute value. --- .../course_overview/block_course_overview.php | 21 ++++++++++++---- course/lib.php | 24 +++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/blocks/course_overview/block_course_overview.php b/blocks/course_overview/block_course_overview.php index 8ece30c1957d3..1de41bcb15777 100644 --- a/blocks/course_overview/block_course_overview.php +++ b/blocks/course_overview/block_course_overview.php @@ -68,9 +68,20 @@ public function get_content() { $site = get_site(); $course = $site; //just in case we need the old global $course hack - if (($courses_limit > 0) && (count($courses) >= $courses_limit)) { - //remove the 'marker' course that we retrieve just to see if we have more than $courses_limit - array_pop($courses); + if (is_enabled_auth('mnet')) { + $remote_courses = get_my_remotecourses(); + } + if (empty($remote_courses)) { + $remote_courses = array(); + } + + if (($courses_limit > 0) && (count($courses)+count($remote_courses) >= $courses_limit)) { + // get rid of any remote courses that are above the limit + $remote_courses = array_slice($remote_courses, 0, $courses_limit - count($courses), true); + if (count($courses) >= $courses_limit) { + //remove the 'marker' course that we retrieve just to see if we have more than $courses_limit + array_pop($courses); + } $morecourses = true; } @@ -87,13 +98,13 @@ public function get_content() { } } - if (empty($courses)) { + if (empty($courses) && empty($remote_courses)) { $content[] = get_string('nocourses','my'); } else { ob_start(); require_once $CFG->dirroot."/course/lib.php"; - print_overview($courses); + print_overview($courses, $remote_courses); $content[] = ob_get_contents(); ob_end_clean(); diff --git a/course/lib.php b/course/lib.php index 101f73f98a556..042a3adcee234 100644 --- a/course/lib.php +++ b/course/lib.php @@ -843,7 +843,7 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) { } -function print_overview($courses) { +function print_overview($courses, array $remote_courses=array()) { global $CFG, $USER, $DB, $OUTPUT; $htmlarray = array(); @@ -859,12 +859,13 @@ function print_overview($courses) { } } foreach ($courses as $course) { - echo $OUTPUT->box_start("coursebox"); - $linkcss = ''; + echo $OUTPUT->box_start('coursebox'); + $attributes = array('title' => s($course->fullname)); if (empty($course->visible)) { - $linkcss = 'class="dimmed"'; + $attributes['class'] = 'dimmed'; } - echo $OUTPUT->heading(''. format_string($course->fullname).'', 3); + echo $OUTPUT->heading(html_writer::link( + new moodle_url('/course/view.php', array('id' => $course->id)), format_string($course->fullname), $attributes), 3); if (array_key_exists($course->id,$htmlarray)) { foreach ($htmlarray[$course->id] as $modname => $html) { echo $html; @@ -872,6 +873,19 @@ function print_overview($courses) { } echo $OUTPUT->box_end(); } + + if (!empty($remote_courses)) { + echo $OUTPUT->heading(get_string('remotecourses', 'mnet')); + } + foreach ($remote_courses as $course) { + echo $OUTPUT->box_start('coursebox'); + $attributes = array('title' => s($course->fullname)); + echo $OUTPUT->heading(html_writer::link( + new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)), + format_string($course->shortname), + $attributes) . ' (' . format_string($course->hostname) . ')', 3); + echo $OUTPUT->box_end(); + } }