Permalink
Browse files

MDL-29481: when student is being regraded we try to pick up the lates…

…t saved but not submitted version of grading

There are no visible changes yet because at the moment rubric is only saved when it is submitted but this is a base for AJAX saving
  • Loading branch information...
1 parent 13926e7 commit 188e840b99cd728b00aff9242bd786a932bfeb30 @marinaglancy marinaglancy committed Nov 7, 2011
View
17 grade/grading/form/lib.php
@@ -694,12 +694,25 @@ public function get_controller() {
}
/**
+ * Returns the specified element from object $this->data
+ *
+ * @param string $key
+ * @return mixed
+ */
+ public function get_data($key) {
+ if (isset($this->data->$key)) {
+ return $this->data->$key;
+ }
+ return null;
+ }
+
+ /**
* Returns instance id
*
* @return int
*/
public function get_id() {
- return $this->data->id;
+ return $this->get_data('id');
}
/**
@@ -708,7 +721,7 @@ public function get_id() {
* @return int
*/
public function get_status() {
- return $this->data->status;
+ return $this->get_data('status');
}
/**
View
1 grade/grading/form/rubric/lang/en/gradingform_rubric.php
@@ -82,5 +82,6 @@
$string['needregrademessage'] = 'Rubric definition was changed after this student had been graded. You must update the grade otherwise it will not be shown to student.';
$string['rubricnotcompleted'] = 'Please choose something for each criterion';
+$string['restoredfromdraft'] = 'Please note: You did not submit the last attempt to grade this person. The grading is restored from draft. To cancel the changes press "Cancel" button below';
$string['backtoediting'] = 'Back to editing';
View
47 grade/grading/form/rubric/lib.php
@@ -484,6 +484,36 @@ protected function delete_plugin_definition() {
}
/**
+ * If instanceid is specified and grading instance exists and it is created by this rater for
+ * this item, this instance is returned.
+ * If there exists a draft for this raterid+itemid, take this draft (this is the change from parent)
+ * 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);
+ }
+ if ($itemid && $raterid) {
+ if ($rs = $DB->get_records('grading_instances', array('raterid' => $raterid, 'itemid' => $itemid), 'timemodified DESC', '*', 0, 1)) {
+ $record = reset($rs);
+ $currentinstance = $this->get_current_instance($raterid, $itemid);
+ if ($record->status == gradingform_rubric_instance::INSTANCE_STATUS_INCOMPLETE && $record->timemodified > $currentinstance->get_data('timemodified')) {
+ $record->isrestored = true;
+ return $this->get_instance($record);
+ }
+ }
+ }
+ return $this->create_instance($raterid, $itemid);
+ }
+
+ /**
* Returns html code to be included in student's feedback.
*
* @param moodle_page $page
@@ -725,6 +755,23 @@ public function render_grading_element($page, $gradingformelement) {
if ($currentinstance && $currentinstance->get_status() == gradingform_instance::INSTANCE_STATUS_NEEDUPDATE) {
$html .= html_writer::tag('div', get_string('needregrademessage', 'gradingform_rubric'), array('class' => 'gradingform_rubric-regrade'));
}
+ $haschanges = false;
+ if ($currentinstance) {
+ $curfilling = $currentinstance->get_rubric_filling();
+ foreach ($curfilling['criteria'] as $criterionid => $curvalues) {
+ $value['criteria'][$criterionid]['savedlevelid'] = $curvalues['levelid'];
+ $newremark = null;
+ $newlevelid = null;
+ if (isset($value['criteria'][$criterionid]['remark'])) $newremark = $value['criteria'][$criterionid]['remark'];
+ if (isset($value['criteria'][$criterionid]['levelid'])) $newlevelid = $value['criteria'][$criterionid]['levelid'];
+ if ($newlevelid != $curvalues['levelid'] || $newremark != $curvalues['remark']) {
+ $haschanges = true;
+ }
+ }
+ }
+ if ($this->get_data('isrestored') && $haschanges) {
+ $html .= html_writer::tag('div', get_string('restoredfromdraft', 'gradingform_rubric'), array('class' => 'gradingform_rubric-restored'));
+ }
$html .= $this->get_controller()->get_renderer($page)->display_rubric($criteria, $options, $mode, $gradingformelement->getName(), $value);
return $html;
}
View
3 grade/grading/form/rubric/renderer.php
@@ -355,6 +355,9 @@ public function display_rubric($criteria, $options, $mode, $elementname = null,
$level['class'] .= ' checked';
//in mode DISPLAY_EVAL the class 'checked' will be added by JS if it is enabled. If JS is not enabled, the 'checked' class will only confuse
}
+ if (isset($criterionvalue['savedlevelid']) && ((int)$criterionvalue['savedlevelid'] === $levelid)) {
+ $level['class'] .= ' currentchecked';
+ }
$level['tdwidth'] = 100/count($criterion['levels']);
$levels_str .= $this->level_template($mode, $options, $elementname, $id, $level);
}
View
2 grade/grading/form/rubric/styles.css
@@ -82,6 +82,7 @@
.gradingform_rubric.editor .criterion.last .controls .movedown input {display:none;}
/* evaluation */
+.gradingform_rubric .criterion .levels .level.currentchecked {background:#fff0f0;}
.gradingform_rubric .criterion .levels .level.checked {background:#d0ffd0;border:1px solid #555;}
.gradingform_rubric.evaluate .criterion .levels .level:hover {background:#30ff30;}
@@ -114,4 +115,5 @@
*/
.gradingform_rubric-regrade {padding:10px;background:#FFDDDD;border:1px solid #F00;margin-bottom:10px;}
+.gradingform_rubric-restored {padding:10px;background:#FFFFDD;border:1px solid #FF0;margin-bottom:10px;}
.gradingform_rubric-error {color:red;font-weight:bold;}

0 comments on commit 188e840

Please sign in to comment.