Skip to content

Commit

Permalink
MDL-11312 Added new grade_letters table, and new grade_items.display …
Browse files Browse the repository at this point in the history
…field.
  • Loading branch information
nicolasconnault committed Sep 18, 2007
1 parent ad2cd66 commit e480c18
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 30 deletions.
20 changes: 16 additions & 4 deletions lib/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20070906" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20070918" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -1326,8 +1326,9 @@
<FIELD NAME="multfactor" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="1.0" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="Multiply all grades by this" PREVIOUS="gradepass" NEXT="plusfactor"/>
<FIELD NAME="plusfactor" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="Add this to all grades" PREVIOUS="multfactor" NEXT="aggregationcoef"/>
<FIELD NAME="aggregationcoef" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="Aggregation coefficient used for category weights or other aggregation types" PREVIOUS="plusfactor" NEXT="sortorder"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Sorting order of the columns" PREVIOUS="aggregationcoef" NEXT="hidden"/>
<FIELD NAME="hidden" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="1 is hidden, &amp;gt; 1 is a date to hide until (prevents viewing)" PREVIOUS="sortorder" NEXT="locked"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Sorting order of the columns" PREVIOUS="aggregationcoef" NEXT="display"/>
<FIELD NAME="display" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="-1" SEQUENCE="false" ENUM="false" COMMENT="Display as real grades, percentages (in reference to the minimum and maximum grades) or letters (A, B, C etc..), or course default (-1)" PREVIOUS="sortorder" NEXT="hidden"/>
<FIELD NAME="hidden" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="1 is hidden, &amp;gt; 1 is a date to hide until (prevents viewing)" PREVIOUS="display" NEXT="locked"/>
<FIELD NAME="locked" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="1 is locked, &amp;gt; 1 is a date to lock until (prevents update)" PREVIOUS="hidden" NEXT="locktime"/>
<FIELD NAME="locktime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="lock all final grades after this date" PREVIOUS="locked" NEXT="needsupdate"/>
<FIELD NAME="needsupdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="If this flag is set, then the whole column will be recalculated" PREVIOUS="locktime" NEXT="timecreated"/>
Expand Down Expand Up @@ -1693,7 +1694,7 @@
<KEY NAME="groupid" TYPE="foreign" FIELDS="groupid" REFTABLE="groups" REFFIELDS="id" PREVIOUS="groupingid"/>
</KEYS>
</TABLE>
<TABLE NAME="user_private_key" COMMENT="access keys used in cookieless scripts - rss, etc." PREVIOUS="groupings_groups">
<TABLE NAME="user_private_key" COMMENT="access keys used in cookieless scripts - rss, etc." PREVIOUS="groupings_groups" NEXT="grade_letters">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="script"/>
<FIELD NAME="script" TYPE="char" LENGTH="128" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="plugin, module - unique identifier" PREVIOUS="id" NEXT="value"/>
Expand All @@ -1712,6 +1713,17 @@
<INDEX NAME="script-value" UNIQUE="false" FIELDS="script, value" COMMENT="index used for key validation"/>
</INDEXES>
</TABLE>
<TABLE NAME="grade_letters" COMMENT="Repository for grade letters, for courses and other moodle entities that use grades." PREVIOUS="user_private_key">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="contextid"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="What contextid does this letter apply to (for now these will always be courses, but later...)" PREVIOUS="id" NEXT="lowerboundary"/>
<FIELD NAME="lowerboundary" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="The lower boundary of the letter. Its upper boundary is the lower boundary of the next highest letter, unless there is none above, in which case it's grademax for that grade_item." PREVIOUS="contextid" NEXT="letter"/>
<FIELD NAME="letter" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="The display value of the letter. Can be any character or string of characters (OK, A, 10% etc..)" PREVIOUS="lowerboundary"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me"/>
</KEYS>
</TABLE>
</TABLES>
<STATEMENTS>
<STATEMENT NAME="insert mnet_application" TYPE="insert" TABLE="mnet_application" COMMENT="Initial insert of records on table mnet_application" NEXT="insert log_display">
Expand Down
77 changes: 53 additions & 24 deletions lib/db/upgrade.php
Expand Up @@ -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);

}


Expand Down Expand Up @@ -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) {

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {

Expand All @@ -1809,46 +1809,46 @@ 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');
$field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'description');

/// 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');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));

/// 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');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('tagid', 'itemtype', 'itemid'));

/// 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');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');

/// 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');
Expand All @@ -1857,49 +1857,49 @@ 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');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));

/// 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');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');

/// 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');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('tagid'), 'tag', array('id'));

/// Launch add key tagid
$result = $result && add_key($table, $key);
}

}


if ($result && $oldversion < 2007082801) {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/grade/grade_item.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/grade/simpletest/testgradecategory.php
Expand Up @@ -171,7 +171,7 @@ function test_grade_category_insert_course_category() {

$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);
Expand Down

0 comments on commit e480c18

Please sign in to comment.