Skip to content

Commit

Permalink
MDL-13379 mnet: course overview at my home page displays remote cours…
Browse files Browse the repository at this point in the history
…es, 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.
  • Loading branch information
mudrd8mz committed Nov 16, 2010
1 parent 43206af commit 45e8775
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
21 changes: 16 additions & 5 deletions blocks/course_overview/block_course_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down
24 changes: 19 additions & 5 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -859,19 +859,33 @@ 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('<a title="'. format_string($course->fullname).'" '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'. format_string($course->fullname).'</a>', 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;
}
}
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();
}
}


Expand Down

0 comments on commit 45e8775

Please sign in to comment.