MDL-9506 gradebook classes
[moodle.git] / lib / gradebook / grade_category.php
CommitLineData
8a31e65c 1<?php // $Id$
2
3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.com //
9// //
10// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.com //
11// //
12// This program is free software; you can redistribute it and/or modify //
13// it under the terms of the GNU General Public License as published by //
14// the Free Software Foundation; either version 2 of the License, or //
15// (at your option) any later version. //
16// //
17// This program is distributed in the hope that it will be useful, //
18// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20// GNU General Public License for more details: //
21// //
22// http://www.gnu.org/copyleft/gpl.html //
23// //
24///////////////////////////////////////////////////////////////////////////
25
26require_once('grade_object.php');
27
28class grade_category extends grade_object
29{
30 /**
31 * The table name
32 * @var string $table
33 */
34 var $table = 'grade_categories';
35
36 /**
37 * Array of class variables that are not part of the DB table fields
38 * @var array $nonfields
39 */
40 var $nonfields = array('table', 'nonfields', 'required_fields');
41
42 /**
43 * Array of required fields (keys) and their default values (values).
44 * @var array $required_fields
45 */
46 var $required_fields = array('aggregation' => 0,
47 'keephigh' => 0,
48 'fullname' => null,
49 'droplow' => 0,
50 'hidden' => 0);
51
52 /**
53 * The course this category belongs to.
54 * @var int $courseid
55 */
56 var $courseid;
57
58 /**
59 * The category this category belongs to (optional).
60 * @var int $categoryid
61 */
62 var $categoryid;
63
64 /**
65 * The name of this category.
66 * @var string $fullname
67 */
68 var $fullname;
69
70 /**
71 * A constant pointing to one of the predefined aggregation strategies (none, mean, median, sum etc) .
72 * @var int $aggregation
73 */
74 var $aggregation;
75
76 /**
77 * Keep only the X highest items.
78 * @var int $keephigh
79 */
80 var $keephigh;
81
82 /**
83 * Drop the X lowest items.
84 * @var int $droplow
85 */
86 var $droplow;
87
88 /**
89 * Date until which to hide this category. If null, 0 or false, category is not hidden.
90 * @var int $hidden
91 */
92 var $hidden;
93
94 /**
95 * Array of grade_items or grade_categories nested exactly 1 level below this category
96 * @var array $children
97 */
98 var $children;
99
100 /**
101 * Constructor
102 * @param object $params an object with named parameters for this category.
103 */
104 function grade_category($params=NULL)
105 {
106 if (!empty($params) && (is_array($params) || is_object($params))) {
107 foreach ($params as $param => $value) {
108 if (in_object_vars($param, $this)) {
109 $this->$param = $value;
110 }
111 }
112
113 $this->set_defaults();
114 }
115 }
116
117
118 /**
119 * Finds and returns a grade_category object based on its ID number.
120 *
121 * @param int $id
122 * @param boolean $static Unless set to true, this method will also set $this object with the returned values.
123 * @return object grade_category object or false if none found.
124 */
125 function get_by_id($id, $static=false)
126 {
127 if ($static) {
128 return grade_category::get_record(true, 'id', $id);
129 } else {
130 return $this->get_record(false, 'id', $id);
131 }
132 }
133
134
135 /**
136 * Finds and returns a grade_category object based on 1-3 field values.
137 *
138 * @param boolean $static Unless set to true, this method will also set $this object with the returned values.
139 * @param string $field1
140 * @param string $value1
141 * @param string $field2
142 * @param string $value2
143 * @param string $field3
144 * @param string $value3
145 * @param string $fields
146 * @return object grade_category object or false if none found.
147 */
148 function get_record($static=false, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*")
149 {
150 // In Moodle 2.0 (PHP5) we can replace table names with the static class var grade_category::$table
151 if ($grade_category = get_record('grade_categories', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
152 if ($static) {
153 $grade_category = new grade_category($grade_category);
154 return $grade_category;
155 } else {
156 foreach ($grade_category as $param => $value) {
157 $this->$param = $value;
158 }
159 return $this;
160 }
161 } else {
162 return false;
163 }
164 }
165
166}
167
168?>