3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
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. //
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: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
26 if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
31 * Shared code for all grade related tests.
33 * @author nicolas@moodle.com
34 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
37 require_once($CFG->libdir
. '/gradelib.php');
38 require_once($CFG->libdir
. '/dmllib.php');
39 require_once($CFG->libdir
. '/ddllib.php');
41 Mock
::generate('grade_item', 'mock_grade_item');
42 Mock
::generate('grade_scale', 'mock_grade_scale');
43 Mock
::generate('grade_category', 'mock_grade_category');
44 Mock
::generate('grade_grade', 'mock_grade_grade');
45 Mock
::generate('grade_outcome', 'mock_grade_outcome');
46 Mock
::generate('grade_lib_wrapper', 'mock_lib_wrapper');
47 Mock
::generate('ADODB_' . $CFG->dbtype
, 'mock_db');
48 Mock
::generate('ADORecordSet_' . $CFG->dbtype
, 'mock_rs');
50 // Prepare partial mocks for the static grade object instances
51 Mock
::generatePartial('grade_category', 'mock_grade_category_partial', array('fetch', 'fetch_all'));
52 Mock
::generatePartial('grade_item', 'mock_grade_item_partial', array('fetch', 'fetch_all'));
53 Mock
::generatePartial('grade_grade', 'mock_grade_grade_partial', array('fetch', 'fetch_all'));
54 Mock
::generatePartial('grade_outcome', 'mock_grade_outcome_partial', array('fetch', 'fetch_all'));
55 Mock
::generatePartial('grade_scale', 'mock_grade_scale_partial', array('fetch', 'fetch_all'));
58 * Here is a brief explanation of the test data set up in these unit tests.
59 * category1 => array(category2 => array(grade_item1, grade_item2), category3 => array(grade_item3))
60 * 3 users for 3 grade_items
62 class grade_test
extends UnitTestCase
{
65 * Each database table receives a number of test entries. These are saved as
66 * arrays of stcClass objects available to this class. This means that
67 * every test has access to these test data. The order of the following array is
68 * crucial, because of the interrelationships between objects.
70 var $tables = array('grade_categories',
76 var $grade_items = array();
77 var $grade_categories = array();
78 var $grade_grades = array();
79 var $grade_outcomes = array();
82 var $activities = array();
87 * Create temporary test tables and entries in the database for these tests.
88 * These tests have to work on a brand new site.
89 * Override $CFG->prefix while these tests run.
92 // Set global category settings to -1 (not force)
94 $CFG->grade_droplow
= -1;
95 $CFG->grade_keephigh
= -1;
96 $CFG->grade_aggregation
= -1;
97 $CFG->grade_aggregateonlygraded
= -1;
98 $CFG->grade_aggregateoutcomes
= -1;
99 $CFG->grade_aggregatesubcats
= -1;
101 $CFG->old_prefix
= $CFG->prefix
;
102 $CFG->prefix
.= 'unittest_';
103 if (!$this->prepare_test_tables()) {
104 die("Could not create all the test tables!");
107 if (!$this->prepare_test_history_tables()) {
108 die("Could not create all the test tables!");
111 foreach ($this->tables
as $table) {
112 $function = "load_$table";
117 function prepare_test_tables() {
120 /// Define table course_modules to be created
121 $table = new XMLDBTable('course_modules');
123 if (!table_exists($table)) {
124 /// Adding fields to table course_modules
125 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
126 $table->addFieldInfo('course', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
127 $table->addFieldInfo('module', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
128 $table->addFieldInfo('instance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
129 $table->addFieldInfo('section', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
130 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '100', null, null, null, null, null, null);
131 $table->addFieldInfo('added', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
132 $table->addFieldInfo('score', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '0');
133 $table->addFieldInfo('indent', XMLDB_TYPE_INTEGER
, '5', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
134 $table->addFieldInfo('visible', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '1');
135 $table->addFieldInfo('visibleold', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '1');
136 $table->addFieldInfo('groupmode', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '0');
137 $table->addFieldInfo('groupingid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
138 $table->addFieldInfo('groupmembersonly', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
140 /// Adding keys to table course_modules
141 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
142 $table->addKeyInfo('groupingid', XMLDB_KEY_FOREIGN
, array('groupingid'), 'groupings', array('id'));
144 /// Adding indexes to table course_modules
145 $table->addIndexInfo('visible', XMLDB_INDEX_NOTUNIQUE
, array('visible'));
146 $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE
, array('course'));
147 $table->addIndexInfo('module', XMLDB_INDEX_NOTUNIQUE
, array('module'));
148 $table->addIndexInfo('instance', XMLDB_INDEX_NOTUNIQUE
, array('instance'));
149 $table->addIndexInfo('idnumber-course', XMLDB_INDEX_NOTUNIQUE
, array('idnumber', 'course'));
151 /// Launch create table for course_modules
152 $result = $result && create_table($table, true, false);
154 delete_records($table->name
);
157 /// Define table modules to be created
158 $table = new XMLDBTable('modules');
160 if (!table_exists($table)) {
162 /// Adding fields to table modules
163 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
164 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '20', null, XMLDB_NOTNULL
, null, null, null, null);
165 $table->addFieldInfo('version', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
166 $table->addFieldInfo('cron', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
167 $table->addFieldInfo('lastcron', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
168 $table->addFieldInfo('search', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
169 $table->addFieldInfo('visible', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '1');
171 /// Adding keys to table modules
172 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
174 /// Adding indexes to table modules
175 $table->addIndexInfo('name', XMLDB_INDEX_NOTUNIQUE
, array('name'));
177 /// Launch create table for modules
178 $result = $result && create_table($table, true, false);
180 delete_records($table->name
);
183 /// Define table grade_items to be created
184 $table = new XMLDBTable('grade_items');
186 if (!table_exists($table)) {
187 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
188 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
189 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
190 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
191 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null);
192 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR
, '30', null, null, null, null, null, null);
193 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
194 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
195 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
196 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
197 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
198 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
199 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
200 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
201 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
202 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
203 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
204 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '1.0');
205 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
206 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
207 $table->addFieldInfo('display', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
208 $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null);
209 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
210 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
211 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
212 $table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
213 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
214 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
215 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
217 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
218 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
219 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN
, array('categoryid'), 'grade_categories', array('id'));
220 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
221 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
223 /// Launch create table for grade_items
224 $result = $result && create_table($table, true, false);
227 delete_records($table->name
);
231 /// Define table grade_categories to be created
232 $table = new XMLDBTable('grade_categories');
234 if ($result && !table_exists($table)) {
236 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
237 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
238 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
239 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
240 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
241 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
242 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
243 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
244 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
245 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
246 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
247 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
248 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
249 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
251 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
252 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
253 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN
, array('parent'), 'grade_categories', array('id'));
255 /// Launch create table for grade_categories
256 $result = $result && create_table($table, true, false);
259 delete_records($table->name
);
263 /// Define table grade_grades to be created
264 $table = new XMLDBTable('grade_grades');
266 if ($result && !table_exists($table)) {
268 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
269 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
270 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
271 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
272 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
273 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
274 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
275 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
276 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
277 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
278 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
279 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
280 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
281 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
282 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
283 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
284 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
285 $table->addFieldInfo('information', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
286 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
287 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
288 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
290 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
291 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
292 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
293 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN
, array('rawscaleid'), 'scale', array('id'));
294 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
296 /// Launch create table for grade_grades
297 $result = $result && create_table($table, true, false);
300 delete_records($table->name
);
304 /// Define table grade_outcomes to be created
305 $table = new XMLDBTable('grade_outcomes');
307 if ($result && !table_exists($table)) {
309 /// Adding fields to table grade_outcomes
310 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
311 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
312 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
313 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
314 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
315 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
316 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
317 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
319 /// Adding keys to table grade_outcomes
320 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
321 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
322 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
323 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
325 /// Launch create table for grade_outcomes
326 $result = $result && create_table($table, true, false);
329 delete_records($table->name
);
333 /// Define table scale to be created
334 $table = new XMLDBTable('scale');
336 if ($result && !table_exists($table)) {
338 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
339 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
340 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
341 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
342 $table->addFieldInfo('scale', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
343 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
344 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
345 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
346 $table->addIndexInfo('courseid', XMLDB_INDEX_NOTUNIQUE
, array('courseid'));
348 /// Launch create table for scale
349 $result = $result && create_table($table, true, false);
352 delete_records($table->name
);
355 /// Define table quiz to be created
356 $table = new XMLDBTable('quiz');
358 if ($result && !table_exists($table)) {
359 /// Adding fields to table quiz
360 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
361 $table->addFieldInfo('course', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
362 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
363 $table->addFieldInfo('intro', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
364 $table->addFieldInfo('timeopen', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
365 $table->addFieldInfo('timeclose', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
366 $table->addFieldInfo('optionflags', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
367 $table->addFieldInfo('penaltyscheme', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
368 $table->addFieldInfo('attempts', XMLDB_TYPE_INTEGER
, '6', null, XMLDB_NOTNULL
, null, null, null, '0');
369 $table->addFieldInfo('attemptonlast', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '0');
370 $table->addFieldInfo('grademethod', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
371 $table->addFieldInfo('decimalpoints', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '2');
372 $table->addFieldInfo('review', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
373 $table->addFieldInfo('questionsperpage', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
374 $table->addFieldInfo('shufflequestions', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '0');
375 $table->addFieldInfo('shuffleanswers', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '0');
376 $table->addFieldInfo('questions', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
377 $table->addFieldInfo('sumgrades', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
378 $table->addFieldInfo('grade', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
379 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
380 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
381 $table->addFieldInfo('timelimit', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
382 $table->addFieldInfo('password', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
383 $table->addFieldInfo('subnet', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
384 $table->addFieldInfo('popup', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '0');
385 $table->addFieldInfo('delay1', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
386 $table->addFieldInfo('delay2', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
388 /// Adding keys to table quiz
389 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
391 /// Adding indexes to table quiz
392 $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE
, array('course'));
394 /// Launch create table for quiz
395 $result = $result && create_table($table, true, false);
397 delete_records($table->name
);
404 function prepare_test_history_tables() {
407 /// Define table grade_items to be created
408 $table = new XMLDBTable('grade_items_history');
410 if (!table_exists($table)) {
412 /// Adding fields to table grade_items_history
413 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
414 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
415 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
416 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
417 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
418 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
419 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
420 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
421 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
422 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null);
423 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR
, '30', null, null, null, null, null, null);
424 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
425 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
426 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
427 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
428 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
429 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
430 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
431 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
432 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
433 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
434 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
435 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '1.0');
436 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
437 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
438 $table->addFieldInfo('display', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
439 $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null);
440 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
441 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
442 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
443 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
445 /// Adding keys to table grade_items_history
446 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
447 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_items', array('id'));
448 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
449 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN
, array('categoryid'), 'grade_categories', array('id'));
450 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
451 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
453 /// Adding indexes to table grade_items_history
454 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
456 /// Launch create table for grade_items_history
457 $result = $result && create_table($table, true, false);
460 delete_records($table->name
);
463 /// Define table grade_categories to be created
464 $table = new XMLDBTable('grade_categories_history');
467 if ($result && !table_exists($table)) {
469 /// Adding fields to table grade_categories_history
470 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
471 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
472 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
473 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
474 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
475 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
476 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
477 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
478 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
479 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
480 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
481 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
482 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
483 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
484 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
485 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
486 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
488 /// Adding keys to table grade_categories_history
489 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
490 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_categories', array('id'));
491 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
492 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN
, array('parent'), 'grade_categories', array('id'));
494 /// Adding indexes to table grade_categories_history
495 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
497 /// Launch create table for grade_categories_history
498 $result = $result && create_table($table, true, false);
501 delete_records($table->name
);
505 /// Define table grade_grades to be created
506 $table = new XMLDBTable('grade_grades_history');
508 if ($result && !table_exists($table)) {
510 /// Adding fields to table grade_grades_history
511 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
512 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
513 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
514 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
515 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
516 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
517 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
518 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
519 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
520 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
521 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
522 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
523 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
524 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
525 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
526 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
527 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
528 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
529 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
530 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
531 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
532 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
533 $table->addFieldInfo('information', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
534 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
536 /// Adding keys to table grade_grades_history
537 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
538 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_grades', array('id'));
539 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
540 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
541 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN
, array('rawscaleid'), 'scale', array('id'));
542 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
543 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
545 /// Adding indexes to table grade_grades_history
546 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
548 /// Launch create table for grade_grades_history
549 $result = $result && create_table($table, true, false);
552 delete_records($table->name
);
556 /// Define table grade_outcomes to be created
557 $table = new XMLDBTable('grade_outcomes_history');
559 if ($result && !table_exists($table)) {
561 /// Adding fields to table grade_outcomes_history
562 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
563 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
564 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
565 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
566 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
567 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
568 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
569 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
570 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
571 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
573 /// Adding keys to table grade_outcomes_history
574 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
575 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_outcomes', array('id'));
576 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
577 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
578 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
580 /// Adding indexes to table grade_outcomes_history
581 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
583 /// Launch create table for grade_outcomes_history
584 $result = $result && create_table($table, true, false);
587 delete_records($table->name
);
590 /// Define table scale to be created
591 $table = new XMLDBTable('scale_history');
594 if ($result && !table_exists($table)) {
596 /// Adding fields to table scale_history
597 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
598 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
599 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
600 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
601 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
602 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
603 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
604 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
605 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
606 $table->addFieldInfo('scale', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
607 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
609 /// Adding keys to table scale_history
610 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
611 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'scales', array('id'));
612 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
614 /// Adding indexes to table scale_history
615 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
617 /// Launch create table for scale_history
618 $result = $result && create_table($table, true, false);
621 delete_records($table->name
);
628 * Drop test tables from DB.
629 * Restore original $CFG->prefix.
631 function tearDown() {
633 // delete the contents of tables before the test run - the unit test might fail on fatal error and the data would not be deleted!
634 foreach ($this->tables
as $table) {
635 unset($this->$table);
637 $CFG->prefix
= $CFG->old_prefix
;
641 * Load scale data into the database, and adds the corresponding objects to this class' variable.
643 function load_scale() {
644 $scale = new stdClass();
646 $scale->name
= 'unittestscale1';
647 $scale->courseid
= $this->courseid
;
648 $scale->userid
= $this->userid
;
649 $scale->scale
= 'Way off topic, Not very helpful, Fairly neutral, Fairly helpful, Supportive, Some good information, Perfect answer!';
650 $scale->description
= 'This scale defines some of qualities that make posts helpful within the Moodle help forums.\n Your feedback will help others see how their posts are being received.';
651 $scale->timemodified
= mktime();
653 if ($scale->id
= insert_record('scale', $scale)) {
654 $this->scale
[0] = $scale;
655 $temp = explode(',', $scale->scale
);
656 $this->scalemax
[0] = count($temp) -1;
659 $scale = new stdClass();
661 $scale->name
= 'unittestscale2';
662 $scale->courseid
= $this->courseid
;
663 $scale->userid
= $this->userid
;
664 $scale->scale
= 'Distinction, Very Good, Good, Pass, Fail';
665 $scale->description
= 'This scale is used to mark standard assignments.';
666 $scale->timemodified
= mktime();
668 if ($scale->id
= insert_record('scale', $scale)) {
669 $this->scale
[1] = $scale;
670 $temp = explode(',', $scale->scale
);
671 $this->scalemax
[1] = count($temp) -1;
674 $scale = new stdClass();
676 $scale->name
= 'unittestscale3';
677 $scale->courseid
= $this->courseid
;
678 $scale->userid
= $this->userid
;
679 $scale->scale
= 'Loner, Contentious, Disinterested, Participative, Follower, Leader';
680 $scale->description
= 'Describes the level of teamwork of a student.';
681 $scale->timemodified
= mktime();
682 $temp = explode(',', $scale->scale
);
683 $scale->max
= count($temp) -1;
685 if ($scale->id
= insert_record('scale', $scale)) {
686 $this->scale
[2] = $scale;
687 $temp = explode(',', $scale->scale
);
688 $this->scalemax
[2] = count($temp) -1;
691 $scale->name
= 'unittestscale4';
692 $scale->courseid
= $this->courseid
;
693 $scale->userid
= $this->userid
;
694 $scale->scale
= 'Does not understand theory, Understands theory but fails practice, Manages through, Excels';
695 $scale->description
= 'Level of expertise at a technical task, with a theoretical framework.';
696 $scale->timemodified
= mktime();
697 $temp = explode(',', $scale->scale
);
698 $scale->max
= count($temp) -1;
700 if ($scale->id
= insert_record('scale', $scale)) {
701 $this->scale
[3] = $scale;
702 $temp = explode(',', $scale->scale
);
703 $this->scalemax
[3] = count($temp) -1;
706 $scale->name
= 'unittestscale5';
707 $scale->courseid
= $this->courseid
;
708 $scale->userid
= $this->userid
;
709 $scale->scale
= 'Insufficient, Acceptable, Excellent.';
710 $scale->description
= 'Description of skills.';
711 $scale->timemodified
= mktime();
712 $temp = explode(',', $scale->scale
);
713 $scale->max
= count($temp) -1;
715 if ($scale->id
= insert_record('scale', $scale)) {
716 $this->scale
[4] = $scale;
717 $temp = explode(',', $scale->scale
);
718 $this->scalemax
[4] = count($temp) -1;
723 * Load grade_category data into the database, and adds the corresponding objects to this class' variable.
725 function load_grade_categories() {
727 $course_category = grade_category
::fetch_course_category($this->courseid
);
729 $grade_category = new stdClass();
731 $grade_category->fullname
= 'unittestcategory1';
732 $grade_category->courseid
= $this->courseid
;
733 $grade_category->aggregation
= GRADE_AGGREGATE_MEAN
;
734 $grade_category->aggregateonlygraded
= 1;
735 $grade_category->keephigh
= 0;
736 $grade_category->droplow
= 0;
737 $grade_category->parent
= $course_category->id
;
738 $grade_category->timecreated
= mktime();
739 $grade_category->timemodified
= mktime();
740 $grade_category->depth
= 2;
742 if ($grade_category->id
= insert_record('grade_categories', $grade_category)) {
743 $grade_category->path
= '/'.$course_category->id
.'/'.$grade_category->id
.'/';
744 update_record('grade_categories', $grade_category);
745 $this->grade_categories
[0] = $grade_category;
748 $grade_category = new stdClass();
750 $grade_category->fullname
= 'unittestcategory2';
751 $grade_category->courseid
= $this->courseid
;
752 $grade_category->aggregation
= GRADE_AGGREGATE_MEAN
;
753 $grade_category->aggregateonlygraded
= 1;
754 $grade_category->keephigh
= 0;
755 $grade_category->droplow
= 0;
756 $grade_category->parent
= $this->grade_categories
[0]->id
;
757 $grade_category->timecreated
= mktime();
758 $grade_category->timemodified
= mktime();
759 $grade_category->depth
= 3;
761 if ($grade_category->id
= insert_record('grade_categories', $grade_category)) {
762 $grade_category->path
= $this->grade_categories
[0]->path
.$grade_category->id
.'/';
763 update_record('grade_categories', $grade_category);
764 $this->grade_categories
[1] = $grade_category;
767 $grade_category = new stdClass();
769 $grade_category->fullname
= 'unittestcategory3';
770 $grade_category->courseid
= $this->courseid
;
771 $grade_category->aggregation
= GRADE_AGGREGATE_MEAN
;
772 $grade_category->aggregateonlygraded
= 1;
773 $grade_category->keephigh
= 0;
774 $grade_category->droplow
= 0;
775 $grade_category->parent
= $this->grade_categories
[0]->id
;
776 $grade_category->timecreated
= mktime();
777 $grade_category->timemodified
= mktime();
778 $grade_category->depth
= 3;
780 if ($grade_category->id
= insert_record('grade_categories', $grade_category)) {
781 $grade_category->path
= $this->grade_categories
[0]->path
.$grade_category->id
.'/';
782 update_record('grade_categories', $grade_category);
783 $this->grade_categories
[2] = $grade_category;
786 // A category with no parent, but grade_items as children
788 $grade_category = new stdClass();
790 $grade_category->fullname
= 'level1category';
791 $grade_category->courseid
= $this->courseid
;
792 $grade_category->aggregation
= GRADE_AGGREGATE_MEAN
;
793 $grade_category->aggregateonlygraded
= 1;
794 $grade_category->keephigh
= 0;
795 $grade_category->droplow
= 0;
796 $grade_category->parent
= $course_category->id
;
797 $grade_category->timecreated
= mktime();
798 $grade_category->timemodified
= mktime();
799 $grade_category->depth
= 2;
801 if ($grade_category->id
= insert_record('grade_categories', $grade_category)) {
802 $grade_category->path
= '/'.$course_category->id
.'/'.$grade_category->id
.'/';
803 update_record('grade_categories', $grade_category);
804 $this->grade_categories
[3] = $grade_category;
809 * Load module entries in modules table\
811 function load_modules() {
812 $module = new stdClass();
813 $module->name
= 'assignment';
814 if ($module->id
= insert_record('modules', $module)) {
815 $this->modules
[0] = $module;
818 $module = new stdClass();
819 $module->name
= 'quiz';
820 if ($module->id
= insert_record('modules', $module)) {
821 $this->modules
[1] = $module;
824 $module = new stdClass();
825 $module->name
= 'forum';
826 if ($module->id
= insert_record('modules', $module)) {
827 $this->modules
[2] = $module;
832 * Load module instance entries in course_modules table
834 function load_course_modules() {
835 $course_module = new stdClass();
836 $course_module->course
= $this->courseid
;
839 if ($course_module->id
= insert_record('course_modules', $course_module)) {
840 $this->course_module
[0] = $course_module;
843 $course_module = new stdClass();
844 $course_module->course
= $this->courseid
;
847 if ($course_module->id
= insert_record('course_modules', $course_module)) {
848 $this->course_module
[0] = $course_module;
851 $course_module = new stdClass();
852 $course_module->course
= $this->courseid
;
855 if ($course_module->id
= insert_record('course_modules', $course_module)) {
856 $this->course_module
[0] = $course_module;
859 $course_module = new stdClass();
860 $course_module->course
= $this->courseid
;
863 if ($course_module->id
= insert_record('course_modules', $course_module)) {
864 $this->course_module
[0] = $course_module;
867 $course_module = new stdClass();
868 $course_module->course
= $this->courseid
;
871 if ($course_module->id
= insert_record('course_modules', $course_module)) {
872 $this->course_module
[0] = $course_module;
875 $course_module = new stdClass();
876 $course_module->course
= $this->courseid
;
879 if ($course_module->id
= insert_record('course_modules', $course_module)) {
880 $this->course_module
[0] = $course_module;
885 * Load test quiz data into the database
887 function load_quiz_activities() {
888 $quiz = new stdClass();
889 $quiz->course
= $this->courseid
;
890 $quiz->name
= 'test quiz';
891 $quiz->intro
= 'let us quiz you!';
892 $quiz->questions
= '1,2';
893 if ($quiz->id
= insert_record('quiz', $quiz)) {
894 $this->activities
[0] = $quiz;
897 $quiz = new stdClass();
898 $quiz->course
= $this->courseid
;
899 $quiz->name
= 'test quiz 2';
900 $quiz->intro
= 'let us quiz you again!';
901 $quiz->questions
= '1,3';
902 if ($quiz->id
= insert_record('quiz', $quiz)) {
903 $this->activities
[1] = $quiz;
909 * Load grade_item data into the database, and adds the corresponding objects to this class' variable.
911 function load_grade_items() {
913 $course_category = grade_category
::fetch_course_category($this->courseid
);
916 $grade_item = new stdClass();
918 $grade_item->courseid
= $this->courseid
;
919 $grade_item->categoryid
= $this->grade_categories
[1]->id
;
920 $grade_item->itemname
= 'unittestgradeitem1';
921 $grade_item->itemtype
= 'mod';
922 $grade_item->itemmodule
= 'quiz';
923 $grade_item->iteminstance
= 1;
924 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
925 $grade_item->grademin
= 30;
926 $grade_item->grademax
= 110;
927 $grade_item->itemnumber
= 1;
928 $grade_item->idnumber
= 'item id 0';
929 $grade_item->iteminfo
= 'Grade item 0 used for unit testing';
930 $grade_item->timecreated
= mktime();
931 $grade_item->timemodified
= mktime();
932 $grade_item->sortorder
= 3;
934 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
935 $this->grade_items
[0] = $grade_item;
939 $grade_item = new stdClass();
941 $grade_item->courseid
= $this->courseid
;
942 $grade_item->categoryid
= $this->grade_categories
[1]->id
;
943 $grade_item->itemname
= 'unittestgradeitem2';
944 $grade_item->itemtype
= 'import';
945 $grade_item->itemmodule
= 'assignment';
946 $grade_item->calculation
= '= ##gi'.$this->grade_items
[0]->id
.'## + 30 + [[item id 0]] - [[item id 0]]';
947 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
948 $grade_item->iteminstance
= 2;
949 $grade_item->itemnumber
= null;
950 $grade_item->grademin
= 0;
951 $grade_item->grademax
= 100;
952 $grade_item->iteminfo
= 'Grade item 1 used for unit testing';
953 $grade_item->timecreated
= mktime();
954 $grade_item->timemodified
= mktime();
955 $grade_item->sortorder
= 4;
957 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
958 $this->grade_items
[1] = $grade_item;
962 $grade_item = new stdClass();
964 $grade_item->courseid
= $this->courseid
;
965 $grade_item->categoryid
= $this->grade_categories
[2]->id
;
966 $grade_item->itemname
= 'unittestgradeitem3';
967 $grade_item->itemtype
= 'mod';
968 $grade_item->itemmodule
= 'forum';
969 $grade_item->iteminstance
= 3;
970 $grade_item->gradetype
= GRADE_TYPE_SCALE
;
971 $grade_item->scaleid
= $this->scale
[0]->id
;
972 $grade_item->grademin
= 0;
973 $grade_item->grademax
= $this->scalemax
[0];
974 $grade_item->iteminfo
= 'Grade item 2 used for unit testing';
975 $grade_item->timecreated
= mktime();
976 $grade_item->timemodified
= mktime();
977 $grade_item->sortorder
= 6;
979 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
980 $this->grade_items
[2] = $grade_item;
983 // Load grade_items associated with the 3 categories
985 $grade_item = new stdClass();
987 $grade_item->courseid
= $this->courseid
;
988 $grade_item->iteminstance
= $this->grade_categories
[0]->id
;
989 $grade_item->itemname
= 'unittestgradeitemcategory1';
990 $grade_item->needsupdate
= 0;
991 $grade_item->itemtype
= 'category';
992 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
993 $grade_item->grademin
= 0;
994 $grade_item->grademax
= 100;
995 $grade_item->iteminfo
= 'Grade item 3 used for unit testing';
996 $grade_item->timecreated
= mktime();
997 $grade_item->timemodified
= mktime();
998 $grade_item->sortorder
= 1;
1000 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
1001 $this->grade_items
[3] = $grade_item;
1005 $grade_item = new stdClass();
1007 $grade_item->courseid
= $this->courseid
;
1008 $grade_item->iteminstance
= $this->grade_categories
[1]->id
;
1009 $grade_item->itemname
= 'unittestgradeitemcategory2';
1010 $grade_item->itemtype
= 'category';
1011 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
1012 $grade_item->needsupdate
= 0;
1013 $grade_item->grademin
= 0;
1014 $grade_item->grademax
= 100;
1015 $grade_item->iteminfo
= 'Grade item 4 used for unit testing';
1016 $grade_item->timecreated
= mktime();
1017 $grade_item->timemodified
= mktime();
1018 $grade_item->sortorder
= 2;
1020 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
1021 $this->grade_items
[4] = $grade_item;
1025 $grade_item = new stdClass();
1027 $grade_item->courseid
= $this->courseid
;
1028 $grade_item->iteminstance
= $this->grade_categories
[2]->id
;
1029 $grade_item->itemname
= 'unittestgradeitemcategory3';
1030 $grade_item->itemtype
= 'category';
1031 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
1032 $grade_item->needsupdate
= true;
1033 $grade_item->grademin
= 0;
1034 $grade_item->grademax
= 100;
1035 $grade_item->iteminfo
= 'Grade item 5 used for unit testing';
1036 $grade_item->timecreated
= mktime();
1037 $grade_item->timemodified
= mktime();
1038 $grade_item->sortorder
= 5;
1040 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
1041 $this->grade_items
[5] = $grade_item;
1044 // Orphan grade_item
1046 $grade_item = new stdClass();
1048 $grade_item->courseid
= $this->courseid
;
1049 $grade_item->categoryid
= $course_category->id
;
1050 $grade_item->itemname
= 'unittestorphangradeitem1';
1051 $grade_item->itemtype
= 'mod';
1052 $grade_item->itemmodule
= 'quiz';
1053 $grade_item->iteminstance
= 5;
1054 $grade_item->itemnumber
= 0;
1055 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
1056 $grade_item->grademin
= 10;
1057 $grade_item->grademax
= 120;
1058 $grade_item->locked
= time();
1059 $grade_item->iteminfo
= 'Orphan Grade 6 item used for unit testing';
1060 $grade_item->timecreated
= mktime();
1061 $grade_item->timemodified
= mktime();
1062 $grade_item->sortorder
= 7;
1064 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
1065 $this->grade_items
[6] = $grade_item;
1068 // 2 grade items under level1category
1070 $grade_item = new stdClass();
1072 $grade_item->courseid
= $this->courseid
;
1073 $grade_item->categoryid
= $this->grade_categories
[3]->id
;
1074 $grade_item->itemname
= 'singleparentitem1';
1075 $grade_item->itemtype
= 'mod';
1076 $grade_item->itemmodule
= 'forum';
1077 $grade_item->iteminstance
= 7;
1078 $grade_item->gradetype
= GRADE_TYPE_SCALE
;
1079 $grade_item->scaleid
= $this->scale
[0]->id
;
1080 $grade_item->grademin
= 0;
1081 $grade_item->grademax
= $this->scalemax
[0];
1082 $grade_item->iteminfo
= 'Grade item 7 used for unit testing';
1083 $grade_item->timecreated
= mktime();
1084 $grade_item->timemodified
= mktime();
1085 $grade_item->sortorder
= 9;
1087 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
1088 $this->grade_items
[7] = $grade_item;
1092 $grade_item = new stdClass();
1094 $grade_item->courseid
= $this->courseid
;
1095 $grade_item->categoryid
= $this->grade_categories
[3]->id
;
1096 $grade_item->itemname
= 'singleparentitem2';
1097 $grade_item->itemtype
= 'mod';
1098 $grade_item->itemmodule
= 'forum';
1099 $grade_item->iteminstance
= 9;
1100 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
1101 $grade_item->grademin
= 0;
1102 $grade_item->grademax
= 100;
1103 $grade_item->iteminfo
= 'Grade item 8 used for unit testing';
1104 $grade_item->timecreated
= mktime();
1105 $grade_item->timemodified
= mktime();
1106 $grade_item->sortorder
= 10;
1108 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
1109 $this->grade_items
[8] = $grade_item;
1112 // Grade_item for level1category
1114 $grade_item = new stdClass();
1116 $grade_item->courseid
= $this->courseid
;
1117 $grade_item->itemname
= 'grade_item for level1 category';
1118 $grade_item->itemtype
= 'category';
1119 $grade_item->itemmodule
= 'quiz';
1120 $grade_item->iteminstance
= $this->grade_categories
[3]->id
;
1121 $grade_item->needsupdate
= true;
1122 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
1123 $grade_item->grademin
= 0;
1124 $grade_item->grademax
= 100;
1125 $grade_item->iteminfo
= 'Orphan Grade item 9 used for unit testing';
1126 $grade_item->timecreated
= mktime();
1127 $grade_item->timemodified
= mktime();
1128 $grade_item->sortorder
= 8;
1130 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
1131 $this->grade_items
[9] = $grade_item;
1134 // Manual grade_item
1136 $grade_item = new stdClass();
1138 $grade_item->courseid
= $this->courseid
;
1139 $grade_item->categoryid
= $course_category->id
;
1140 $grade_item->itemname
= 'manual grade_item';
1141 $grade_item->itemtype
= 'manual';
1142 $grade_item->itemnumber
= 0;
1143 $grade_item->needsupdate
= false;
1144 $grade_item->gradetype
= GRADE_TYPE_VALUE
;
1145 $grade_item->grademin
= 0;
1146 $grade_item->grademax
= 100;
1147 $grade_item->iteminfo
= 'Manual grade item 10 used for unit testing';
1148 $grade_item->timecreated
= mktime();
1149 $grade_item->timemodified
= mktime();
1151 if ($grade_item->id
= insert_record('grade_items', $grade_item)) {
1152 $this->grade_items
[10] = $grade_item;
1158 * Load grade_grades data into the database, and adds the corresponding objects to this class' variable.
1160 function load_grade_grades() {
1161 // Grades for grade_item 1
1162 $grade = new stdClass();
1163 $grade->itemid
= $this->grade_items
[0]->id
;
1165 $grade->rawgrade
= 15; // too small
1166 $grade->finalgrade
= 30;
1167 $grade->timecreated
= mktime();
1168 $grade->timemodified
= mktime();
1169 $grade->information
= 'Thumbs down';
1170 $grade->informationformat
= FORMAT_PLAIN
;
1171 $grade->feedback
= 'Good, but not good enough..';
1172 $grade->feedbackformat
= FORMAT_PLAIN
;
1174 if ($grade->id
= insert_record('grade_grades', $grade)) {
1175 $this->grade_grades
[0] = $grade;
1178 $grade = new stdClass();
1179 $grade->itemid
= $this->grade_items
[0]->id
;
1181 $grade->rawgrade
= 40;
1182 $grade->finalgrade
= 40;
1183 $grade->timecreated
= mktime();
1184 $grade->timemodified
= mktime();
1186 if ($grade->id
= insert_record('grade_grades', $grade)) {
1187 $this->grade_grades
[1] = $grade;
1190 $grade = new stdClass();
1191 $grade->itemid
= $this->grade_items
[0]->id
;
1193 $grade->rawgrade
= 170; // too big
1194 $grade->finalgrade
= 110;
1195 $grade->timecreated
= mktime();
1196 $grade->timemodified
= mktime();
1198 if ($grade->id
= insert_record('grade_grades', $grade)) {
1199 $this->grade_grades
[2] = $grade;
1203 // No raw grades for grade_item 2 - it is calculated
1205 $grade = new stdClass();
1206 $grade->itemid
= $this->grade_items
[1]->id
;
1208 $grade->finalgrade
= 60;
1209 $grade->timecreated
= mktime();
1210 $grade->timemodified
= mktime();
1212 if ($grade->id
= insert_record('grade_grades', $grade)) {
1213 $this->grade_grades
[3] = $grade;
1216 $grade = new stdClass();
1217 $grade->itemid
= $this->grade_items
[1]->id
;
1219 $grade->finalgrade
= 70;
1220 $grade->timecreated
= mktime();
1221 $grade->timemodified
= mktime();
1223 if ($grade->id
= insert_record('grade_grades', $grade)) {
1224 $this->grade_grades
[4] = $grade;
1227 $grade = new stdClass();
1228 $grade->itemid
= $this->grade_items
[1]->id
;
1230 $grade->finalgrade
= 100;
1231 $grade->timecreated
= mktime();
1232 $grade->timemodified
= mktime();
1234 if ($grade->id
= insert_record('grade_grades', $grade)) {
1235 $this->grade_grades
[5] = $grade;
1239 // Grades for grade_item 3
1241 $grade = new stdClass();
1242 $grade->itemid
= $this->grade_items
[2]->id
;
1244 $grade->rawgrade
= 2;
1245 $grade->finalgrade
= 6;
1246 $grade->scaleid
= $this->scale
[3]->id
;
1247 $grade->timecreated
= mktime();
1248 $grade->timemodified
= mktime();
1250 if ($grade->id
= insert_record('grade_grades', $grade)) {
1251 $this->grade_grades
[6] = $grade;
1254 $grade = new stdClass();
1255 $grade->itemid
= $this->grade_items
[2]->id
;
1257 $grade->rawgrade
= 3;
1258 $grade->finalgrade
= 2;
1259 $grade->scaleid
= $this->scale
[3]->id
;
1260 $grade->timecreated
= mktime();
1261 $grade->timemodified
= mktime();
1263 if ($grade->id
= insert_record('grade_grades', $grade)) {
1264 $this->grade_grades
[] = $grade;
1267 $grade = new stdClass();
1268 $grade->itemid
= $this->grade_items
[2]->id
;
1270 $grade->rawgrade
= 1;
1271 $grade->finalgrade
= 3;
1272 $grade->scaleid
= $this->scale
[3]->id
;
1273 $grade->timecreated
= mktime();
1274 $grade->timemodified
= mktime();
1276 if ($grade->id
= insert_record('grade_grades', $grade)) {
1277 $this->grade_grades
[] = $grade;
1280 // Grades for grade_item 7
1282 $grade = new stdClass();
1283 $grade->itemid
= $this->grade_items
[6]->id
;
1285 $grade->rawgrade
= 97;
1286 $grade->finalgrade
= 69;
1287 $grade->timecreated
= mktime();
1288 $grade->timemodified
= mktime();
1290 if ($grade->id
= insert_record('grade_grades', $grade)) {
1291 $this->grade_grades
[] = $grade;
1294 $grade = new stdClass();
1295 $grade->itemid
= $this->grade_items
[6]->id
;
1297 $grade->rawgrade
= 49;
1298 $grade->finalgrade
= 87;
1299 $grade->timecreated
= mktime();
1300 $grade->timemodified
= mktime();
1302 if ($grade->id
= insert_record('grade_grades', $grade)) {
1303 $this->grade_grades
[] = $grade;
1306 $grade = new stdClass();
1307 $grade->itemid
= $this->grade_items
[6]->id
;
1309 $grade->rawgrade
= 67;
1310 $grade->finalgrade
= 94;
1311 $grade->timecreated
= mktime();
1312 $grade->timemodified
= mktime();
1314 if ($grade->id
= insert_record('grade_grades', $grade)) {
1315 $this->grade_grades
[] = $grade;
1318 // Grades for grade_item 8
1320 $grade = new stdClass();
1321 $grade->itemid
= $this->grade_items
[7]->id
;
1323 $grade->rawgrade
= 3;
1324 $grade->finalgrade
= 3;
1325 $grade->timecreated
= mktime();
1326 $grade->timemodified
= mktime();
1328 if ($grade->id
= insert_record('grade_grades', $grade)) {
1329 $this->grade_grades
[] = $grade;
1332 $grade = new stdClass();
1333 $grade->itemid
= $this->grade_items
[7]->id
;
1335 $grade->rawgrade
= 6;
1336 $grade->finalgrade
= 6;
1337 $grade->timecreated
= mktime();
1338 $grade->timemodified
= mktime();
1340 if ($grade->id
= insert_record('grade_grades', $grade)) {
1341 $this->grade_grades
[] = $grade;
1344 // Grades for grade_item 9
1346 $grade = new stdClass();
1347 $grade->itemid
= $this->grade_items
[8]->id
;
1349 $grade->rawgrade
= 20;
1350 $grade->finalgrade
= 20;
1351 $grade->timecreated
= mktime();
1352 $grade->timemodified
= mktime();
1354 if ($grade->id
= insert_record('grade_grades', $grade)) {
1355 $this->grade_grades
[] = $grade;
1358 $grade = new stdClass();
1359 $grade->itemid
= $this->grade_items
[8]->id
;
1361 $grade->rawgrade
= 50;
1362 $grade->finalgrade
= 50;
1363 $grade->timecreated
= mktime();
1364 $grade->timemodified
= mktime();
1366 if ($grade->id
= insert_record('grade_grades', $grade)) {
1367 $this->grade_grades
[] = $grade;
1370 $grade = new stdClass();
1371 $grade->itemid
= $this->grade_items
[7]->id
;
1373 $grade->rawgrade
= 100;
1374 $grade->finalgrade
= 100;
1375 $grade->timecreated
= mktime();
1376 $grade->timemodified
= mktime();
1378 if ($grade->id
= insert_record('grade_grades', $grade)) {
1379 $this->grade_grades
[] = $grade;
1384 * Load grade_outcome data into the database, and adds the corresponding objects to this class' variable.
1386 function load_grade_outcomes() {
1387 // Calculation for grade_item 1
1388 $grade_outcome = new stdClass();
1389 $grade_outcome->fullname
= 'Team work';
1390 $grade_outcome->shortname
= 'Team work';
1391 $grade_outcome->timecreated
= mktime();
1392 $grade_outcome->timemodified
= mktime();
1393 $grade_outcome->scaleid
= $this->scale
[2]->id
;
1395 if ($grade_outcome->id
= insert_record('grade_outcomes', $grade_outcome)) {
1396 $this->grade_outcomes
[] = $grade_outcome;
1399 // Calculation for grade_item 2
1400 $grade_outcome = new stdClass();
1401 $grade_outcome->fullname
= 'Complete circuit board';
1402 $grade_outcome->shortname
= 'Complete circuit board';
1403 $grade_outcome->timecreated
= mktime();
1404 $grade_outcome->timemodified
= mktime();
1405 $grade_outcome->scaleid
= $this->scale
[3]->id
;
1407 if ($grade_outcome->id
= insert_record('grade_outcomes', $grade_outcome)) {
1408 $this->grade_outcomes
[] = $grade_outcome;
1411 // Calculation for grade_item 3
1412 $grade_outcome = new stdClass();
1413 $grade_outcome->fullname
= 'Debug Java program';
1414 $grade_outcome->shortname
= 'Debug Java program';
1415 $grade_outcome->timecreated
= mktime();
1416 $grade_outcome->timemodified
= mktime();
1417 $grade_outcome->scaleid
= $this->scale
[4]->id
;
1419 if ($grade_outcome->id
= insert_record('grade_outcomes', $grade_outcome)) {
1420 $this->grade_outcomes
[] = $grade_outcome;
1425 * No unit tests here