mirrored from git://git.moodle.org/moodle.git
/
grade_grades_raw.php
231 lines (199 loc) · 8.14 KB
/
grade_grades_raw.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
require_once('grade_object.php');
class grade_grades_raw extends grade_object {
/**
* The DB table.
* @var string $table
*/
var $table = 'grade_grades_raw';
/**
* Array of class variables that are not part of the DB table fields
* @var array $nonfields
*/
var $nonfields = array('table', 'nonfields', 'scale');
/**
* The id of the grade_item this raw grade belongs to.
* @var int $itemid
*/
var $itemid;
/**
* The id of the user this raw grade belongs to.
* @var int $userid
*/
var $userid;
/**
* The grade value of this raw grade, if such was provided by the module.
* @var float $gradevalue
*/
var $gradevalue;
/**
* The maximum allowable grade when this grade was created.
* @var float $grademax
*/
var $grademax;
/**
* The minimum allowable grade when this grade was created.
* @var float $grademin
*/
var $grademin;
/**
* id of the scale, if this grade is based on a scale.
* @var int $scaleid
*/
var $scaleid;
/**
* A grade_scale object (referenced by $this->scaleid).
* @var object $scale
*/
var $scale;
/**
* The userid of the person who last modified this grade.
* @var int $usermodified
*/
var $usermodified;
/**
* Additional textual information about this grade. It can be automatically generated
* from the module or entered manually by the teacher. This is kept in its own table
* for efficiency reasons, so it is encapsulated in its own object, and included in this raw grade object.
* @var object $grade_grades_text
*/
var $grade_grades_text;
/**
* Constructor. Extends the basic functionality defined in grade_object.
* @param array $params Can also be a standard object.
* @param boolean $fetch Wether or not to fetch the corresponding row from the DB.
*/
function grade_grades_raw($params=NULL, $fetch=true) {
$this->grade_object($params, $fetch);
}
/**
* Instantiates a grade_scale object whose data is retrieved from the DB,
* if this raw grade's scaleid variable is set.
* @return object grade_scale
*/
function load_scale() {
if (!empty($this->scaleid)) {
$this->scale = grade_scale::fetch('id', $this->scaleid);
$this->scale->load_items();
}
return $this->scale;
}
/**
* Loads the grade_grades_text object linked to this grade (through the intersection of itemid and userid), and
* saves it as a class variable for this final object.
* @return object
*/
function load_text() {
if (empty($this->grade_grades_text)) {
return $this->grade_grades_text = grade_grades_text::fetch('itemid', $this->itemid, 'userid', $this->userid);
}
}
/**
* Finds and returns a grade_grades_raw object based on 1-3 field values.
* @static
* @param string $field1
* @param string $value1
* @param string $field2
* @param string $value2
* @param string $field3
* @param string $value3
* @param string $fields
* @return object grade_category object or false if none found.
*/
function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
if ($object = get_record('grade_grades_raw', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
if (isset($this) && get_class($this) == 'grade_grades_raw') {
foreach ($object as $param => $value) {
$this->$param = $value;
}
return $this;
} else {
$object = new grade_grades_raw($object);
$object->load_text();
return $object;
}
} else {
return false;
}
}
/**
* Updates this grade with the given textual information. This will create a new grade_grades_text entry
* if none was previously in DB for this raw grade, or will update the existing one.
* @param string $information Further info like forum rating distribution 4/5/7/0/1
* @param int $informationformat Text format for information
* @param string $feedback Manual feedback from the teacher. Could be a code like 'mi'.
* @param int $feedbackformat Text format for the feedback
* @return boolean Success or Failure
*/
function annotate($information, $informationformat=FORMAT_PLAIN, $feedback=NULL, $feedbackformat=FORMAT_PLAIN) {
$grade_text = new grade_grades_text();
$grade_text->gradesid = $this->id;
$grade_text->information = $information;
$grade_text->informationformat = $informationformat;
$grade_text->feedback = $feedback;
$grade_text->feedbackformat = $feedbackformat;
$result = true;
if (empty($this->text)) {
$result = $grade_text->insert();
} else {
$result = $grade_text->update();
}
$this->text = $grade_text;
return $result;
}
/**
* In addition to the normal updating set up in grade_object, this object also records
* its pre-update value and its new value in the grade_history table.
*
* @param float $newgrade The new gradevalue of this object
* @param string $howmodified What caused the modification? manual/module/import/cron...
* @param string $note A note attached to this modification.
* @return boolean Success or Failure.
*/
function update($newgrade, $howmodified='manual', $note=NULL) {
global $USER;
$oldgrade = $this->gradevalue;
$this->gradevalue = $newgrade;
if (!empty($this->scale->id)) {
$this->scaleid = $this->scale->id;
}
$result = parent::update();
// Update grade_grades_text if changed
if (!empty($this->text)) {
$grade_text = grade_grades_text::fetch('gradesid', $this->id);
if ($this->text != $grade_text && $this->text->id == $grade_text->id) {
$result = $result & $this->text->update();
}
}
if ($result) {
// TODO Handle history recording error, such as displaying a notice, but still return true
grade_history::insert_change($this, $oldgrade, $howmodified, $note);
return true;
} else {
return false;
}
}
}
?>