From e01d4a22360f0876659ecdf53a68511aaefe9c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 23 Oct 2013 11:45:18 +0200 Subject: [PATCH] MDL-42494 Fix workshop coding exception if all assessments have zero weight If all assessments for the given submission have zero weight, the grading evaluation plugin "Comparison with the best assessment" is unable to decide on the average assessment as it ignores those with zero weight. In such rare case, it makes sense to set the grading grade to null and prevent the coding exception. --- mod/workshop/eval/best/lib.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mod/workshop/eval/best/lib.php b/mod/workshop/eval/best/lib.php index d09431d53ec..954cf271d27 100644 --- a/mod/workshop/eval/best/lib.php +++ b/mod/workshop/eval/best/lib.php @@ -163,6 +163,16 @@ class workshop_best_evaluation extends workshop_evaluation { // get a hypothetical average assessment $average = $this->average_assessment($assessments); + // if unable to calculate the average assessment, set the grading grades to null + if (is_null($average)) { + foreach ($assessments as $asid => $assessment) { + if (!is_null($assessment->gradinggrade)) { + $DB->set_field('workshop_assessments', 'gradinggrade', null, array('id' => $asid)); + } + } + return; + } + // calculate variance of dimension grades $variances = $this->weighted_variance($assessments); foreach ($variances as $dimid => $variance) { @@ -272,6 +282,8 @@ class workshop_best_evaluation extends workshop_evaluation { * Given a set of a submission's assessments, returns a hypothetical average assessment * * The passed structure must be array of assessments objects with ->weight and ->dimgrades properties. + * Returns null if all passed assessments have zero weight as there is nothing to choose + * from then. * * @param array $assessments as prepared by {@link self::prepare_data_from_recordset()} * @return null|stdClass