Merge branch 'MDL-26365' of git://github.com/timhunt/moodle
[moodle.git] / lib / completion / completion_aggregation.php
blob5591261f2979d5c5f9fb4d24d27426c2250bdd80
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 /**
20 * Course completion critieria aggregation
22 * @package moodlecore
23 * @copyright 2009 Catalyst IT Ltd
24 * @author Aaron Barnes <aaronb@catalyst.net.nz>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once($CFG->libdir.'/completion/data_object.php');
29 /**
30 * Course completion critieria aggregation
32 class completion_aggregation extends data_object {
34 /**
35 * DB Table
36 * @var string $table
38 public $table = 'course_completion_aggr_methd';
40 /**
41 * Array of required table fields, must start with 'id'.
42 * @var array $required_fields
44 public $required_fields = array('id', 'course', 'criteriatype', 'method', 'value');
46 /**
47 * Course id
48 * @access public
49 * @var int
51 public $course;
53 /**
54 * Criteria type this aggregation method applies to, or NULL for overall course aggregation
55 * @access public
56 * @var int
58 public $criteriatype;
60 /**
61 * Aggregation method (COMPLETION_AGGREGATION_* constant)
62 * @access public
63 * @var int
65 public $method;
67 /**
68 * Method value
69 * @access public
70 * @var mixed
72 public $value;
75 /**
76 * Finds and returns a data_object instance based on params.
77 * @static abstract
79 * @param array $params associative arrays varname=>value
80 * @return object data_object instance or false if none found.
82 public static function fetch($params) {
83 return self::fetch_helper('course_completion_aggr_methd', __CLASS__, $params);
87 /**
88 * Finds and returns all data_object instances based on params.
89 * @static abstract
91 * @param array $params associative arrays varname=>value
92 * @return array array of data_object insatnces or false if none found.
94 public static function fetch_all($params) {}
96 /**
97 * Set the aggregation method
98 * @access public
99 * @param $method int
100 * @return void
102 public function setMethod($method) {
103 $methods = array(
104 COMPLETION_AGGREGATION_ALL,
105 COMPLETION_AGGREGATION_ANY,
108 if (in_array($method, $methods)) {
109 $this->method = $method;
110 } else {
111 $this->method = COMPLETION_AGGREGATION_ALL;