Permalink
Browse files

[Fixed] Fails gracefully when no course modules are found.

[Fixed] Does not remove other modules from the activity link options due to same ids.
  • Loading branch information...
michaelpenne
michaelpenne committed Jan 13, 2006
1 parent dfd02fa commit b4f4f09ca8716ed26e4faf4fbb8d9bd81668e763
Showing with 31 additions and 28 deletions.
  1. +31 −28 mod/lesson/mod.html
View
@@ -544,40 +544,43 @@
<td>
<?php
// get the modules
- $mods = get_course_mods($form->course);
- $modinstances = array();
- foreach ($mods as $mod) {
- if ($mod->instance == $form->instance) { // don't add this lesson
- continue;
+ if ($mods = get_course_mods($form->course)) {
+ $modinstances = array();
+ foreach ($mods as $mod) {
+ if ($mod->instance == $form->instance and $mod->module == $form->module) { // don't add this lesson
+ continue;
+ }
+ // get the module name and then store it in a new array
+ if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $form->course)) {
+ $modinstances[$mod->modname][$module->id] = $module->name;
+ }
}
- // get the module name and then store it in a new array
- if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $form->course)) {
- $modinstances[$mod->modname][$module->id] = $module->name;
+ ksort($modinstances); // sort by module name
+
+ // print out a select dropdown with optgroups
+ echo '<select id="menuactivitylink" name="activitylink">';
+ if ($form->activitylink == 0) {
+ echo '<option selected="selected" value="0">'.get_string('none')."</option>\n";
+ } else {
+ echo '<option value="0">'.get_string('none')."</option>\n";
}
- }
- ksort($modinstances); // sort by module name
-
- // print out a select dropdown with optgroups
- echo '<select id="menuactivitylink" name="activitylink">';
- if ($form->activitylink == 0) {
- echo '<option selected="selected" value="0">'.get_string('none')."</option>\n";
- } else {
- echo '<option value="0">'.get_string('none')."</option>\n";
- }
- foreach ($modinstances as $module => $instances) {
- echo '<optgroup label="'.get_string('modulename', $module).'">'."\n";
+ foreach ($modinstances as $module => $instances) {
+ echo '<optgroup label="'.get_string('modulename', $module).'">'."\n";
- asort($instances);
- foreach ($instances as $modid => $instance) {
- if ($form->activitylink == $modid) { // check for being selected
- echo '<option selected="selected" value="'.$modid.'">'.$instance."</option>\n";
- } else {
- echo '<option value="'.$modid.'">'.$instance."</option>\n";
+ asort($instances);
+ foreach ($instances as $modid => $instance) {
+ if ($form->activitylink == $modid) { // check for being selected
+ echo '<option selected="selected" value="'.$modid.'">'.$instance."</option>\n";
+ } else {
+ echo '<option value="'.$modid.'">'.$instance."</option>\n";
+ }
}
+ echo "</optgroup>\n";
}
- echo "</optgroup>\n";
+ echo "</select>\n";
+ } else {
+ print_string('nocoursemods', 'lesson');
}
- echo "</select>\n";
helpbutton("activitylink", get_string("activitylink", "lesson"), "lesson");
?>

0 comments on commit b4f4f09

Please sign in to comment.