[Fixed] Fails gracefully when no course modules are found.
[Fixed] Does not remove other modules from the activity link options due to same ids.
This commit is contained in:
+34
-31
@@ -544,40 +544,43 @@ if ($form->mode == "add") {
|
||||
<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;
|
||||
}
|
||||
// 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";
|
||||
}
|
||||
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";
|
||||
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;
|
||||
}
|
||||
}
|
||||
echo "</optgroup>\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";
|
||||
|
||||
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 "</select>\n";
|
||||
} else {
|
||||
print_string('nocoursemods', 'lesson');
|
||||
}
|
||||
echo "</select>\n";
|
||||
|
||||
helpbutton("activitylink", get_string("activitylink", "lesson"), "lesson");
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user