]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17915: Conditional activities do not update when you change manual activity compl...
authorsam_marshall <sam_marshall>
Thu, 15 Jan 2009 17:09:02 +0000 (17:09 +0000)
committersam_marshall <sam_marshall>
Thu, 15 Jan 2009 17:09:02 +0000 (17:09 +0000)
course/completion.js
course/lib.php
lib/conditionlib.php

index 6a46d06fe2c224700bc2500bc3af3cd57950887f..06513435b17f639c983e23df5d85ddb2ad8acd03 100644 (file)
@@ -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]);
+    }
   }
 } 
 
index f89e297fd4a8fa3ae406b91c283b9f98f8237484..ac095180175e8e0e93ffbc58334658593427f7ef 100644 (file)
@@ -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;
index f82d2c4209d9e8f83542123c6cae2b5d7054ac9d..d14916b542c68dea26f61ec24e177b3bf623aff2 100644 (file)
@@ -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]);
+    }
 }
 ?>