MDL-65276 core: move functions to completion_regular_task
[moodle.git] / completion / cron.php
CommitLineData
2be4d090 1<?php
2be4d090
MD
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
2be4d090 17/**
0628925b 18 * Code used by scheduled tasks for reviewing and aggregating course completion criteria.
2be4d090 19 *
836375ec
SH
20 * @package core_completion
21 * @category completion
2be4d090 22 * @copyright 2009 Catalyst IT Ltd
836375ec
SH
23 * @author Aaron Barnes <aaronb@catalyst.net.nz>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2be4d090 25 */
2be4d090 26
836375ec 27defined('MOODLE_INTERNAL') || die();
f55ff38a 28require_once($CFG->libdir.'/completionlib.php');
2be4d090 29
2be4d090
MD
30
31/**
32 * Aggregate criteria status's as per configured aggregation method
33 *
34 * @param int $method COMPLETION_AGGREGATION_* constant
35 * @param bool $data Criteria completion status
36 * @param bool|null $state Aggregation state
2be4d090
MD
37 */
38function completion_cron_aggregate($method, $data, &$state) {
39 if ($method == COMPLETION_AGGREGATION_ALL) {
40 if ($data && $state !== false) {
41 $state = true;
42 } else {
43 $state = false;
44 }
45 } elseif ($method == COMPLETION_AGGREGATION_ANY) {
46 if ($data) {
47 $state = true;
48 } else if (!$data && $state === null) {
49 $state = false;
50 }
51 }
52}