From 5724882c2f05628a8faad1002fae2f7e90522ed9 Mon Sep 17 00:00:00 2001
From: Gordon Bateson <gordonbateson@gmail.com>
Date: Sat, 2 Jan 2016 15:33:02 +0900
Subject: [PATCH] MDL-79863 qtype_ordering: qtype_ordering fix handling of
 unscored items in grading details during review of question attempt

---
 question/type/ordering/lang/en/qtype_ordering.php |  1 +
 question/type/ordering/renderer.php               | 12 +++++++++---
 question/type/ordering/version.php                |  4 ++--
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/question/type/ordering/lang/en/qtype_ordering.php b/question/type/ordering/lang/en/qtype_ordering.php
index 45fcdd3622d..9cf1e3df4e4 100644
--- a/question/type/ordering/lang/en/qtype_ordering.php
+++ b/question/type/ordering/lang/en/qtype_ordering.php
@@ -43,6 +43,7 @@ $string['horizontal'] = 'Horizontal';
 $string['layouttype_help'] = 'Choose whether to display the items vertically or horizontally.';
 $string['layouttype'] = 'Layout of items';
 $string['noresponsedetails'] = 'Sorry, no details of the response to this question are available.';
+$string['noscore'] = 'No score';
 $string['notenoughanswers'] = 'Ordering questions must have more than {$a} answers.';
 $string['relativeallpreviousandnext'] = 'Relative to ALL the previous and next items';
 $string['relativenextexcludelast'] = 'Relative to the next item (excluding last)';
diff --git a/question/type/ordering/renderer.php b/question/type/ordering/renderer.php
index e139463ed48..01fe535cca8 100644
--- a/question/type/ordering/renderer.php
+++ b/question/type/ordering/renderer.php
@@ -209,9 +209,13 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
                         $answer = $question->answers[$answerid];
                         $score = $this->get_ordering_item_score($question, $position, $answerid);
                         list($score, $maxscore, $fraction, $percent, $class, $img) = $score;
-                        $totalscore += $score;
-                        $totalmaxscore += $maxscore;
-                        $score = "$score / $maxscore = $percent%";
+                        if ($maxscore===null) {
+                            $score = get_string('noscore', $plugin);
+                        } else {
+                            $totalscore += $score;
+                            $totalmaxscore += $maxscore;
+                            $score = "$score / $maxscore = $percent%";
+                        }
                         $scoredetails .= html_writer::tag('li', $score, $params);
                     }
 
@@ -310,6 +314,8 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
             $maxscore = null; // max score for this item
             $fraction = 0.0;  // $score / $maxscore
             $percent  = 0;    // 100 * $fraction
+            $class    = '';   // CSS class
+            $img      = '';   // icon to show correctness
 
             switch ($question->options->gradingtype) {
 
diff --git a/question/type/ordering/version.php b/question/type/ordering/version.php
index e666df3f586..c92c18eff46 100644
--- a/question/type/ordering/version.php
+++ b/question/type/ordering/version.php
@@ -31,5 +31,5 @@ $plugin->cron      = 0;
 $plugin->component = 'qtype_ordering';
 $plugin->maturity  = MATURITY_STABLE;
 $plugin->requires  = 2010112400; // Moodle 2.0
-$plugin->version   = 2016010136;
-$plugin->release   = '2016-01-01 (36)';
+$plugin->version   = 2016010237;
+$plugin->release   = '2016-01-02 (37)';