Skip to content

Commit

Permalink
Activities can now be hidden/shown from the activity editing page. Al…
Browse files Browse the repository at this point in the history
…so for modules that know about groups the groupmode can be set from there. See bug 2533. This required adding to the mod.html files calls to new functions print_visible_setting() and print_groupmode_setting() which are combined in print_standard_coursemodule_settings().

The visibility of coursemodules is now always set through the function set_coursemodule_visible() in order to make sure that the associated events get updated in the calendar appropriately.

If moving a coursemodule to a hidden section then the module is set to hidden as well and its events are hidden in the calendar.

If deleting a coursemodule its events are deleted from the calendar.

The function choose_from_menu() has an extra optional argument $disabled which, when set to true, will disable the menu.

For the sake of consistency the function set_groupmode_for_module has been renamed to set_coursemodule_groupmode and the functions show_course_module() and hide_course_module() have been combined to set_coursemodule_visible().
  • Loading branch information
gustav_delius committed Feb 12, 2005
1 parent 2fd4148 commit 48e535b
Show file tree
Hide file tree
Showing 23 changed files with 338 additions and 244 deletions.
107 changes: 88 additions & 19 deletions course/lib.php
Expand Up @@ -934,11 +934,7 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
if (!empty($section->sequence)) {
$modules = explode(",", $section->sequence);
foreach ($modules as $moduleid) {
if ($visibility) {
show_course_module($moduleid);
} else {
hide_course_module($moduleid);
}
set_coursemodule_visible($moduleid, $visibility);
}
}
rebuild_course_cache($courseid);
Expand Down Expand Up @@ -1534,34 +1530,35 @@ function add_mod_to_section($mod, $beforemod=NULL) {
}
}

