Hello all,
This is my first posting here. I am currently helping to implement a Career Skills Development course at a UK University. In a home test environment, I've made a few changes to the Moodle code which I think have helped to improve the navigation and usability. None of the other forums seemed applicable, so I thought I'd post them here for discussion.
Put indentation in jump menu:
The course we are putting together has dozens of resources. Within the topic format on the course's front page, I have organised them nicely using indentation. However, this indentation is not shown in the "jump to" menu, and so the menu looks like an unordered list of only partly related pages. I have added indentation with the following changes:
course/lib.php, new line 813:
$mod[$seq]->indent = $rawmods[$seq]->indent; // store the indent in the course's modinfo array
course/mod.php, new line 252:
rebuild_course_cache($cm->course); // rebuild the modinfo array when an indent changes
lib/weblib.php, line 3336:
$menu[$url] = str_pad ("", $mod->indent*18, " ") . $mod->name; // add an indent of 3 spaces (3 * 6 characters) in the jump menu
Removing selected indented items from the main topics page:
As we have so many resources, it could be useful to hide anything more than 2 levels deep (indented 2 or more times) on the front page. But I don't want them to be completely hidden - they should still be accessible via the Previous/Next buttons and through internal linking. By adding a class to each row in the topic format, you can use stylesheets to show or hide resources at different indent levels.
course/lib.php: line 980
echo '<tr class="indent'. $mod->indent . '"><td class="activity '.$mod->modname.'">';
They can then be turned on or off using stylesheets:
tr.indent2, tr.indent3, tr.indent4 {display: none;}
Previous and Next labels on buttons:
I added the words "Previous" and "Next" to the arrows in the navigation. I was able to use the existing translations:
lib/weblib.php, line 3348:
"<input type=\"submit\" value=\"< " . get_string ('previous') . "\" /></form>"; // add the translation for previous
lib/weblib.php, line 3354:
"<input type=\"submit\" value=\"" . get_string ('next') . " >\" /></form>"; // add the translation for next
Allow for the easy selecting of internal links when using the HTML editor:
This is a very useful administrative change when using the HTML editor, especially if you have a lot of links between resources. It enables you to quickly choose an existing activity to link to, without having to copy and paste the link. It uses the existing "jump to" menu and then a bit of Javascript to fill the URL field:
lib/editor/popups/link_std.php: new lines after 157
<?
$menu = preg_match ("|<select[^>]+>(.*)</select>|s", navmenu ($course), $m); //extract just the list
$menu = preg_replace ("/Jump[^<]+\.\./", "choose one", $m[1]); //remove the Jump to line
?>
<tr>
<td class="label"></td>
<td><select Xonchange="document.getElementById('f_href').value=this.options[this.selectedIndex].value"><?=$menu?></select></td>
</tr>
Put the heirarchy in the breadcrumbs:
As our course has lots of resources at different indentation levels, I wanted this structure to be reflected in the breadcrumbs. So instead of the bread crumbs saying:
Moodle >> Careers course >> Resources >> Sociology
It reflects the indentation structure and says:
Moodle >> Careers course >> Resources >> Taking action >> Writing CVs >> Example CVs >> Sociology
mod/resource/lib.php, new lines after 101:
// This loops through all this course's modules building a list of the things that lead to me with
// their indentations. If any resource jumps straight from indent 1 to 3, this will behave unexpectedly.
if (($this->cm->indent > 0) && ($modinfo = unserialize($course->modinfo))) {
$indents = array();
foreach ($modinfo as $mod) { //for each module, find those above me
if ($this->cm->id == $mod->cm) break;
if ($mod->indent < $this->cm->indent) $indents[$mod->indent] = $mod;
} //for each module
foreach ($indents as $mod) { //for each module above me
$this->navigation .= " <a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/mod/{$mod->mod}/view.php?id={$mod->cm}\">" . strip_tags(format_string(urldecode($mod->name),true)) . "</a> -> ";
} // for each of the modules above me
} // if this resource is indented
I hope other developers might find these changes useful, and may want to include them in the CVS builds.
Thank you,
Paul Tero