The My Moodle feature in Moodle 1.9x displays a list of registered courses to a user after logging in. The nice thing about the list is that each course link is followed by a listing of any recent news or events in the course. Unfortunately in highly active courses this list becomes quite lengthy, and ultimately obnoxious as the length obstructs quick access to other courses in one’s view.
To remedy this I have, for quite some time, maintained a custom bit of very basic Javascript and CSS that sets the default view of news items to hidden, with a clickable link to show the entire list from the My Moodle page:
Nothing fancy, and even as I look at it now I can think of improvements…
We just upgraded to 1.9.8 this semester, and because this snippet modifies Moodle core I had my developer Kevin re-test the snippet before I asked our server admin Paul to replace the existing function as follows:
file Location: '/course/lib.php' file line: "800" function to replace: "function print_overview($courses)"
Here’s the actual replacement function:
// Replaces function in “course/lib.php” to hide course news by default.
// Hidden news is viewable via Javascript by clicking “There is news in this course” link.
// Link does not exist if there is no news in the course.
function print_overview($courses) {
global $CFG, $USER;
$htmlarray = array();
if ($modules = get_records(‘modules’)) {
foreach ($modules as $mod) {
if (file_exists(dirname(dirname(__FILE__)).’/mod/’.$mod->name.’/lib.php’)) {
include_once(dirname(dirname(__FILE__)).’/mod/’.$mod->name.’/lib.php’);
$fname = $mod->name.’_print_overview’;
if (function_exists($fname)) {
$fname($courses,$htmlarray);
}
}
}
}
foreach ($courses as $course) {
print “<ul style=\”margin: 0; padding: 0; list-style: none; width: 96%; \”>”;
$linkcss = ”;
if (empty($course->visible)) {
$linkcss = ‘class=”dimmed”‘;
}
print’<li class=”coursebox” style=”padding: .5em 1em 1em”><h3 style=”font-size: 120%; font-weight: normal; margin: 0 0 .2em 0″><a title=”‘. format_string($course->fullname).’” ‘.$linkcss.’ href=”‘.$CFG->wwwroot.’/course/view.php?id=’.$course->id.’”>’. format_string($course->fullname).’</a></h3>’;
if (array_key_exists($course->id,$htmlarray)) {
print ‘<a href=”#” id=”toggler_’.$course->id.’” onclick=”document.getElementById(\’coursenews_’.$course->id.’\').style.display=(document.getElementById(\’coursenews_’.$course->id.’\').style.display==\’block\’?\’none\’:\’block\’); document.getElementById(\’toggler_’.$course->id.’\').innerHTML=(document.getElementById(\’toggler_’.$course->id.’\').innerHTML == \’There is news in this course…\’?\’Hide course news…\’:\’There is news in this course…\’);”>There is news in this course…</a><div id=”coursenews_’.$course->id.’” style=”display: none”>’;
foreach ($htmlarray[$course->id] as $modname => $html) {
echo $html;
}
print “</div><!–end contents–></li>”;
}
print “</ul>”;
}
}
//End My Moodle Show-Hide News modification


The OpenShare block in Moodle