function set_groupmode_for_module($id, $groupmode) {
function set_coursemodule_groupmode($id, $groupmode) {
return set_field("course_modules", "groupmode", $groupmode, "id", $id);
}

function hide_course_module($mod) {
$cm = get_record('course_modules', 'id', $mod);
function set_coursemodule_visible($id, $visible) {
$cm = get_record('course_modules', 'id', $id);
$modulename = get_field('modules', 'name', 'id', $cm->module);
if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
foreach($events as $event) {
hide_event($event);
if ($visible) {
show_event($event);
} else {
hide_event($event);
}
}
}
return set_field("course_modules", "visible", 0, "id", $mod);
return set_field("course_modules", "visible", $visible, "id", $id);
}

function show_course_module($mod) {
$cm = get_record('course_modules', 'id', $mod);
function delete_course_module($id) {
$cm = get_record('course_modules', 'id', $id);
$modulename = get_field('modules', 'name', 'id', $cm->module);
if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
foreach($events as $event) {
show_event($event);
delete_event($event);
}
}
return set_field("course_modules", "visible", 1, "id", $mod);
}

function delete_course_module($mod) {
return set_field("course_modules", "deleted", 1, "id", $mod);
return set_field("course_modules", "visible", 0, "id", $id);
return set_field("course_modules", "deleted", 1, "id", $id);
}

function delete_mod_from_section($mod, $section) {
Expand Down Expand Up @@ -1634,10 +1631,13 @@ function moveto_module($mod, $section, $beforemod=NULL) {

if ($mod->section != $section->id) {
$mod->section = $section->id;

if (!update_record("course_modules", $mod)) {
return false;
}
// if moving to a hidden section then hide module
if (!$section->visible) {
set_coursemodule_visible($mod->id, 0);
}
}

/// Add the module into the new section
Expand Down Expand Up @@ -1776,4 +1776,73 @@ function course_in_meta ($course) {
return record_exists("course_meta","child_course",$course->id);
}


/**
* Print standard form elements on module setup forms in mod/.../mod.html
*/
function print_standard_coursemodule_settings($form) {
print_groupmode_setting($form);
print_visible_setting($form);
}

/**
* Print groupmode form element on module setup forms in mod/.../mod.html
*/
function print_groupmode_setting($form) {

if (! $course = get_record('course', 'id', $form->course)) {
error("This course doesn't exist");
}
if ($form->coursemodule) {
if (! $cm = get_record('course_modules', 'id', $form->coursemodule)) {
error("This course module doesn't exist");
}
} else {
$cm = null;
}
$groupmode = groupmode($course, $cm);
if ($course->groupmode or (!$course->groupmodeforce)) {
echo '<tr valign="top">';
echo '<td align="right"><b>'.get_string('groupmode').':</b></td>';
echo '<td>';
unset($choices);
$choices[NOGROUPS] = get_string('groupsnone');
$choices[SEPARATEGROUPS] = get_string('groupsseparate');
$choices[VISIBLEGROUPS] = get_string('groupsvisible');
choose_from_menu($choices, 'groupmode', $groupmode, '', '', 0, false, $course->groupmodeforce);
helpbutton('groupmode', get_string('groupmode'));
echo '</td></tr>';
}
}

/**
* Print visibility setting form element on module setup forms in mod/.../mod.html
*/
function print_visible_setting($form) {

if ($form->coursemodule) {
$visible = get_field('course_modules', 'visible', 'id', $form->coursemodule);
} else {
$visible = true;
}

if ($form->mode == 'add') { // in this case $form->section is the section number, not the id
$hiddensection = !get_field('course_sections', 'visible', 'section', $form->section, 'course', $form->course);
} else {
$hiddensection = !get_field('course_sections', 'visible', 'id', $form->section);
}
if ($hiddensection) {
$visible = false;
}

echo '<tr valign="top">';
echo '<td align="right"><b>'.get_string('showimmediately').':</b></td>';
echo '<td>';
unset($choices);
$choices[1] = get_string('yes');
$choices[0] = get_string('no');
choose_from_menu($choices, 'visible', $visible, '', '', 0, false, $hiddensection);
echo '</td></tr>';
}

?>
38 changes: 29 additions & 9 deletions course/mod.php
Expand Up @@ -67,6 +67,20 @@
if (is_string($return)) {
error($return, "view.php?id=$course->id");
}

// to deal with pre-1.5 modules
if (!isset($mod->visible)) {
//We get the section's visible field status
$mod->visible = get_field("course_sections","visible","id",$sectionid);
}
if (!isset($mod->groupmode)) {
$course = get_record('course', 'id', $mod->course);
$cm = get_record('course_modules', 'id', $mod->coursemodule);
$mod->groupmode = groupmode($course, $cm);
}

set_coursemodule_visible($mod->coursemodule, $mod->visible);
set_coursemodule_groupmode($mod->coursemodule, $mod->groupmode);

if (isset($mod->redirect)) {
$SESSION->returnpage = $mod->redirecturl;
Expand Down Expand Up @@ -113,12 +127,18 @@
if (! $sectionid = add_mod_to_section($mod) ) {
error("Could not add the new course module to that section");
}
//We get the section's visible field status
$visible = get_field("course_sections","visible","id",$sectionid);

if (! set_field("course_modules", "visible", $visible, "id", $mod->coursemodule)) {
error("Could not update the course module with the correct visibility");
}

// to deal with pre-1.5 modules
if (!isset($mod->visible)) {
//We get the section's visible field status
$mod->visible = get_field("course_sections","visible","id",$sectionid);
}
if (!isset($mod->groupmode)) {
$mod->groupmode = get_field('course', 'groupmode', 'id', $mod->course);
}

set_coursemodule_visible($mod->coursemodule, $mod->visible);
set_coursemodule_groupmode($mod->coursemodule, $mod->groupmode);

if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
error("Could not update the course module with the correct section");
Expand Down Expand Up @@ -250,7 +270,7 @@
error("You can't modify this course!");
}

hide_course_module($cm->id);
set_coursemodule_visible($cm->id, 0);

rebuild_course_cache($cm->course);

Expand Down Expand Up @@ -280,7 +300,7 @@
}

if ($module->visible and ($section->visible or (SITEID == $cm->course))) {
show_course_module($cm->id);
set_coursemodule_visible($cm->id, 1);
rebuild_course_cache($cm->course);
}

Expand All @@ -301,7 +321,7 @@
error("You can't modify this course!");
}

set_groupmode_for_module($cm->id, $_GET['groupmode']);
set_coursemodule_groupmode($cm->id, $_GET['groupmode']);

rebuild_course_cache($cm->course);

Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Expand Up @@ -916,6 +916,7 @@
$string['showallusers'] = 'Show all users';
$string['showallweeks'] = 'Show all weeks';
$string['showgrades'] = 'Show grades';
$string['showimmediately'] = 'Show immediately';
$string['showlistofcourses'] = 'Show list of courses';
$string['showonlytopic'] = 'Show only topic $a';
$string['showonlyweek'] = 'Show only week $a';
Expand Down
11 changes: 5 additions & 6 deletions lib/weblib.php
Expand Up @@ -600,19 +600,18 @@ function close_window_button() {
* @param type description
* @todo Finish documenting this function
*/
function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false) {
function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false) {

if ($nothing == 'choose') {
$nothing = get_string('choose') .'...';
}

if ($script) {
$javascript = 'onchange="'. $script .'"';
} else {
$javascript = '';
$attributes = ($script) ? 'onchange="'. $script .'"' : '';
if ($disabled) {
$attributes .= ' disabled="disabled"';
}

$output = '<select name="'. $name .'" '. $javascript .'>' . "\n";
$output = '<select name="'. $name .'" '. $attributes .'>' . "\n";
if ($nothing) {
$output .= ' <option value="'. $nothingvalue .'"'. "\n";
if ($nothingvalue === $selected) {
Expand Down
5 changes: 3 additions & 2 deletions mod/assignment/mod.html
Expand Up @@ -111,11 +111,11 @@
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("maximumsize", "assignment") ?>:</b></td>
<td><?php
<td><?php
$choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
?>
</td>
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("duedate", "assignment") ?>:</b></td>
Expand All @@ -125,6 +125,7 @@
print_time_selector("duehour", "dueminute", $form->timedue);
?></td>
</tr>
<?php print_standard_coursemodule_settings($form); ?>
</table>
<br />
<center>
Expand Down

0 comments on commit 48e535b

Please sign in to comment.