From a343b13f59903f91a11400abe53c821d89076fe4 Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Thu, 15 Jan 2009 17:09:02 +0000 Subject: [PATCH] MDL-17915: Conditional activities do not update when you change manual activity completion using an AJAX tickbox- --- course/completion.js | 4 +++- course/lib.php | 15 +++++++++++++-- lib/conditionlib.php | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/course/completion.js b/course/completion.js index 6a46d06fe2..06513435b1 100644 --- a/course/completion.js +++ b/course/completion.js @@ -13,7 +13,9 @@ function completion_init() { var toggles=YAHOO.util.Dom.getElementsByClassName('togglecompletion', 'form'); for(var i=0;icompletionstate==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 " -
"; +
"; if(!$shownhelp && !$isediting) { helpbutton('completionicons',get_string('completionicons','completion'),'completion'); $shownhelp=true; diff --git a/lib/conditionlib.php b/lib/conditionlib.php index f82d2c4209..d14916b542 100644 --- a/lib/conditionlib.php +++ b/lib/conditionlib.php @@ -534,5 +534,29 @@ WHERE } } } + + /** + * 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]); + } } ?> -- 2.39.5