MDL-29483: allow the grading instance to exist without itemid until submitting (submission in assignment might not yet existed)
This commit is contained in:
@@ -368,10 +368,10 @@ abstract class gradingform_controller {
|
||||
* @param int $itemid
|
||||
* @return gradingform_instance
|
||||
*/
|
||||
public function create_instance($raterid, $itemid) {
|
||||
public function create_instance($raterid, $itemid = null) {
|
||||
global $DB;
|
||||
// first find if there is already an active instance for this itemid
|
||||
if ($current = $this->get_current_instance($raterid, $itemid)) {
|
||||
if ($itemid && $current = $this->get_current_instance($raterid, $itemid)) {
|
||||
return $this->get_instance($current->copy($raterid, $itemid));
|
||||
} else {
|
||||
$class = 'gradingform_'. $this->get_method_name(). '_instance';
|
||||
@@ -588,6 +588,9 @@ abstract class gradingform_instance {
|
||||
// already active
|
||||
return;
|
||||
}
|
||||
if (empty($this->data->itemid)) {
|
||||
throw new coding_exception('You cannot mark active the grading instance without itemid');
|
||||
}
|
||||
$currentid = $this->get_controller()->get_current_instance($this->data->raterid, $this->data->itemid, true);
|
||||
if ($currentid) {
|
||||
if ($currentid != $this->get_id()) {
|
||||
@@ -618,9 +621,22 @@ abstract class gradingform_instance {
|
||||
* Updates the instance with the data received from grading form. This function may be
|
||||
* called via AJAX when grading is not yet completed, so it does not change the
|
||||
* status of the instance.
|
||||
*
|
||||
* @param array $elementvalue
|
||||
*/
|
||||
public function update($elementvalue) {
|
||||
// TODO update timemodified at least
|
||||
global $DB;
|
||||
$newdata = new stdClass();
|
||||
$newdata->id = $this->get_id();
|
||||
$newdata->timemodified = time();
|
||||
if (isset($elementvalue['itemid']) && $elementvalue['itemid'] != $this->data->itemid) {
|
||||
$newdata->itemid = $elementvalue['itemid'];
|
||||
}
|
||||
// TODO also update: rawgrade, feedback, feedbackformat
|
||||
$DB->update_record('grading_instances', $newdata);
|
||||
foreach ($newdata as $key => $value) {
|
||||
$this->data->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -632,10 +648,16 @@ abstract class gradingform_instance {
|
||||
|
||||
/**
|
||||
* Called when teacher submits the grading form:
|
||||
* updates the instance in DB, marks it as ACTIVE and returns the grade to be pushed to the gradebook
|
||||
* updates the instance in DB, marks it as ACTIVE and returns the grade to be pushed to the gradebook.
|
||||
* $itemid must be specified here (it was not required when the instance was
|
||||
* created, because it might not existed in draft)
|
||||
*
|
||||
* @param array $elementvalue
|
||||
* @param int $itemid
|
||||
* @return int the grade on 0-100 scale
|
||||
*/
|
||||
public function submit_and_get_grade($elementvalue) {
|
||||
public function submit_and_get_grade($elementvalue, $itemid) {
|
||||
$elementvalue['itemid'] = $itemid;
|
||||
$this->update($elementvalue);
|
||||
$this->make_active();
|
||||
return $this->get_grade();
|
||||
|
||||
@@ -457,11 +457,13 @@ class gradingform_rubric_instance extends gradingform_instance {
|
||||
* Updates the instance with the data received from grading form. This function may be
|
||||
* called via AJAX when grading is not yet completed, so it does not change the
|
||||
* status of the instance.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function update($data) {
|
||||
global $DB;
|
||||
$currentgrade = $this->get_rubric_filling();
|
||||
parent::update($data); // TODO ? +timemodified
|
||||
parent::update($data);
|
||||
foreach ($data['criteria'] as $criterionid => $record) {
|
||||
if (!array_key_exists($criterionid, $currentgrade['criteria'])) {
|
||||
$newrecord = array('forminstanceid' => $this->get_id(), 'criterionid' => $criterionid,
|
||||
|
||||
@@ -1067,11 +1067,11 @@ class assignment_base {
|
||||
$mformdata->fileui_options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||
}
|
||||
if ($controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) {
|
||||
if (!isset($submission->id)) {
|
||||
// we create a submission if it does not exist yet because we need submission->id for grading
|
||||
$mformdata->submission = $this->get_submission($user->id, true);
|
||||
$itemid = null;
|
||||
if (!empty($submission->id)) {
|
||||
$itemid = $submission->id;
|
||||
}
|
||||
$mformdata->advancedgradinginstance = $controller->create_instance($USER->id, $mformdata->submission->id);
|
||||
$mformdata->advancedgradinginstance = $controller->create_instance($USER->id, $itemid);
|
||||
}
|
||||
|
||||
$submitform = new mod_assignment_grading_form( null, $mformdata );
|
||||
@@ -1613,7 +1613,9 @@ class assignment_base {
|
||||
// preprocess advanced grading here
|
||||
if ($gradinginstance) {
|
||||
$data = $mform->get_data();
|
||||
$_POST['xgrade'] = $gradinginstance->submit_and_get_grade($data->advancedgrading);
|
||||
// create submission if it did not exist yet because we need submission->id for storing the grading instance
|
||||
$submission = $this->get_submission($userid, true);
|
||||
$_POST['xgrade'] = $gradinginstance->submit_and_get_grade($data->advancedgrading, $submission->id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user