course completion MDL-2631 Course completion feature - Thanks to Aaron Barnes and...
[moodle.git] / lib / completion / completion_aggregation.php
CommitLineData
2be4d090
MD
1<?php
2
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.
14//
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/>.
17
18
19/**
20 * Course completion critieria aggregation
21 *
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
26 */
27require_once($CFG->libdir.'/completion/data_object.php');
28
29/**
30 * Course completion critieria aggregation
31 */
32class completion_aggregation extends data_object {
33
34 /**
35 * DB Table
36 * @var string $table
37 */
38 public $table = 'course_completion_aggr_methd';
39
40 /**
41 * Array of required table fields, must start with 'id'.
42 * @var array $required_fields
43 */
44 public $required_fields = array('id', 'course', 'criteriatype', 'method', 'value');
45
46 /**
47 * Course id
48 * @access public
49 * @var int
50 */
51 public $course;
52
53 /**
54 * Criteria type this aggregation method applies to, or NULL for overall course aggregation
55 * @access public
56 * @var int
57 */
58 public $criteriatype;
59
60 /**
61 * Aggregation method (COMPLETION_AGGREGATION_* constant)
62 * @access public
63 * @var int
64 */
65 public $method;
66
67 /**
68 * Method value
69 * @access public
70 * @var mixed
71 */
72 public $value;
73
74
75 /**
76 * Finds and returns a data_object instance based on params.
77 * @static abstract
78 *
79 * @param array $params associative arrays varname=>value
80 * @return object data_object instance or false if none found.
81 */
82 public static function fetch($params) {
83 return self::fetch_helper('course_completion_aggr_methd', __CLASS__, $params);
84 }
85
86
87 /**
88 * Finds and returns all data_object instances based on params.
89 * @static abstract
90 *
91 * @param array $params associative arrays varname=>value
92 * @return array array of data_object insatnces or false if none found.
93 */
94 public static function fetch_all($params) {}
95
96 /**
97 * Set the aggregation method
98 * @access public
99 * @param $method int
100 * @return void
101 */
102 public function setMethod($method) {
103 $methods = array(
104 COMPLETION_AGGREGATION_ALL,
105 COMPLETION_AGGREGATION_ANY,
106 );
107
108 if (in_array($method, $methods)) {
109 $this->method = $method;
110 } else {
111 $this->method = COMPLETION_AGGREGATION_ALL;
112 }
113 }
114}