MDL-30159: fixed bug: When evaluating by advanced grading extra entries are inserted in grading_instances

This commit is contained in:
Marina Glancy 2011-11-07 14:37:58 +08:00
parent ffbf4370a2
commit 13926e735d
2 changed files with 23 additions and 1 deletions

View File

@ -448,6 +448,25 @@ abstract class gradingform_controller {
}
}
/**
* If instanceid is specified and grading instance exists and it is created by this rater for
* this item, this instance is returned.
* Otherwise new instance is created for the specified rater and itemid
*
* @param int $instanceid
* @param int $raterid
* @param int $itemid
* @return gradingform_instance
*/
public function get_or_create_instance($instanceid, $raterid, $itemid) {
global $DB;
if ($instanceid &&
$instance = $DB->get_record('grading_instances', array('id' => $instanceid, 'raterid' => $raterid, 'itemid' => $itemid), '*', IGNORE_MISSING)) {
return $this->get_instance($instance);
}
return $this->create_instance($raterid, $itemid);
}
/**
* Returns the HTML code displaying the preview of the grading form
*

View File

@ -615,6 +615,7 @@ class assignment_base {
//make user global so we can use the id
global $USER, $OUTPUT, $DB, $PAGE;
$mailinfo = optional_param('mailinfo', null, PARAM_BOOL);
if (optional_param('next', null, PARAM_BOOL)) {
@ -1077,7 +1078,8 @@ class assignment_base {
if (!empty($submission->id)) {
$itemid = $submission->id;
}
$mformdata->advancedgradinginstance = $controller->create_instance($USER->id, $itemid);
$instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT);
$mformdata->advancedgradinginstance = $controller->get_or_create_instance($instanceid, $USER->id, $itemid);
} else {
$advancedgradingwarning = $controller->form_unavailable_notification();
}
@ -2389,6 +2391,7 @@ class mod_assignment_grading_form extends moodleform {
$grademenu = make_grades_menu($this->_customdata->assignment->grade);
if ($gradinginstance = $this->use_advanced_grading()) {
$mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id());
$gradinginstance->get_controller()->set_grade_range($grademenu);
$mform->addElement('grading', 'advancedgrading', get_string('grade').':', array('gradinginstance' => $gradinginstance));
} else {