From e480c18cf1f16b90d9190d1fb6b5d89daf241287 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Tue, 18 Sep 2007 14:26:15 +0000 Subject: [PATCH] MDL-11312 Added new grade_letters table, and new grade_items.display field. --- lib/db/install.xml | 20 +- lib/db/upgrade.php | 77 +++++--- lib/grade/grade_item.php | 6 + lib/grade/simpletest/testgradecategory.php | 2 +- lib/simpletest/fixtures/gradetest.php | 216 +++++++++++++++++++++ version.php | 2 +- 6 files changed, 293 insertions(+), 30 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index 8d86b55b6a..5603c1ff5d 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -1326,8 +1326,9 @@ - - + + + @@ -1693,7 +1694,7 @@ - +
@@ -1712,6 +1713,17 @@
+ + + + + + + + + + +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index d550837eb5..2bf5b5f2e1 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1434,8 +1434,8 @@ function xmldb_main_upgrade($oldversion=0) { $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id')); $table->addKeyInfo('courseid-outcomeid', XMLDB_KEY_UNIQUE, array('courseid', 'outcomeid')); /// Launch create table for grade_outcomes_courses - $result = $result && create_table($table); - + $result = $result && create_table($table); + } @@ -1736,12 +1736,12 @@ function xmldb_main_upgrade($oldversion=0) { /// Define field ordering to be added to tag_instance table $table = new XMLDBTable('tag_instance'); $field = new XMLDBField('ordering'); - + $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'itemid'); /// Launch add field rawname $result = $result && add_field($table, $field); - } + } if ($result && $oldversion < 2007082700) { @@ -1753,10 +1753,10 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch add field timemodified $result = $result && add_field($table, $field); } - + /// migrate all tags table to tag if ($result && $oldversion < 2007082701) { - require_once($CFG->dirroot.'/tag/lib.php'); + require_once($CFG->dirroot.'/tag/lib.php'); $tagrefs = array(); // $tagrefs[$oldtagid] = $newtagid if ($tags = get_records('tags')) { foreach ($tags as $oldtag) { @@ -1783,7 +1783,7 @@ function xmldb_main_upgrade($oldversion=0) { } } } - + // fetch all the tag instances and migrate them as well if ($blogtags = get_records('blog_tag_instance')) { foreach ($blogtags as $blogtag) { @@ -1798,7 +1798,7 @@ function xmldb_main_upgrade($oldversion=0) { $table = new XMLDBTable('blog_tag_instance'); drop_table($table); } - + /// MDL-11015, MDL-11016 if ($result && $oldversion < 2007082800) { @@ -1809,7 +1809,7 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch change of type for field userid $result = $result && change_field_type($table, $field); - + /// Changing type of field descriptionformat on table tag to int $table = new XMLDBTable('tag'); $field = new XMLDBField('descriptionformat'); @@ -1817,7 +1817,7 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch change of type for field descriptionformat $result = $result && change_field_type($table, $field); - + /// Define key userid (foreign) to be added to tag $table = new XMLDBTable('tag'); $key = new XMLDBKey('userid'); @@ -1825,7 +1825,7 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch add key userid $result = $result && add_key($table, $key); - + /// Define index tagiditem (unique) to be dropped form tag_instance $table = new XMLDBTable('tag_instance'); $index = new XMLDBIndex('tagiditem'); @@ -1833,7 +1833,7 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch drop index tagiditem $result = $result && drop_index($table, $index); - + /// Changing type of field tagid on table tag_instance to int $table = new XMLDBTable('tag_instance'); $field = new XMLDBField('tagid'); @@ -1841,14 +1841,14 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch change of type for field tagid $result = $result && change_field_type($table, $field); - + /// Define key tagid (foreign) to be added to tag_instance $table = new XMLDBTable('tag_instance'); $key = new XMLDBKey('tagid'); $key->setAttributes(XMLDB_KEY_FOREIGN, array('tagid'), 'tag', array('id')); /// Launch add key tagid - $result = $result && add_key($table, $key); + $result = $result && add_key($table, $key); /// Changing sign of field itemid on table tag_instance to unsigned $table = new XMLDBTable('tag_instance'); @@ -1857,15 +1857,15 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch change of sign for field itemid $result = $result && change_field_unsigned($table, $field); - + /// Changing sign of field ordering on table tag_instance to unsigned $table = new XMLDBTable('tag_instance'); $field = new XMLDBField('ordering'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'itemid'); /// Launch change of sign for field ordering - $result = $result && change_field_unsigned($table, $field); - + $result = $result && change_field_unsigned($table, $field); + /// Define index itemtype-itemid-tagid (unique) to be added to tag_instance $table = new XMLDBTable('tag_instance'); $index = new XMLDBIndex('itemtype-itemid-tagid'); @@ -1873,15 +1873,15 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch add index itemtype-itemid-tagid $result = $result && add_index($table, $index); - + /// Define index tagid (unique) to be dropped form tag_correlation $table = new XMLDBTable('tag_correlation'); $index = new XMLDBIndex('tagid'); $index->setAttributes(XMLDB_INDEX_UNIQUE, array('tagid')); /// Launch drop index tagid - $result = $result && drop_index($table, $index); - + $result = $result && drop_index($table, $index); + /// Changing type of field tagid on table tag_correlation to int $table = new XMLDBTable('tag_correlation'); $field = new XMLDBField('tagid'); @@ -1889,8 +1889,8 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch change of type for field tagid $result = $result && change_field_type($table, $field); - - + + /// Define key tagid (foreign) to be added to tag_correlation $table = new XMLDBTable('tag_correlation'); $key = new XMLDBKey('tagid'); @@ -1898,8 +1898,8 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch add key tagid $result = $result && add_key($table, $key); - - } + + } if ($result && $oldversion < 2007082801) { @@ -2064,6 +2064,35 @@ function xmldb_main_upgrade($oldversion=0) { } + if ($result && $oldversion < 2007091800) { + + /// Define field display to be added to grade_items + $table = new XMLDBTable('grade_items'); + $field = new XMLDBField('display'); + $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '-1', 'sortorder'); + + /// Launch add field display + $result = $result && add_field($table, $field); + } + + if ($result && $oldversion < 2007091800) { + + /// Define table grade_letters to be created + $table = new XMLDBTable('grade_letters'); + + /// Adding fields to table grade_letters + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('lowerboundary', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('letter', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); + + /// Adding keys to table grade_letters + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Launch create table for grade_letters + $result = $result && create_table($table); + } + /* /// drop old gradebook tables diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 671e06870a..126fcc9645 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -198,6 +198,12 @@ class grade_item extends grade_object { */ var $sortorder = 0; + /** + * Display type of the grades (Real, Percentage, Letter, or default). + * @var int $display + */ + var $display = null; + /** * 0 if visible, 1 always hidden or date not visible until * @var int $hidden diff --git a/lib/grade/simpletest/testgradecategory.php b/lib/grade/simpletest/testgradecategory.php index 5a1df76d4a..cae623876f 100755 --- a/lib/grade/simpletest/testgradecategory.php +++ b/lib/grade/simpletest/testgradecategory.php @@ -171,7 +171,7 @@ class grade_category_test extends grade_test { $id = $grade_category->insert_course_category($this->courseid); $this->assertNotNull($id); - $this->assertEqual('course grade category', $grade_category->fullname); + $this->assertEqual('Course grade category', $grade_category->fullname); $this->assertEqual(GRADE_AGGREGATE_MEAN, $grade_category->aggregate); $this->assertEqual("/$id/", $grade_category->path); $this->assertEqual(1, $grade_category->depth); diff --git a/lib/simpletest/fixtures/gradetest.php b/lib/simpletest/fixtures/gradetest.php index efbb20793e..0cb96eecee 100644 --- a/lib/simpletest/fixtures/gradetest.php +++ b/lib/simpletest/fixtures/gradetest.php @@ -65,6 +65,7 @@ class grade_test extends UnitTestCase { var $grade_outcomes = array(); var $scale = array(); + var $activities = array(); var $courseid = 1; var $userid = 1; @@ -74,7 +75,15 @@ class grade_test extends UnitTestCase { * Override $CFG->prefix while these tests run. */ function setUp() { + // Set global category settings to -1 (not force) global $CFG; + $CFG->grade_droplow = -1; + $CFG->grade_keephigh = -1; + $CFG->grade_aggregation = -1; + $CFG->grade_aggregateonlygraded = -1; + $CFG->grade_aggregateoutcomes = -1; + $CFG->grade_aggregatesubcats = -1; + $CFG->old_prefix = $CFG->prefix; $CFG->prefix .= 'unittest_'; if (!$this->prepare_test_tables()) { @@ -94,6 +103,69 @@ class grade_test extends UnitTestCase { function prepare_test_tables() { $result = true; + /// Define table course_modules to be created + $table = new XMLDBTable('course_modules'); + + if (!table_exists($table)) { + /// Adding fields to table course_modules + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('module', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('section', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '100', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('added', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('score', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('indent', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1'); + $table->addFieldInfo('visibleold', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1'); + $table->addFieldInfo('groupmode', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('groupingid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('groupmembersonly', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + + /// Adding keys to table course_modules + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('groupingid', XMLDB_KEY_FOREIGN, array('groupingid'), 'groupings', array('id')); + + /// Adding indexes to table course_modules + $table->addIndexInfo('visible', XMLDB_INDEX_NOTUNIQUE, array('visible')); + $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE, array('course')); + $table->addIndexInfo('module', XMLDB_INDEX_NOTUNIQUE, array('module')); + $table->addIndexInfo('instance', XMLDB_INDEX_NOTUNIQUE, array('instance')); + $table->addIndexInfo('idnumber-course', XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'course')); + + /// Launch create table for course_modules + $result = $result && create_table($table, true, false); + } else { + delete_records($table->name); + } + + /// Define table modules to be created + $table = new XMLDBTable('modules'); + + if (!table_exists($table)) { + + /// Adding fields to table modules + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('search', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1'); + + /// Adding keys to table modules + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Adding indexes to table modules + $table->addIndexInfo('name', XMLDB_INDEX_NOTUNIQUE, array('name')); + + /// Launch create table for modules + $result = $result && create_table($table, true, false); + } else { + delete_records($table->name); + } + /// Define table grade_items to be created $table = new XMLDBTable('grade_items'); @@ -288,6 +360,50 @@ class grade_test extends UnitTestCase { delete_records($table->name); } + /// Define table quiz to be created + $table = new XMLDBTable('quiz'); + + if ($result && !table_exists($table)) { + /// Adding fields to table quiz + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('intro', XMLDB_TYPE_TEXT, 'small', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('optionflags', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('penaltyscheme', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('attempts', XMLDB_TYPE_INTEGER, '6', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('attemptonlast', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('grademethod', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1'); + $table->addFieldInfo('decimalpoints', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '2'); + $table->addFieldInfo('review', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('questionsperpage', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('shufflequestions', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('shuffleanswers', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('questions', XMLDB_TYPE_TEXT, 'small', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('sumgrades', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('grade', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('timelimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('password', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('subnet', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('popup', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('delay1', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('delay2', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + + /// Adding keys to table quiz + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Adding indexes to table quiz + $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE, array('course')); + + /// Launch create table for quiz + $result = $result && create_table($table, true, false); + } else { + delete_records($table->name); + } return $result; } @@ -728,6 +844,106 @@ class grade_test extends UnitTestCase { } } + /** + * Load module entries in modules table\ + */ + function load_modules() { + $module = new stdClass(); + $module->name = 'assignment'; + if ($module->id = insert_record('modules', $module)) { + $this->modules[0] = $module; + } + + $module = new stdClass(); + $module->name = 'quiz'; + if ($module->id = insert_record('modules', $module)) { + $this->modules[1] = $module; + } + + $module = new stdClass(); + $module->name = 'forum'; + if ($module->id = insert_record('modules', $module)) { + $this->modules[2] = $module; + } + } + + /** + * Load module instance entries in course_modules table + */ + function load_course_modules() { + $course_module = new stdClass(); + $course_module->course = $this->courseid; + $quiz->module = 1; + $quiz->instance = 2; + if ($course_module->id = insert_record('course_modules', $course_module)) { + $this->course_module[0] = $course_module; + } + + $course_module = new stdClass(); + $course_module->course = $this->courseid; + $quiz->module = 2; + $quiz->instance = 1; + if ($course_module->id = insert_record('course_modules', $course_module)) { + $this->course_module[0] = $course_module; + } + + $course_module = new stdClass(); + $course_module->course = $this->courseid; + $quiz->module = 2; + $quiz->instance = 5; + if ($course_module->id = insert_record('course_modules', $course_module)) { + $this->course_module[0] = $course_module; + } + + $course_module = new stdClass(); + $course_module->course = $this->courseid; + $quiz->module = 3; + $quiz->instance = 3; + if ($course_module->id = insert_record('course_modules', $course_module)) { + $this->course_module[0] = $course_module; + } + + $course_module = new stdClass(); + $course_module->course = $this->courseid; + $quiz->module = 3; + $quiz->instance = 7; + if ($course_module->id = insert_record('course_modules', $course_module)) { + $this->course_module[0] = $course_module; + } + + $course_module = new stdClass(); + $course_module->course = $this->courseid; + $quiz->module = 3; + $quiz->instance = 9; + if ($course_module->id = insert_record('course_modules', $course_module)) { + $this->course_module[0] = $course_module; + } + } + + /** + * Load test quiz data into the database + */ + function load_quiz_activities() { + $quiz = new stdClass(); + $quiz->course = $this->courseid; + $quiz->name = 'test quiz'; + $quiz->intro = 'let us quiz you!'; + $quiz->questions = '1,2'; + if ($quiz->id = insert_record('quiz', $quiz)) { + $this->activities[0] = $quiz; + } + + $quiz = new stdClass(); + $quiz->course = $this->courseid; + $quiz->name = 'test quiz 2'; + $quiz->intro = 'let us quiz you again!'; + $quiz->questions = '1,3'; + if ($quiz->id = insert_record('quiz', $quiz)) { + $this->activities[1] = $quiz; + } + + } + /** * Load grade_item data into the database, and adds the corresponding objects to this class' variable. */ diff --git a/version.php b/version.php index 3dbd3aca9a..2a86bd036e 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2007091702; // YYYYMMDD = date + $version = 2007091800; // YYYYMMDD = date // XY = increments within a single day $release = '1.9 Beta +'; // Human-friendly version name -- 2.39.5