MDL-45848 grading: Added ability to unset grades with advanced grading

Thanks to Mohamed Alsharaf for assistance on this patch
This commit is contained in:
Dave Cooper
2015-01-13 09:19:11 +08:00
parent edbcfbd61f
commit 93023ceef4
4 changed files with 97 additions and 4 deletions
+33
View File
@@ -756,6 +756,26 @@ class gradingform_guide_instance extends gradingform_instance {
return $instanceid;
}
/**
* Determines whether the submitted form was empty.
*
* @param array $elementvalue value of element submitted from the form
* @return boolean true if the form is empty
*/
public function is_empty_form($elementvalue) {
$criteria = $this->get_controller()->get_definition()->guide_criteria;
foreach ($criteria as $id => $criterion) {
$score = $elementvalue['criteria'][$id]['score'];
$remark = $elementvalue['criteria'][$id]['remark'];
if ((isset($score) && $score !== '')
|| ((isset($remark) && $remark !== ''))) {
return false;
}
}
return true;
}
/**
* Validates that guide is fully completed and contains valid grade on each criterion
*
@@ -843,6 +863,19 @@ class gradingform_guide_instance extends gradingform_instance {
$this->get_guide_filling(true);
}
/**
* Removes the attempt from the gradingform_guide_fillings table
* @param array $data the attempt data
*/
public function clear_attempt($data) {
global $DB;
foreach ($data['criteria'] as $criterionid => $record) {
$DB->delete_records('gradingform_guide_fillings',
array('criterionid' => $criterionid, 'instanceid' => $this->get_id()));
}
}
/**
* Calculates the grade to be pushed to the gradebook
*
+27 -1
View File
@@ -935,6 +935,28 @@ abstract class gradingform_instance {
*/
abstract public function get_grade();
/**
* Determines whether the submitted form was empty.
*
* @param array $elementvalue value of element submitted from the form
* @return boolean true if the form is empty
*/
public function is_empty_form($elementvalue) {
return false;
}
/**
* Removes the attempt from the gradingform_*_fillings table.
* This function is not abstract as to not break plugins that might
* use advanced grading.
* @param array $data the attempt data
*/
public function clear_attempt($data) {
// This function is empty because the way to clear a grade
// attempt will be different depending on the grading method.
return;
}
/**
* 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.
@@ -947,12 +969,16 @@ abstract class gradingform_instance {
*/
public function submit_and_get_grade($elementvalue, $itemid) {
$elementvalue['itemid'] = $itemid;
if ($this->is_empty_form($elementvalue)) {
$this->clear_attempt($elementvalue);
$this->make_active();
return -1;
}
$this->update($elementvalue);
$this->make_active();
return $this->get_grade();
}
/**
* Returns html for form element of type 'grading'. If there is a form input element
* it must have the name $gradingformelement->getName().
+31
View File
@@ -756,6 +756,37 @@ class gradingform_rubric_instance extends gradingform_instance {
return $instanceid;
}
/**
* Determines whether the submitted form was empty.
*
* @param array $elementvalue value of element submitted from the form
* @return boolean true if the form is empty
*/
public function is_empty_form($elementvalue) {
$criteria = $this->get_controller()->get_definition()->rubric_criteria;
foreach ($criteria as $id => $criterion) {
if (isset($elementvalue['criteria'][$id]['levelid'])
|| !empty($elementvalue['criteria'][$id]['remark'])) {
return false;
}
}
return true;
}
/**
* Removes the attempt from the gradingform_guide_fillings table
* @param array $data the attempt data
*/
public function clear_attempt($data) {
global $DB;
foreach ($data['criteria'] as $criterionid => $record) {
$DB->delete_records('gradingform_rubric_fillings',
array('criterionid' => $criterionid, 'instanceid' => $this->get_id()));
}
}
/**
* Validates that rubric is fully completed and contains valid grade on each criterion
*
+6 -3
View File
@@ -138,11 +138,14 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
* Function registered as rule for this element and is called when this element is being validated.
* This is a wrapper to pass the validation to the method gradingform_instance::validate_grading_element
*
* @param mixed $elementValue value of element to be validated
* @param mixed $elementvalue value of element to be validated
* @param array $attributes element attributes
* @return MoodleQuickForm_grading
*/
static function _validate($elementValue, $attributes = null) {
return $attributes['gradinginstance']->validate_grading_element($elementValue);
public static function _validate($elementvalue, $attributes = null) {
if (!$attributes['gradinginstance']->is_empty_form($elementvalue)) {
return $attributes['gradinginstance']->validate_grading_element($elementvalue);
}
return true;
}
}