Skip to content

Commit

Permalink
MDL-17915: Conditional activities do not update when you change manua…
Browse files Browse the repository at this point in the history
…l activity completion using an AJAX tickbox-
  • Loading branch information
sam_marshall committed Jan 15, 2009
1 parent a561d96 commit a343b13
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion course/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function completion_init() {

var toggles=YAHOO.util.Dom.getElementsByClassName('togglecompletion', 'form');
for(var i=0;i<toggles.length;i++) {
completion_init_toggle(toggles[i]);
if(toggles[i].className.indexOf('preventjs')==-1) {
completion_init_toggle(toggles[i]);
}
}
}

Expand Down
15 changes: 13 additions & 2 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1609,9 +1609,20 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
$completiondata->completionstate==COMPLETION_COMPLETE
? COMPLETION_INCOMPLETE
: COMPLETION_COMPLETE;
// In manual mode the icon is a toggle form.
// In manual mode the icon is a toggle form...

// If this completion state is used by the
// conditional activities system, we need to turn
// off the JS.
if (!empty($CFG->enableavailability) &&
condition_info::completion_value_used_as_condition(
$course, $mod)) {
$extraclass = ' preventjs';
} else {
$extraclass = '';
}
echo "
<form class='togglecompletion' method='post' action='togglecompletion.php'><div>";
<form class='togglecompletion$extraclass' method='post' action='togglecompletion.php'><div>";
if(!$shownhelp && !$isediting) {
helpbutton('completionicons',get_string('completionicons','completion'),'completion');
$shownhelp=true;
Expand Down
24 changes: 24 additions & 0 deletions lib/conditionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,5 +534,29 @@ public static function update_cm_from_form($cm,$fromform,$wipefirst=true) {
}
}
}

/**
* Used in course/lib.php because we need to disable the completion JS if
* a completion value affects a conditional activity.
* @param object $course Moodle course object
* @param object $cm Moodle course-module
* @return bool True if this is used in a condition, false otherwise
*/
public static function completion_value_used_as_condition($course,$cm) {
// Have we already worked out a list of required completion values
// for this course? If so just use that
static $affected = array();
if (!array_key_exists($course->id, $affected)) {
// We don't have data for this course, build it
$modinfo = get_fast_modinfo($course);
$affected[$course->id] = array();
foreach ($modinfo->cms as $cm) {
foreach ($cm->conditionscompletion as $cmid=>$expectedcompletion) {
$affected[$course->id][$cmid] = true;
}
}
}
return array_key_exists($cm->id,$affected[$course->id]);
}
}
?>

0 comments on commit a343b13

Please sign in to comment.