MDL-65276 core: move completion_cron_aggregate() to completionlib
authorSimey Lameze <simey@moodle.com>
Fri, 5 Apr 2019 02:59:10 +0000 (10:59 +0800)
committerSimey Lameze <simey@moodle.com>
Fri, 5 Apr 2019 05:38:30 +0000 (13:38 +0800)
lib/completionlib.php

index 3d8a5e7..a84e3f6 100644 (file)
@@ -1369,3 +1369,26 @@ class completion_info {
             $CFG->wwwroot.'/course/view.php?id='.$this->course->id,null,$error);
     }
 }
+
+/**
+ * Aggregate criteria status's as per configured aggregation method.
+ *
+ * @param int $method COMPLETION_AGGREGATION_* constant.
+ * @param bool $data Criteria completion status.
+ * @param bool|null $state Aggregation state.
+ */
+function completion_cron_aggregate($method, $data, &$state) {
+    if ($method == COMPLETION_AGGREGATION_ALL) {
+        if ($data && $state !== false) {
+            $state = true;
+        } else {
+            $state = false;
+        }
+    } elseif ($method == COMPLETION_AGGREGATION_ANY) {
+        if ($data) {
+            $state = true;
+        } else if (!$data && $state === null) {
+            $state = false;
+        }
+    }
+}