if ($preferences->backup_gradebook_history) {
$status = backup_gradebook_categories_history_info($bf, $preferences);
$status = backup_gradebook_grades_history_info($bf, $preferences);
- $status = backup_gradebook_grades_text_history_info($bf, $preferences);
$status = backup_gradebook_items_history_info($bf, $preferences);
$status = backup_gradebook_outcomes_history($bf, $preferences);
}
// do not restore if this grade_item is a mod, and
if ($grade_item->itemtype == 'mod') {
- // this still needs to be included, though grades and grades_text can be ignored
+ // this still needs to be included, though grades can be ignored
} else if ($grade_item->itemtype == 'category') {
// if not all grade items are being backed up
// we ignore this type of grade_item and grades associated
// but userdata is not selected
} else {
$status = backup_gradebook_grades_info($bf,$preferences,$grade_item->id);
- $status = backup_gradebook_grades_text_info($bf,$preferences,$grade_item->id);
}
//End grade_item
fwrite ($bf,end_tag("GRADE_ITEM",4,true));
fwrite ($bf,full_tag("EXPORTED",7,false,$grade->exported));
fwrite ($bf,full_tag("OVERRIDDEN",7,false,$grade->overridden));
fwrite ($bf,full_tag("EXCLUDED",7,false,$grade->excluded));
+ fwrite ($bf,full_tag("FEEDBACK",7,false,$grade->feedback));
+ fwrite ($bf,full_tag("FEEDBACKFORMAT",7,false,$grade->feedbackformat));
+ fwrite ($bf,full_tag("INFORMATION",7,false,$grade->information));
+ fwrite ($bf,full_tag("INFORMATIONFORMAT",7,false,$grade->informationformat));
fwrite ($bf,end_tag("GRADE",6,true));
}
$status = fwrite ($bf,end_tag("GRADE_GRADES",5,true));
return $status;
}
- function backup_gradebook_grades_text_info($bf, $preferences, $itemid) {
-
- global $CFG;
-
- $status = true;
-
- // find all grade texts belonging to this item
- if ($grades = get_records('grade_grades', 'itemid', $itemid)) {
- fwrite ($bf,start_tag("GRADE_GRADES_TEXT",5,true));
- foreach ($grades as $grade) {
- if ($texts = get_records('grade_grades_text', 'gradeid', $grade->id)) {
- foreach ($texts as $text) {
- fwrite ($bf,start_tag("GRADE_TEXT",6,true));
- fwrite ($bf,full_tag("ID",7,false,$text->id));
- fwrite ($bf,full_tag("GRADEID",7,false,$text->gradeid));
- fwrite ($bf,full_tag("INFORMATION",7,false,$text->information));
- fwrite ($bf,full_tag("INFORMATIONFORMAT",7,false,$text->informationformat));
- fwrite ($bf,full_tag("FEEDBACK",7,false,$text->feedback));
- fwrite ($bf,full_tag("FEEDBACKFORMAT",7,false,$text->feedbackformat));
- fwrite ($bf,end_tag("GRADE_TEXT",6,true));
- }
- }
- }
- $status = fwrite ($bf,end_tag("GRADE_GRADES_TEXT",5,true));
- }
- return $status;
- }
-
function backup_gradebook_categories_history_info($bf, $preferences) {
global $CFG;
fwrite ($bf,full_tag("EXPORTED",7,false,$ch->exported));
fwrite ($bf,full_tag("OVERRIDDEN",7,false,$ch->overridden));
fwrite ($bf,full_tag("EXCLUDED",7,false,$ch->excluded));
- fwrite ($bf,end_tag("GRADE_GRADES_HISTORY",6,true));
- }
- $status = fwrite ($bf,end_tag("GRADE_GRADES_HISTORIES",5,true));
- }
- return $status;
- }
-
- function backup_gradebook_grades_text_history_info($bf, $preferences) {
-
- global $CFG;
- $status = true;
-
- // find all grade categories history
- if ($chs = get_records_sql("SELECT ggth.* FROM {$CFG->prefix}grade_grades_text_history ggth,
- {$CFG->prefix}grade_grades gg,
- {$CFG->prefix}grade_items gi
- WHERE gi.courseid = $preferences->backup_course
- AND ggth.gradeid = gg.id
- AND gg.itemid = gi.id")) {
-
- fwrite ($bf,start_tag("GRADE_TEXT_HISTORIES",5,true));
- foreach ($chs as $ch) {
- fwrite ($bf,start_tag("GRADE_TEXT_HISTORY",6,true));
- fwrite ($bf,full_tag("ID",7,false,$ch->id));
- fwrite ($bf,full_tag("OLDID",7,false,$ch->oldid));
- fwrite ($bf,full_tag("ACTION",7,false,$ch->action));
- fwrite ($bf,full_tag("SOURCE",7,false,$ch->source));
- fwrite ($bf,full_tag("TIMEMODIFIED",7,false,$ch->timemodified));
- fwrite ($bf,full_tag("LOGGEDUSER",7,false,$ch->loggeduser));
- fwrite ($bf,full_tag("GRADEID",7,false,$ch->gradeid));
- fwrite ($bf,full_tag("INFORMATION",7,false,$ch->information));
- fwrite ($bf,full_tag("INFORMATIONFORMAT",7,false,$ch->informationformat));
fwrite ($bf,full_tag("FEEDBACK",7,false,$ch->feedback));
fwrite ($bf,full_tag("FEEDBACKFORMAT",7,false,$ch->feedbackformat));
- fwrite ($bf,full_tag("USERMODIFIED",7,false,$ch->usermodified));
- fwrite ($bf,end_tag("GRADE_TEXT_HISTORY",6,true));
+ fwrite ($bf,full_tag("INFORMATION",7,false,$ch->information));
+ fwrite ($bf,full_tag("INFORMATIONFORMAT",7,false,$ch->informationformat));
+ fwrite ($bf,end_tag("GRADE_GRADES_HISTORY",6,true));
}
- $status = fwrite ($bf,end_tag("GRADE_TEXT_HISTORIES",5,true));
+ $status = fwrite ($bf,end_tag("GRADE_GRADES_HISTORIES",5,true));
}
return $status;
}
$outcomescoursescount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_outcomes_courses');
$gchcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_categories_history');
$gghcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_grades_history');
- $ggthcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_grades_text_history');
$gihcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_items_history');
$gohcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_outcomes_history');
}
}
- // Process grade items (grade_raw, grade_final, and grade_text)
+ // Process grade items (grade_grade)
if ($itemscount && $continue) {
if (!defined('RESTORE_SILENTLY')) {
echo '<li>'.get_string('gradeitems','grades').'</li>';
backup_putid($restore->backup_unique_code,'grade_items', backup_todb($info['GRADE_ITEM']['#']['ID']['0']['#']), $itemid);
}
- // no need to restore grades/grades_text if user data is not selected
+ // no need to restore grades if user data is not selected
if ($dbrec->itemtype == 'mod' && !restore_userdata_selected($restore, $dbrec->itemmodule, $iteminstance)) {
// module instance not selected when restored using granular
// skip this item
continue;
}
- /// now, restore grade_grades, grade_text
+ /// now, restore grade_grades
if (!empty($info['GRADE_ITEM']['#']['GRADE_GRADES']['0']['#']) && ($grades = $info['GRADE_ITEM']['#']['GRADE_GRADES']['0']['#']['GRADE'])) {
//Iterate over items
for($i = 0; $i < sizeof($grades); $i++) {
$grade->exported = backup_todb($ite_info['#']['EXPORTED']['0']['#']);
$grade->overridden = backup_todb($ite_info['#']['OVERRIDDEN']['0']['#']);
$grade->excluded = backup_todb($ite_info['#']['EXCLUDED']['0']['#']);
+ $grade->feedback = backup_todb($ite_info['#']['FEEDBACK']['0']['#']);
+ $grade->feedbackformat = backup_todb($ite_info['#']['FEEDBACKFORMAT']['0']['#']);
+ $grade->information = backup_todb($ite_info['#']['INFORMATION']['0']['#']);
+ $grade->informationformat = backup_todb($ite_info['#']['INFORMATIONFORMAT']['0']['#']);
$newid = insert_record('grade_grades', $grade);
}
}
}
-
-
-
- /// processing grade_grades_text
- if (!empty($info['GRADE_ITEM']['#']['GRADE_GRADES_TEXT']['0']['#']) && ($texts = $info['GRADE_ITEM']['#']['GRADE_GRADES_TEXT']['0']['#']['GRADE_TEXT'])) {
- //Iterate over items
- for($i = 0; $i < sizeof($texts); $i++) {
- $ite_info = $texts[$i];
- //traverse_xmlize($ite_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
- $grade = backup_getid($restore->backup_unique_code,"grade_grades", backup_todb($ite_info['#']['GRADEID']['0']['#']));
-
- $text = new object();
- $text->gradeid = $grade->new_id;
- $text->information = backup_todb($ite_info['#']['INFORMATION']['0']['#']);
- $text->informationformat = backup_todb($ite_info['#']['INFORMATIONFORMAT']['0']['#']);
- $text->feedback = backup_todb($ite_info['#']['FEEDBACK']['0']['#']);
- $text->feedbackformat = backup_todb($ite_info['#']['FEEDBACKFORMAT']['0']['#']);
-
- $newid = insert_record('grade_grades_text', $text);
- if ($newid) {
- backup_putid($restore->backup_unique_code,'grade_grades_text', backup_todb($ite_info['#']['ID']['0']['#']), $newid);
- }
- $counter++;
- if ($counter % 20 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if ($counter % 400 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
- }
- }
}
$counteritems++; // increment item count
}
$dbrec->exported = backup_todb($info['GRADE_GRADES_HISTORY']['#']['EXPORTED']['0']['#']);
$dbrec->overridden = backup_todb($info['GRADE_GRADES_HISTORY']['#']['OVERRIDDEN']['0']['#']);
$dbrec->excluded = backup_todb($info['GRADE_GRADES_HISTORY']['#']['EXCLUDED']['0']['#']);
-
- insert_record('grade_grades_history', $dbrec);
- unset($dbrec);
-
- }
- //Increment counters
- $counter++;
- //Do some output
- if ($counter % 1 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if ($counter % 20 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
- }
- }
- }
- }
-
- // process histories
-
- if ($ggthcount && $continue && !isset($SESSION->restore->importing) && $restore->restore_gradebook_history) {
- if (!defined('RESTORE_SILENTLY')) {
- echo '<li>'.get_string('gradegradestexthistory','grades').'</li>';
- }
- $counter = 0;
- while ($counter < $ggthcount) {
- //Fetch recordset_size records in each iteration
- $recs = get_records_select("backup_ids","table_name = 'grade_grades_text_history' AND backup_code = '$restore->backup_unique_code'",
- "old_id",
- "old_id",
- $counter,
- $recordset_size);
-
- if ($recs) {
- foreach ($recs as $rec) {
- //Get the full record from backup_ids
- $data = backup_getid($restore->backup_unique_code,'grade_grades_text_history',$rec->old_id);
- if ($data) {
- //Now get completed xmlized object
- $info = $data->info;
- //traverse_xmlize($info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- $oldobj = backup_getid($restore->backup_unique_code,"grade_grades_text", backup_todb($info['GRADE_TEXT_HISTORY']['#']['OLDID']['0']['#']));
- if (empty($oldobj->new_id)) {
- // if the old object is not being restored, can't restoring its history
- $counter++;
- continue;
- }
- $dbrec->oldid = $oldobj->new_id;
- $dbrec->action = backup_todb($info['GRADE_TEXT_HISTORY']['#']['ACTION']['0']['#']);
- $dbrec->source = backup_todb($info['GRADE_TEXT_HISTORY']['#']['SOURCE']['0']['#']);
- $dbrec->timemodified = backup_todb($info['GRADE_TEXT_HISTORY']['#']['TIMEMODIFIED']['0']['#']);
- if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_TEXT_HISTORY']['#']['LOGGEDUSER']['0']['#']))) {
- $dbrec->loggeduser = $oldobj->new_id;
- }
- $oldobj = backup_getid($restore->backup_unique_code,"grade_grades", backup_todb($info['GRADE_TEXT_HISTORY']['#']['GRADEID']['0']['#']));
- $dbrec->gradeid = $oldobj->new_id;
- if (empty($dbrec->gradeid)) {
- $counter++;
- continue; // grade not being restore, possibly because grade item is not restored
- }
-
- $dbrec->information = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATION']['0']['#']);
- $dbrec->informationformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATIONFORMAT']['0']['#']);
$dbrec->feedback = backup_todb($info['GRADE_TEXT_HISTORY']['#']['FEEDBACK']['0']['#']);
$dbrec->feedbackformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['FEEDBACKFORMAT']['0']['#']);
- if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_TEXT_HISTORY']['#']['USERMODIFIED']['0']['#']))) {
- $dbrec->usermodified = $oldobj->new_id;
- }
+ $dbrec->information = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATION']['0']['#']);
+ $dbrec->informationformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATIONFORMAT']['0']['#']);
- insert_record('grade_grades_text_history', $dbrec);
+ insert_record('grade_grades_history', $dbrec);
unset($dbrec);
}
}
// process histories
+
if ($gihcount && $continue && !isset($SESSION->restore->importing) && $restore->restore_gradebook_history) {
if (!defined('RESTORE_SILENTLY')) {
echo '<li>'.get_string('gradeitemshistory','grades').'</li>';
unset($this->temp);
}
- if (($this->level == 5) and ($tagName == "GRADE_TEXT_HISTORY")) {
- //Prepend XML standard header to info gathered
- $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
- //Call to xmlize for this portion of xml data (one PREFERENCE)
- //echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
- $data = xmlize($xml_data,0);
- //echo strftime ("%X",time())."<p>"; //Debug
- //traverse_xmlize($data); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
- //Now, save data to db. We'll use it later
- //Get id and status from data
- $id = $data["GRADE_TEXT_HISTORY"]["#"]["ID"]["0"]["#"];
- $this->counter++;
- //Save to db
- $status = backup_putid($this->preferences->backup_unique_code, 'grade_grades_text_history', $id,
- null,$data);
- //Create returning info
- $this->info = $this->counter;
- //Reset temp
-
- unset($this->temp);
- }
-
if (($this->level == 5) and ($tagName == "GRADE_ITEM_HISTORY")) {
//Prepend XML standard header to info gathered
$xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
$mform = new edit_grade_form(null, array('grade_item'=>$grade_item, 'gpr'=>$gpr));
if ($grade = get_record('grade_grades', 'itemid', $grade_item->id, 'userid', $userid)) {
- if ($grade_text = get_record('grade_grades_text', 'gradeid', $grade->id)) {
- // always clean existing feedback - grading should not have XSS risk
- if (can_use_html_editor()) {
- $options = new object();
- $options->smiley = false;
- $options->filter = false;
- $options->noclean = false;
- $grade->feedback = format_text($grade_text->feedback, $grade_text->feedbackformat, $options);
- $grade->feedbackformat = FORMAT_HTML;
- } else {
- $grade->feedback = clean_text($grade_text->feedback, $grade_text->feedbackformat);
- $grade->feedbackformat = $grade_text->feedbackformat;
- }
+
+ // always clean existing feedback - grading should not have XSS risk
+ if (can_use_html_editor()) {
+ $options = new object();
+ $options->smiley = false;
+ $options->filter = false;
+ $options->noclean = false;
+ $grade->feedback = format_text($grade->feedback, $grade->feedbackformat, $options);
+ $grade->feedbackformat = FORMAT_HTML;
+ } else {
+ $grade->feedback = clean_text($grade->feedback, $grade->feedbackformat);
}
$grade->locked = $grade->locked > 0 ? 1:0;
// form processing
} else if ($data = $mform->get_data(false)) {
$old_grade_grade = new grade_grade(array('userid'=>$data->userid, 'itemid'=>$grade_item->id), true); //might not exist yet
- $old_grade_text = new grade_grade_text(array('gradeid' => $old_grade_grade->id), true);
// fix no grade for scales
if (!isset($data->finalgrade) or $data->finalgrade == $data->oldgrade) {
}
if (!isset($data->feedback)) {
- $data->feedback = $old_grade_text->feedback;
- $data->feedbackformat = $old_grade_text->feedbackformat;
+ $data->feedback = $old_grade_grade->feedback;
+ $data->feedbackformat = $old_grade_grade->feedbackformat;
}
// update final grade or feedback
$grade_item->update_final_grade($data->userid, $data->finalgrade, NULL, 'editgrade', $data->feedback, $data->feedbackformat);
$itemids = array_keys($this->grade_items);
$itemids = implode(',', $itemids);
- $grades_sql = "SELECT g.*, gt.feedback, gt.feedbackformat
+ $grades_sql = "SELECT g.*
FROM {$CFG->prefix}grade_grades g
- LEFT JOIN {$CFG->prefix}grade_grades_text gt ON gt.gradeid = g.id
INNER JOIN {$CFG->prefix}user u ON g.userid = u.id
INNER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
$groupsql
global $CFG;
// please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it!
- $sql = "SELECT g.*, gt.feedback, gt.feedbackformat, gi.grademin, gi.grademax
+ $sql = "SELECT g.*, gi.grademin, gi.grademax
FROM {$CFG->prefix}grade_items gi,
{$CFG->prefix}grade_grades g
- LEFT JOIN {$CFG->prefix}grade_grades_text gt ON g.id = gt.gradeid
WHERE g.itemid = gi.id AND gi.courseid = $this->courseid $this->userselect";
if ($grades = get_records_sql($sql)) {
$data = array();
$grade_grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$this->user->id));
- $grade_text = $grade_grade->load_text();
// TODO: indicate items that "needsupdate" - missing final calculation
}
/// prints notes
- if (!empty($grade_text->feedback)) {
- $data[] = $grade_text->feedback;
+ if (!empty($grade_grade->feedback)) {
+ $data[] = format_text($grade_grade->feedback, $grade_grade->feedbackformat);
} else {
$data[] = ' ';
}
<INDEX NAME="idnumber-courseid" UNIQUE="false" FIELDS="idnumber, courseid" COMMENT="non unique index (although programatically we are guarantying some sort of uniqueness both under this table and the course_modules one). TODO: We need a central store of module idnumbers in the future." PREVIOUS="gradetype"/>
</INDEXES>
</TABLE>
- <TABLE NAME="grade_grades" COMMENT="grade_grades This table keeps individual grades for each user and each item, exactly as imported or submitted by modules. The rawgrademax/min and rawscaleid are stored here to record the values at the time the grade was stored, because teachers might change this for an activity! All the results are normalised/resampled for the final grade value." PREVIOUS="grade_items" NEXT="grade_grades_text">
+ <TABLE NAME="grade_grades" COMMENT="grade_grades This table keeps individual grades for each user and each item, exactly as imported or submitted by modules. The rawgrademax/min and rawscaleid are stored here to record the values at the time the grade was stored, because teachers might change this for an activity! All the results are normalised/resampled for the final grade value." PREVIOUS="grade_items" NEXT="grade_outcomes_history">
<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="itemid"/>
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="The item this grade belongs to" PREVIOUS="id" NEXT="userid"/>
<FIELD NAME="locktime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="automatic locking of final grade, 0 means none, date otherwise" PREVIOUS="locked" NEXT="exported"/>
<FIELD NAME="exported" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="date of last grade export, 0 if none" PREVIOUS="locktime" NEXT="overridden"/>
<FIELD NAME="overridden" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="indicates grade overridden from gradebook, 0 means none, date means overridden" PREVIOUS="exported" NEXT="excluded"/>
- <FIELD NAME="excluded" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="grade excluded from aggregation functions, date means when excluded" PREVIOUS="overridden" NEXT="timecreated"/>
- <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="the time this grade was first created" PREVIOUS="excluded" NEXT="timemodified"/>
+ <FIELD NAME="excluded" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="grade excluded from aggregation functions, date means when excluded" PREVIOUS="overridden" NEXT="feedback"/>
+ <FIELD NAME="feedback" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="grading feedback" PREVIOUS="excluded" NEXT="feedbackformat"/>
+ <FIELD NAME="feedbackformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="format of feedback text" PREVIOUS="feedback" NEXT="information"/>
+ <FIELD NAME="information" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="optiona information" PREVIOUS="feedbackformat" NEXT="informationformat"/>
+ <FIELD NAME="informationformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="format of information text" PREVIOUS="information" NEXT="timecreated"/>
+ <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="the time this grade was first created" PREVIOUS="informationformat" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="the time this grade was last modified" PREVIOUS="timecreated"/>
</FIELDS>
<KEYS>
<INDEX NAME="locked-locktime" UNIQUE="false" FIELDS="locked, locktime" COMMENT="used in grading cron"/>
</INDEXES>
</TABLE>
- <TABLE NAME="grade_grades_text" COMMENT="This table keeps additional textual information about each individual grade, whether it be automatically generated from the module or entered manually by the teacher. It's here separate from the all-numeric grade_grades for database efficiency reasons." PREVIOUS="grade_grades" NEXT="grade_outcomes_history">
- <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="gradeid"/>
- <FIELD NAME="gradeid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="information"/>
- <FIELD NAME="information" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Further information like forum rating distribution 4/5/7/0/1" PREVIOUS="gradeid" NEXT="informationformat"/>
- <FIELD NAME="informationformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Text format for information" PREVIOUS="information" NEXT="feedback"/>
- <FIELD NAME="feedback" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Manual feedback from the teacher. Could be a code like 'mi'." PREVIOUS="informationformat" NEXT="feedbackformat"/>
- <FIELD NAME="feedbackformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Text format for feedback" PREVIOUS="feedback" NEXT="timecreated"/>
- <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="the time these entry was first created" PREVIOUS="feedbackformat" NEXT="timemodified"/>
- <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" ENUM="false" COMMENT="the time this entry was last updated" PREVIOUS="timecreated" NEXT="usermodified"/>
- <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" ENUM="false" COMMENT="the userid of the person who last modified this entry" PREVIOUS="timemodified"/>
- </FIELDS>
- <KEYS>
- <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="gradeid"/>
- <KEY NAME="gradeid" TYPE="foreign" FIELDS="gradeid" REFTABLE="grade_grades" REFFIELDS="id" PREVIOUS="primary" NEXT="usermodified"/>
- <KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id" PREVIOUS="gradeid"/>
- </KEYS>
- </TABLE>
- <TABLE NAME="grade_outcomes_history" COMMENT="History table" PREVIOUS="grade_grades_text" NEXT="grade_categories_history">
+ <TABLE NAME="grade_outcomes_history" COMMENT="History table" PREVIOUS="grade_grades" NEXT="grade_categories_history">
<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="action"/>
<FIELD NAME="action" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="created/modified/deleted constants" PREVIOUS="id" NEXT="oldid"/>
<INDEX NAME="action" UNIQUE="false" FIELDS="action" COMMENT="insert/update/delete"/>
</INDEXES>
</TABLE>
- <TABLE NAME="grade_grades_history" COMMENT="History table" PREVIOUS="grade_items_history" NEXT="grade_grades_text_history">
+ <TABLE NAME="grade_grades_history" COMMENT="History table" PREVIOUS="grade_items_history" NEXT="grade_import_newitem">
<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="action"/>
<FIELD NAME="action" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="created/modified/deleted constants" PREVIOUS="id" NEXT="oldid"/>
<FIELD NAME="locktime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="automatic locking of final grade, 0 means none, date otherwise" PREVIOUS="locked" NEXT="exported"/>
<FIELD NAME="exported" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="date of last grade export, 0 if none" PREVIOUS="locktime" NEXT="overridden"/>
<FIELD NAME="overridden" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="indicates grade overridden from gradebook, 0 means none, date means overridden" PREVIOUS="exported" NEXT="excluded"/>
- <FIELD NAME="excluded" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="grade excluded from aggregation functions, date means when excluded" PREVIOUS="overridden"/>
+ <FIELD NAME="excluded" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="grade excluded from aggregation functions, date means when excluded" PREVIOUS="overridden" NEXT="feedback"/>
+ <FIELD NAME="feedback" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="grading feedback" PREVIOUS="excluded" NEXT="feedbackformat"/>
+ <FIELD NAME="feedbackformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="format of feedback text" PREVIOUS="feedback" NEXT="information"/>
+ <FIELD NAME="information" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="optiona information" PREVIOUS="feedbackformat" NEXT="informationformat"/>
+ <FIELD NAME="informationformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="format of information text" PREVIOUS="information"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="oldid"/>
<INDEX NAME="action" UNIQUE="false" FIELDS="action" COMMENT="insert/update/delete"/>
</INDEXES>
</TABLE>
- <TABLE NAME="grade_grades_text_history" COMMENT="History table" PREVIOUS="grade_grades_history" NEXT="grade_import_newitem">
- <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="action"/>
- <FIELD NAME="action" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="created/modified/deleted constants" PREVIOUS="id" NEXT="oldid"/>
- <FIELD NAME="oldid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the table, please edit me" PREVIOUS="action" NEXT="source"/>
- <FIELD NAME="source" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="What caused the modification? manual/module/import/..." PREVIOUS="oldid" NEXT="timemodified"/>
- <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="The last time this grade_item was modified" PREVIOUS="source" NEXT="loggeduser"/>
- <FIELD NAME="loggeduser" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="the userid of the person who last modified this outcome" PREVIOUS="timemodified" NEXT="gradeid"/>
- <FIELD NAME="gradeid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="loggeduser" NEXT="information"/>
- <FIELD NAME="information" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Further information like forum rating distribution 4/5/7/0/1" PREVIOUS="gradeid" NEXT="informationformat"/>
- <FIELD NAME="informationformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Text format for information" PREVIOUS="information" NEXT="feedback"/>
- <FIELD NAME="feedback" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Manual feedback from the teacher. Could be a code like 'mi'." PREVIOUS="informationformat" NEXT="feedbackformat"/>
- <FIELD NAME="feedbackformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Text format for feedback" PREVIOUS="feedback" NEXT="usermodified"/>
- <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="the userid of the person who last modified this grade" PREVIOUS="feedbackformat"/>
- </FIELDS>
- <KEYS>
- <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="oldid"/>
- <KEY NAME="oldid" TYPE="foreign" FIELDS="oldid" REFTABLE="grade_grades_text" REFFIELDS="id" PREVIOUS="primary" NEXT="gradeid"/>
- <KEY NAME="gradeid" TYPE="foreign" FIELDS="gradeid" REFTABLE="grade_grades" REFFIELDS="id" PREVIOUS="oldid" NEXT="usermodified"/>
- <KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id" PREVIOUS="gradeid" NEXT="loggeduser"/>
- <KEY NAME="loggeduser" TYPE="foreign" FIELDS="loggeduser" REFTABLE="user" REFFIELDS="id" PREVIOUS="usermodified"/>
- </KEYS>
- <INDEXES>
- <INDEX NAME="action" UNIQUE="false" FIELDS="action" COMMENT="insert/update/delete"/>
- </INDEXES>
- </TABLE>
- <TABLE NAME="grade_import_newitem" COMMENT="temporary table for storing new grade_item names from grade import" PREVIOUS="grade_grades_text_history" NEXT="grade_import_values">
+ <TABLE NAME="grade_import_newitem" COMMENT="temporary table for storing new grade_item names from grade import" PREVIOUS="grade_grades_history" NEXT="grade_import_values">
<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="itemname"/>
<FIELD NAME="itemname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="new grade item name" PREVIOUS="id" NEXT="import_code"/>
$table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null);
+ $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null);
+ $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$result = $result && create_table($table);
- /// Define table grade_grades_text to be created
- $table = new XMLDBTable('grade_grades_text');
-
- /// Adding fields to table grade_grades_text
- $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
- $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
- $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
- $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
- $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
- $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
-
- /// Adding keys to table grade_grades_text
- $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
- $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id'));
- $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
-
- /// Launch create table for grade_grades_text
- $result = $result && create_table($table);
-
-
/// Define table grade_outcomes_history to be created
$table = new XMLDBTable('grade_outcomes_history');
$table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null);
+ $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null);
+ $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
/// Adding keys to table grade_grades_history
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$result = $result && create_table($table);
- /// Define table grade_grades_text_history to be created
- $table = new XMLDBTable('grade_grades_text_history');
-
- /// Adding fields to table grade_grades_text_history
- $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
- $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
- $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
- $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
- $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
- $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
- $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
-
- /// Adding keys to table grade_grades_text_history
- $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
- $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_grades_text', array('id'));
- $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id'));
- $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
- $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
-
- /// Adding indexes to table grade_grades_text_history
- $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
-
- /// Launch create table for grade_grades_text_history
- $result = $result && create_table($table);
-
-
/// Define table grade_import_newitem to be created
$table = new XMLDBTable('grade_import_newitem');
}
if ($result && $oldversion < 2007090503) {
-/// Remove obsoleted unit tests tables - they will be recreated automatically
- $tables = array('grade_categories',
- 'scale',
- 'grade_items',
- 'grade_calculations',
- 'grade_grades',
- 'grade_grades_raw',
- 'grade_grades_final',
- 'grade_grades_text',
- 'grade_outcomes',
- 'grade_outcomes_courses');
-
- foreach ($tables as $tablename) {
- $table = new XMLDBTable('unittest_'.$tablename);
- if (table_exists($table)) {
- drop_table($table);
- }
- $table = new XMLDBTable('unittest_'.$tablename.'_history');
- if (table_exists($table)) {
- drop_table($table);
- }
- }
-
-
/// Define field aggregatesubcats to be added to grade_categories
$table = new XMLDBTable('grade_categories');
$field = new XMLDBField('aggregatesubcats');
load_all_capabilities();
}
+ /**
+ * Merging of grade_grades_text back into grade_grades
+ */
+ if ($result && $oldversion < 2007092002) {
+
+/// Remove obsoleted unit tests tables - they will be recreated automatically
+ $tables = array('grade_categories',
+ 'scale',
+ 'grade_items',
+ 'grade_calculations',
+ 'grade_grades',
+ 'grade_grades_raw',
+ 'grade_grades_final',
+ 'grade_grades_text',
+ 'grade_outcomes',
+ 'grade_outcomes_courses');
+
+ foreach ($tables as $tablename) {
+ $table = new XMLDBTable('unittest_'.$tablename);
+ if (table_exists($table)) {
+ drop_table($table);
+ }
+ $table = new XMLDBTable('unittest_'.$tablename.'_history');
+ if (table_exists($table)) {
+ drop_table($table);
+ }
+ }
+
+ /// Define field feedback to be added to grade_grades
+ $table = new XMLDBTable('grade_grades');
+ $field = new XMLDBField('feedback');
+ $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null, 'excluded');
+
+ if (!field_exists($table, $field)) {
+ /// Launch add field feedback
+ $result = $result && add_field($table, $field);
+ }
+
+ /// Define field feedbackformat to be added to grade_grades
+ $table = new XMLDBTable('grade_grades');
+ $field = new XMLDBField('feedbackformat');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'feedback');
+
+ if (!field_exists($table, $field)) {
+ /// Launch add field feedbackformat
+ $result = $result && add_field($table, $field);
+ }
+
+ /// Define field information to be added to grade_grades
+ $table = new XMLDBTable('grade_grades');
+ $field = new XMLDBField('information');
+ $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null, 'feedbackformat');
+
+ if (!field_exists($table, $field)) {
+ /// Launch add field information
+ $result = $result && add_field($table, $field);
+ }
+
+ /// Define field informationformat to be added to grade_grades
+ $table = new XMLDBTable('grade_grades');
+ $field = new XMLDBField('informationformat');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'information');
+
+ if (!field_exists($table, $field)) {
+ /// Launch add field informationformat
+ $result = $result && add_field($table, $field);
+ }
+
+ /// Define field feedback to be added to grade_grades_history
+ $table = new XMLDBTable('grade_grades_history');
+ $field = new XMLDBField('feedback');
+ $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null, 'excluded');
+
+ if (!field_exists($table, $field)) {
+ /// Launch add field feedback
+ $result = $result && add_field($table, $field);
+ }
+
+ /// Define field feedbackformat to be added to grade_grades_history
+ $table = new XMLDBTable('grade_grades_history');
+ $field = new XMLDBField('feedbackformat');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'feedback');
+
+ if (!field_exists($table, $field)) {
+ /// Launch add field feedbackformat
+ $result = $result && add_field($table, $field);
+ }
+
+ /// Define field information to be added to grade_grades_history
+ $table = new XMLDBTable('grade_grades_history');
+ $field = new XMLDBField('information');
+ $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null, 'feedbackformat');
+
+ if (!field_exists($table, $field)) {
+ /// Launch add field information
+ $result = $result && add_field($table, $field);
+ }
+
+ /// Define field informationformat to be added to grade_grades_history
+ $table = new XMLDBTable('grade_grades_history');
+ $field = new XMLDBField('informationformat');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'information');
+
+ if (!field_exists($table, $field)) {
+ /// Launch add field informationformat
+ $result = $result && add_field($table, $field);
+ }
+
+ $table = new XMLDBTable('grade_grades_text');
+ if ($result and table_exists($table)) {
+ //migrade existing data into grade_grades table - this is slow but works for all dbs,
+ //it will be executed on development sites only
+ $fields = array('feedback', 'information');
+ foreach ($fields as $field) {
+ $sql = "UPDATE {$CFG->prefix}grade_grades
+ SET $field = (
+ SELECT $field
+ FROM {$CFG->prefix}grade_grades_text ggt
+ WHERE ggt.gradeid = {$CFG->prefix}grade_grades.id)";
+ $result = execute_sql($sql) && $result;
+ }
+ $fields = array('feedbackformat', 'informationformat');
+ foreach ($fields as $field) {
+ $sql = "UPDATE {$CFG->prefix}grade_grades
+ SET $field = COALESCE((
+ SELECT $field
+ FROM {$CFG->prefix}grade_grades_text ggt
+ WHERE ggt.gradeid = {$CFG->prefix}grade_grades.id), 0)";
+ $result = execute_sql($sql) && $result;
+ }
+
+ if ($result) {
+ $tables = array('grade_grades_text', 'grade_grades_text_history');
+
+ foreach ($tables as $table) {
+ $table = new XMLDBTable($table);
+ if (table_exists($table)) {
+ drop_table($table);
+ }
+ }
+ }
+ }
+ }
/*
/// drop old gradebook tables
var $table = 'grade_categories';
/**
- * Array of class variables that are not part of the DB table fields
- * @var array $nonfields
+ * Array of required table fields, must start with 'id'.
+ * @var array $required_fields
*/
- var $nonfields = array('table', 'required_fields', 'nonfields', 'children', 'all_children', 'grade_item', 'parent_category', 'sortorder');
+ var $required_fields = array('id', 'courseid', 'parent', 'depth', 'path', 'fullname', 'aggregation',
+ 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes',
+ 'aggregatesubcats', 'timecreated', 'timemodified');
/**
* The course this category belongs to.
$usersql = "";
}
+ $grade_inst = new grade_grade();
+ $fields = 'g.'.implode(',g.', $grade_inst->required_fields);
+
// where to look for final grades - include grade of this item too, we will store the results there
$gis = implode(',', array_merge($depends_on, array($this->grade_item->id)));
- $sql = "SELECT g.*
+ $sql = "SELECT $fields
FROM {$CFG->prefix}grade_grades g, {$CFG->prefix}grade_items gi
WHERE gi.id = g.itemid AND gi.id IN ($gis) $usersql
ORDER BY g.userid";
var $table = 'grade_grades';
/**
- * Array of class variables that are not part of the DB table fields
- * @var array $nonfields
+ * Array of required table fields, must start with 'id'.
+ * @var array $required_fields
*/
- var $nonfields = array('table', 'nonfields', 'required_fields', 'grade_grade_text', 'grade_item');
+ var $required_fields = array('id', 'itemid', 'userid', 'rawgrade', 'rawgrademax', 'rawgrademin',
+ 'rawscaleid', 'usermodified', 'finalgrade', 'hidden', 'locked',
+ 'locktime', 'exported', 'overridden', 'excluded', 'timecreated', 'timemodified');
+
+ /**
+ * Array of optional fields with default values (these should match db defaults)
+ * @var array $optional_fields
+ */
+ var $optional_fields = array('feedback'=>null, 'feedbackformat'=>0, 'information'=>null, 'informationformat'=>0);
/**
* The id of the grade_item this grade belongs to.
*/
var $usermodified;
- /**
- * Additional textual information about this grade. It can be automatically generated
- * from the module or entered manually by the teacher. This is kept in its own table
- * for efficiency reasons, so it is encapsulated in its own object, and included in this grade object.
- * @var object $grade_grade_text
- */
- var $grade_grade_text;
-
/**
* The final value of this grade.
* @var float $finalgrade
*/
var $excluded = 0;
- /**
- * Loads the grade_grade_text object linked to this grade (through the intersection of itemid and userid), and
- * saves it as a class variable for this final object.
- * @return object
- */
- function load_text() {
- if (empty($this->id)) {
- return false; // text can not be attached to non existing grade
- }
-
- if (empty($this->grade_grade_text->id)) {
- $this->grade_grade_text = grade_grade_text::fetch(array('gradeid'=>$this->id));
- }
-
- return $this->grade_grade_text;
- }
-
/**
* Loads the grade_item object referenced by $this->itemid and saves it as $this->grade_item for easy access.
* @return object grade_item.
return grade_object::fetch_all_helper('grade_grades', 'grade_grade', $params);
}
-
- /**
- * Delete grade together with feedback.
- * @param string $source from where was the object deleted (mod/forum, manual, etc.)
- * @return boolean success
- */
- function delete($source=null) {
- if ($text = $this->load_text()) {
- $text->delete($source);
- }
- return parent::delete($source);
- }
-
- /**
- * Updates this grade with the given textual information. This will create a new grade_grade_text entry
- * if none was previously in DB for this raw grade, or will update the existing one.
- * @param string $information Manual information from the teacher. Could be a code like 'mi'
- * @param int $informationformat Text format for the information
- * @return boolean Success or Failure
- */
- function update_information($information, $informationformat) {
- $this->load_text();
-
- if (empty($this->grade_grade_text->id)) {
- $this->grade_grade_text = new grade_grade_text();
-
- $this->grade_grade_text->gradeid = $this->id;
- $this->grade_grade_text->userid = $this->userid;
- $this->grade_grade_text->information = $information;
- $this->grade_grade_text->informationformat = $informationformat;
-
- return $this->grade_grade_text->insert();
-
- } else {
- if ($this->grade_grade_text->information != $information
- or $this->grade_grade_text->informationformat != $informationformat) {
-
- $this->grade_grade_text->information = $information;
- $this->grade_grade_text->informationformat = $informationformat;
- return $this->grade_grade_text->update();
- } else {
- return true;
- }
- }
- }
-
- /**
- * Updates this grade with the given textual information. This will create a new grade_grade_text entry
- * if none was previously in DB for this raw grade, or will update the existing one.
- * @param string $feedback Manual feedback from the teacher. Could be a code like 'mi'
- * @param int $feedbackformat Text format for the feedback
- * @return boolean Success or Failure
- */
- function update_feedback($feedback, $feedbackformat, $usermodified=null) {
- global $USER;
-
- $this->load_text();
-
- if (empty($usermodified)) {
- $usermodified = $USER->id;
- }
-
- if (empty($this->grade_grade_text->id)) {
- $this->grade_grade_text = new grade_grade_text();
-
- $this->grade_grade_text->gradeid = $this->id;
- $this->grade_grade_text->feedback = $feedback;
- $this->grade_grade_text->feedbackformat = $feedbackformat;
- $this->grade_grade_text->usermodified = $usermodified;
-
- return $this->grade_grade_text->insert();
-
- } else {
- if ($this->grade_grade_text->feedback != $feedback
- or $this->grade_grade_text->feedbackformat != $feedbackformat) {
-
- $this->grade_grade_text->feedback = $feedback;
- $this->grade_grade_text->feedbackformat = $feedbackformat;
- $this->grade_grade_text->usermodified = $usermodified;
-
- return $this->grade_grade_text->update();
- } else {
- return true;
- }
- }
- }
-
/**
* Given a float value situated between a source minimum and a source maximum, converts it to the
* corresponding value situated between a target minimum and a target maximum. Thanks to Darlene
+++ /dev/null
-<?php // $Id$
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-require_once('grade_object.php');
-
-/**
- * A text string used to compute the value displayed by a grade_item.
- * There can be only one grade_text per grade_item (one-to-one).
- */
-class grade_grade_text extends grade_object {
- /**
- * DB Table (used by grade_object).
- * @var string $table
- */
- var $table = 'grade_grades_text';
-
- /**
- * Array of class variables that are not part of the DB table fields
- * @var array $nonfields
- */
- var $nonfields = array('table', 'required_fields', 'nonfields');
-
- /**
- * The grade_grade.id this text refers to.
- * @var int $itemid
- */
- var $gradeid;
-
- /**
- * Further information like forum rating distribution 4/5/7/0/1
- * @var string $information
- */
- var $information;
-
- /**
- * Text format for information (FORMAT_PLAIN, FORMAT_HTML etc...).
- * @var int $informationformat
- */
- var $informationformat = FORMAT_MOODLE;
-
- /**
- * Manual feedback from the teacher. This could be a code like 'mi'.
- * @var string $feedback
- */
- var $feedback;
-
- /**
- * Text format for feedback (FORMAT_PLAIN, FORMAT_HTML etc...).
- * @var int $feedbackformat
- */
- var $feedbackformat = FORMAT_MOODLE;
-
- /**
- * The userid of the person who last modified this text.
- * @var int $usermodified
- */
- var $usermodified;
-
- /**
- * Finds and returns a grade_grade_text instance based on params.
- * @static
- *
- * @param array $params associative arrays varname=>value
- * @return object grade_grade_text instance or false if none found.
- */
- function fetch($params) {
- return grade_object::fetch_helper('grade_grades_text', 'grade_grade_text', $params);
- }
-
- /**
- * Finds and returns all grade_grade_text instances based on params.
- * @static
- *
- * @param array $params associative arrays varname=>value
- * @return array array of grade_grade_text insatnces or false if none found.
- */
- function fetch_all($params) {
- return grade_object::fetch_all_helper('grade_grades_text', 'grade_grade_text', $params);
- }
-
-}
-?>
var $table = 'grade_items';
/**
- * Array of class variables that are not part of the DB table fields
- * @var array $nonfields
+ * Array of required table fields, must start with 'id'.
+ * @var array $required_fields
*/
- var $nonfields = array('table', 'nonfields', 'required_fields', 'formula', 'calculation_normalized', 'scale', 'item_category', 'parent_category', 'outcome');
+ var $required_fields = array('id', 'courseid', 'categoryid', 'itemname', 'itemtype', 'itemmodule', 'iteminstance',
+ 'itemnumber', 'iteminfo', 'idnumber', 'calculation', 'gradetype', 'grademax', 'grademin',
+ 'scaleid', 'outcomeid', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef',
+ 'sortorder', 'display', 'hidden', 'locked', 'locktime', 'needsupdate', 'timecreated',
+ 'timemodified');
/**
* The course this grade_item belongs to.
// normal grade item - just new final grades
$result = true;
+ $grade_inst = new grade_grade();
+ $fields = implode(',', $grade_inst->required_fields);
if ($userid) {
- $rs = get_recordset_select('grade_grades', "itemid={$this->id} AND userid=$userid");
+ $rs = get_recordset_select('grade_grades', "itemid={$this->id} AND userid=$userid", '', $fields);
} else {
- $rs = get_recordset('grade_grades', 'itemid', $this->id);
+ $rs = get_recordset('grade_grades', 'itemid', $this->id, '', $fields);
}
if ($rs) {
if ($rs->RecordCount() > 0) {
*/
function update_final_grade($userid, $finalgrade=false, $source=NULL, $note=NULL, $feedback=false, $feedbackformat=FORMAT_MOODLE, $usermodified=null) {
global $USER, $CFG;
+
if (empty($usermodified)) {
$usermodified = $USER->id;
}
}
$oldgrade = new object();
- $oldgrade->finalgrade = $grade->finalgrade;
- $oldgrade->overridden = $grade->overridden;
+ $oldgrade->finalgrade = $grade->finalgrade;
+ $oldgrade->overridden = $grade->overridden;
+ $oldgrade->feedback = $grade->feedback;
+ $oldgrade->feedbackformat = $grade->feedbackformat;
if ($finalgrade !== false or $feedback !== false) {
if (($this->is_outcome_item() or $this->is_manual_item()) and !$this->is_calculated()) {
$grade->finalgrade = $finalgrade;
}
+ // do we have comment from teacher?
+ if ($feedback !== false) {
+ $grade->feedback = $feedback;
+ $grade->feedbackformat = $feedbackformat;
+ }
+
if (empty($grade->id)) {
$result = (boolean)$grade->insert($source);
- } else if ($grade->finalgrade !== $oldgrade->finalgrade or $grade->overridden !== $oldgrade->overridden) {
+ } else if ($grade->finalgrade !== $oldgrade->finalgrade
+ or $grade->overridden !== $oldgrade->overridden
+ or $grade->feedback !== $oldgrade->feedback
+ or $grade->feedbackformat !== $oldgrade->feedbackformat) {
$result = $grade->update($source);
}
- // do we have comment from teacher?
- if ($result and $feedback !== false) {
- $result = $grade->update_feedback($feedback, $feedbackformat, $usermodified);
- }
-
if (!$result) {
// something went wrong - better force final grade recalculation
$this->force_regrading();
$usermodified = $USER->id;
}
+ $result = true;
+
// calculated grades can not be updated; course and category can not be updated because they are aggregated
if ($this->is_calculated() or $this->is_outcome_item() or !$this->is_normal_item()
or $this->gradetype == GRADE_TYPE_NONE or $this->is_locked()) {
}
$oldgrade = new object();
- $oldgrade->finalgrade = $grade->finalgrade;
- $oldgrade->rawgrade = $grade->rawgrade;
- $oldgrade->rawgrademin = $grade->rawgrademin;
- $oldgrade->rawgrademax = $grade->rawgrademax;
- $oldgrade->rawscaleid = $grade->rawscaleid;
+ $oldgrade->finalgrade = $grade->finalgrade;
+ $oldgrade->rawgrade = $grade->rawgrade;
+ $oldgrade->rawgrademin = $grade->rawgrademin;
+ $oldgrade->rawgrademax = $grade->rawgrademax;
+ $oldgrade->rawscaleid = $grade->rawscaleid;
+ $oldgrade->feedback = $grade->feedback;
+ $oldgrade->feedbackformat = $grade->feedbackformat;
// fist copy current grademin/max and scale
$grade->rawgrademin = $this->grademin;
$grade->rawgrademax = $this->grademax;
$grade->rawscaleid = $this->scaleid;
+ // change raw grade?
if ($rawgrade !== false) {
$grade->rawgrade = $rawgrade;
}
+ // do we have comment from teacher?
+ if ($feedback !== false) {
+ $grade->feedback = $feedback;
+ $grade->feedbackformat = $feedbackformat;
+ }
+
if (empty($grade->id)) {
$result = (boolean)$grade->insert($source);
- } else if ($grade->finalgrade !== $oldgrade->finalgrade
- or $grade->rawgrade !== $oldgrade->rawgrade
- or $grade->rawgrademin !== $oldgrade->rawgrademin
- or $grade->rawgrademax !== $oldgrade->rawgrademax
- or $grade->rawscaleid !== $oldgrade->rawscaleid) {
+ } else if ($grade->finalgrade !== $oldgrade->finalgrade
+ or $grade->rawgrade !== $oldgrade->rawgrade
+ or $grade->rawgrademin !== $oldgrade->rawgrademin
+ or $grade->rawgrademax !== $oldgrade->rawgrademax
+ or $grade->rawscaleid !== $oldgrade->rawscaleid
+ or $grade->feedback !== $oldgrade->feedback
+ or $grade->feedbackformat !== $oldgrade->feedbackformat) {
$result = $grade->update($source);
-
- } else {
- $result = true;
}
- // do we have comment from teacher?
- if ($result and $feedback !== false) {
- $result = $grade->update_feedback($feedback, $feedbackformat, $usermodified);
- }
+ if (!$result) {
+ // something went wrong - better force final grade recalculation
+ $this->force_regrading();
- if (!$this->needsupdate) {
+ } else if (!$this->needsupdate) {
$course_item = grade_item::fetch_course_item($this->courseid);
if (!$course_item->needsupdate) {
if (!grade_regrade_final_grades($this->courseid, $userid, $this)) {
$usersql = "";
}
- $sql = "SELECT g.*
+ $grade_inst = new grade_grade();
+ $fields = 'g.'.implode(',g.', $grade_inst->required_fields);
+
+ $sql = "SELECT $fields
FROM {$CFG->prefix}grade_grades g, {$CFG->prefix}grade_items gi
WHERE gi.id = g.itemid AND gi.courseid={$this->courseid} AND gi.id IN ($gis) $usersql
ORDER BY g.userid";
* @param string $formula
* @return boolean true if calculation possible, false otherwise
*/
- function validate_formula($formula) {
+ function validate_formula($formulastr) {
global $CFG;
require_once($CFG->libdir.'/mathslib.php');
- $formula = grade_item::normalize_formula($formula, $this->courseid);
+ $formulastr = grade_item::normalize_formula($formulastr, $this->courseid);
- if (empty($formula)) {
+ if (empty($formulastr)) {
return true;
}
- if (strpos($formula, '=') !== 0) {
+ if (strpos($formulastr, '=') !== 0) {
return get_string('errorcalculationnoequal', 'grades');
}
+ // get used items
+ if (preg_match_all('/##gi(\d+)##/', $formulastr, $matches)) {
+ $useditems = array_unique($matches[1]); // remove duplicates
+ } else {
+ $useditems = array();
+ }
+
+ if (!empty($this->id)) {
+ unset($useditems[$this->id]);
+ }
+
// prepare formula and init maths library
- $formula = preg_replace('/##(gi\d+)##/', '\1', $formula);
+ $formula = preg_replace('/##(gi\d+)##/', '\1', $formulastr);
$formula = new calc_formula($formula);
- // get used items
- $useditems = $this->depends_on();
if (empty($useditems)) {
$grade_items = array();
*/
class grade_object {
/**
- * Array of class variables that are not part of the DB table fields
- * @var array $nonfields
+ * Array of required table fields, must start with 'id'.
+ * @var array $required_fields
*/
- var $nonfields = array('nonfields', 'required_fields');
+ var $required_fields = array('id', 'timecreated', 'timemodified');
/**
- * Array of required fields (keys) and their default values (values).
- * @var array $required_fields
+ * Array of optional fields with default values - usually long text information that is not always needed.
+ * If you want to create an instance without optional fields use: new grade_object($only_required_fields, false);
+ * @var array $optional_fields
*/
- var $required_fields = array();
+ var $optional_fields = array();
/**
* The PK.
var $id;
/**
- * The first time this grade_calculation was created.
+ * The first time this grade_object was created.
* @var int $timecreated
*/
var $timecreated;
/**
- * The last time this grade_calculation was modified.
+ * The last time this grade_object was modified.
* @var int $timemodified
*/
var $timemodified;
* @param array $params an array with required parameters for this grade object.
* @param boolean $fetch Whether to fetch corresponding row from DB or not.
*/
- function grade_object($params=NULL, $fetch = true) {
+ function grade_object($params=NULL, $fetch=true) {
if (!empty($params) and (is_array($params) or is_object($params))) {
if ($fetch and $data = $this->fetch($params)) {
grade_object::set_properties($this, $data);
}
}
+ /**
+ * Makes sure all the optional fields are loaded.
+ * If id present (==instance exists in db) fetches data from db.
+ * Defaults are used for new instances.
+ */
+ function load_optional_fields() {
+ foreach ($this->optional_fields as $field=>$default) {
+ if (array_key_exists($field, $this)) {
+ continue;
+ }
+ if (empty($this->id)) {
+ $this->$field = $default;
+ } else {
+ $this->$field = get_field($this->table, $field, 'id', $this->id);
+ }
+ }
+ }
+
/**
* Finds and returns a grade_object instance based on params.
* @static abstract
$wheresql = array();
- // remove incorrect params - warn developer if needed
+ // remove incorrect params
foreach ($params as $var=>$value) {
- if (!in_array($var, array_keys($classvars)) or in_array($var, $instance->nonfields)) {
- debugging("Incorrect property name $var for class $classname");
+ if (!in_array($var, $instance->required_fields) and !array_key_exists($var, $instance->optional_fields)) {
continue;
}
if (is_null($value)) {
// we need to do this to prevent infinite loops in addslashes_recursive - grade_item -> category ->grade_item
$data = new object();
foreach ($this as $var=>$value) {
- if (!in_array($var, $this->nonfields)) {
+ if (in_array($var, $this->required_fields) or array_key_exists($var, $this->optional_fields)) {
if (is_object($value) or is_array($value)) {
debugging("Incorrect property '$var' found when updating grade object");
} else {
}
}
- if(!update_record($this->table, addslashes_recursive($data))) {
+ if (!update_record($this->table, addslashes_recursive($data))) {
return false;
}
// we need to do this to prevent infinite loops in addslashes_recursive - grade_item -> category ->grade_item
$data = new object();
foreach ($this as $var=>$value) {
- if (!in_array($var, $this->nonfields)) {
+ if (in_array($var, $this->required_fields) or array_key_exists($var, $this->optional_fields)) {
if (is_object($value) or is_array($value)) {
debugging("Incorrect property '$var' found when inserting grade object");
} else {
* @static final
*/
function set_properties(&$instance, $params) {
- $classvars = (array)$instance;
foreach ($params as $var => $value) {
- if (in_array($var, array_keys($classvars))) {
+ if (in_array($var, $instance->required_fields) or array_key_exists($var, $instance->optional_fields)) {
$instance->$var = $value;
}
}
var $table = 'grade_outcomes';
/**
- * Array of class variables that are not part of the DB table fields
- * @var array $nonfields
+ * Array of required table fields, must start with 'id'.
+ * @var array $required_fields
*/
- var $nonfields = array('table', 'nonfields', 'required_fields', 'scale');
+ var $required_fields = array('id', 'courseid', 'shortname', 'fullname', 'scaleid',
+ 'description', 'timecreated', 'timemodified', 'usermodified');
/**
* The course this outcome belongs to.
var $table = 'scale';
/**
- * Array of class variables that are not part of the DB table fields
- * @var array $nonfields
+ * Array of required table fields, must start with 'id'.
+ * @var array $required_fields
*/
- var $nonfields = array('table', 'nonfields', 'required_fields', 'scale_items');
+ var $required_fields = array('id', 'courseid', 'userid', 'name', 'scale', 'description', 'timemodified');
/**
* The course this scale belongs to.
$this->assertEqual(count($this->grade_grades), count($grades));
}
- function test_grade_raw_update_feedback() {
-
- }
-
- function test_grade_raw_update_information() {
-
- }
-
- function test_grade_load_text() {
- $grade_grade = new grade_grade($this->grade_grades[0]);
- $this->assertTrue(method_exists($grade_grade, 'load_text'));
- $this->assertNull($grade_grade->grade_grade_text);
- $this->assertNotNull($grade_grade->load_text());
- $this->assertNotNull($grade_grade->grade_grade_text);
- $this->assertEqual($this->grade_grades_text[0]->id, $grade_grade->grade_grade_text->id);
- }
-
function test_grade_grade_load_grade_item() {
$grade_grade = new grade_grade($this->grade_grades[0]);
$this->assertTrue(method_exists($grade_grade, 'load_grade_item'));
+++ /dev/null
-<?php // $Id$
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 1999-2004 Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-/**
- * Unit tests for grade_text object.
- *
- * @author nicolas@moodle.com
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- * @package moodlecore
- */
-
-if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
-}
-
-require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
-
-class grade_text_test extends grade_test {
-
- function test_grade_grade_text_construct() {
- $params = new stdClass();
-
- $params->gradeid = $this->grade_grades[0]->id;
- $params->information = 'Thumbs down';
- $params->informationformat = FORMAT_PLAIN;
- $params->feedback = 'Good, but not good enough..';
- $params->feedbackformat = FORMAT_PLAIN;
-
- $grade_grade_text = new grade_grade_text($params, false);
- $this->assertEqual($params->gradeid, $grade_grade_text->gradeid);
- $this->assertEqual($params->information, $grade_grade_text->information);
- $this->assertEqual($params->informationformat, $grade_grade_text->informationformat);
- $this->assertEqual($params->feedback, $grade_grade_text->feedback);
- $this->assertEqual($params->feedbackformat, $grade_grade_text->feedbackformat);
- }
-
- function test_grade_grade_text_insert() {
- global $USER;
-
- $grade_grade_text = new grade_grade_text();
- $this->assertTrue(method_exists($grade_grade_text, 'insert'));
-
- $grade_grade_text->gradeid = $this->grade_grades[0]->id;
- $grade_grade_text->information = 'Thumbs down';
- $grade_grade_text->informationformat = FORMAT_PLAIN;
- $grade_grade_text->feedback = 'Good, but not good enough..';
- $grade_grade_text->feedbackformat = FORMAT_PLAIN;
- $grade_grade_text->usermodified = $USER->id;
-
- $grade_grade_text->insert();
-
- $last_grade_grade_text = end($this->grade_grades_text);
-
- $this->assertEqual($grade_grade_text->id, $last_grade_grade_text->id + 1);
- $this->assertFalse(empty($grade_grade_text->timecreated));
- $this->assertFalse(empty($grade_grade_text->timemodified));
- $this->assertEqual($USER->id, $grade_grade_text->usermodified);
- }
-
- function test_grade_grade_text_update() {
- $grade_grade_text = new grade_grade_text($this->grade_grades_text[0]);
- $this->assertTrue(method_exists($grade_grade_text, 'update'));
-
- $this->assertTrue($grade_grade_text->update(89));
- $information = get_field('grade_grades_text', 'information', 'id', $this->grade_grades_text[0]->id);
- $this->assertEqual($grade_grade_text->information, $information);
- }
-
- function test_grade_grade_text_delete() {
- $grade_grade_text = new grade_grade_text($this->grade_grades_text[0]);
- $this->assertTrue(method_exists($grade_grade_text, 'delete'));
-
- $this->assertTrue($grade_grade_text->delete());
- $this->assertFalse(get_record('grade_grades_text', 'id', $grade_grade_text->id));
- }
-
- function test_grade_grade_text_fetch() {
- $grade_grade_text = new grade_grade_text();
- $this->assertTrue(method_exists($grade_grade_text, 'fetch'));
-
- $grade_grade_text = grade_grade_text::fetch(array('id'=>$this->grade_grades_text[0]->id));
- $this->assertEqual($this->grade_grades_text[0]->id, $grade_grade_text->id);
- $this->assertEqual($this->grade_grades_text[0]->information, $grade_grade_text->information);
- }
-
- function test_grade_grade_text_fetch_all() {
- $grade_grade_text = new grade_grade_text();
- $this->assertTrue(method_exists($grade_grade_text, 'fetch_all'));
-
- $grade_grade_texts = grade_grade_text::fetch_all(array());
- $this->assertEqual(count($this->grade_grades_text[0]), count($grade_grade_texts));
- }
-}
-?>
require_once($CFG->libdir . '/grade/grade_grade.php');
require_once($CFG->libdir . '/grade/grade_scale.php');
require_once($CFG->libdir . '/grade/grade_outcome.php');
-require_once($CFG->libdir . '/grade/grade_grade_text.php');
/***** PUBLIC GRADE API - only these functions should be used in modules *****/
//no user info
} if ($grade = $item->get_grade($userid, false)) {
- $o->grade = $grade->finalgrade;
- $o->locked = $grade->is_locked();
- $o->hidden = $grade->is_hidden();
- $o->overridden = $grade->overridden;
-
- if ($text = $grade->load_text()) {
- $o->feedback = $text->feedback;
- $o->feedbackformat = $text->feedbackformat;
- } else {
- $o->feedback = null;
- $o->feedbackformat = FORMAT_MOODLE;
- }
+ $o->grade = $grade->finalgrade;
+ $o->locked = $grade->is_locked();
+ $o->hidden = $grade->is_hidden();
+ $o->overridden = $grade->overridden;
+ $o->feedback = $text->feedback;
+ $o->feedbackformat = $text->feedbackformat;
} else {
$o->grade = null;
'scale',
'grade_items',
'grade_grades',
- 'grade_grades_text',
'grade_outcomes');
var $grade_items = array();
var $grade_categories = array();
var $grade_grades = array();
- var $grade_grades_text = array();
var $grade_outcomes = array();
var $scale = array();
$table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null);
+ $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null);
+ $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
}
- /// Define table grade_grades_text to be created
- $table = new XMLDBTable('grade_grades_text');
-
- if ($result && !table_exists($table)) {
-
- /// Adding fields to table grade_grades_text
- $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
- $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
- $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
- $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
- $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
- $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
-
- /// Adding keys to table grade_grades_text
- $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
- $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
-
- /// Launch create table for grade_grades_text
- $result = $result && create_table($table, true, false);
-
- } else {
- delete_records($table->name);
- }
-
-
/// Define table grade_outcomes to be created
$table = new XMLDBTable('grade_outcomes');
$table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null);
+ $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', XMLDB_UNSIGNED, null, null, null, null, null);
+ $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
/// Adding keys to table grade_grades_history
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
}
- /// Define table grade_grades_text to be created
- $table = new XMLDBTable('grade_grades_text_history');
-
- if ($result && !table_exists($table)) {
-
- /// Adding fields to table grade_grades_text_history
- $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
- $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
- $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
- $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
- $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
- $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
- $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
-
- /// Adding keys to table grade_grades_text_history
- $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
- $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_grades_text', array('id'));
- $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id'));
- $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
- $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
-
- /// Adding indexes to table grade_grades_text_history
- $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
-
- /// Launch create table for grade_grades_text_history
- $result = $result && create_table($table, true, false);
-
- } else {
- delete_records($table->name);
- }
-
-
/// Define table grade_outcomes to be created
$table = new XMLDBTable('grade_outcomes_history');
$grade->finalgrade = 30;
$grade->timecreated = mktime();
$grade->timemodified = mktime();
+ $grade->information = 'Thumbs down';
+ $grade->informationformat = FORMAT_PLAIN;
+ $grade->feedback = 'Good, but not good enough..';
+ $grade->feedbackformat = FORMAT_PLAIN;
if ($grade->id = insert_record('grade_grades', $grade)) {
$this->grade_grades[0] = $grade;
}
}
- /**
- * Load grade_grades_text data into the database, and adds the corresponding objects to this class' variable.
- */
- function load_grade_grades_text() {
- $grade_grades_text = new stdClass();
-
- $grade_grades_text->gradeid = $this->grade_grades[0]->id;
- $grade_grades_text->information = 'Thumbs down';
- $grade_grades_text->informationformat = FORMAT_PLAIN;
- $grade_grades_text->feedback = 'Good, but not good enough..';
- $grade_grades_text->feedbackformat = FORMAT_PLAIN;
-
- if ($grade_grades_text->id = insert_record('grade_grades_text', $grade_grades_text)) {
- $this->grade_grades_text[] = $grade_grades_text;
- }
- }
-
/**
* Load grade_outcome data into the database, and adds the corresponding objects to this class' variable.
*/
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2007092001; // YYYYMMDD = date
+ $version = 2007092002; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 Beta +'; // Human-friendly version name