From aa8741d9c6be63b88c71e319f2763e356b718ed1 Mon Sep 17 00:00:00 2001 From: Gordon Bateson Date: Fri, 5 Feb 2016 00:50:08 +0900 Subject: [PATCH] MDL-79863 qtype_ordering: qtype_ordering add new grading method: ALL_OR_NOTHING --- .../type/ordering/lang/en/qtype_ordering.php | 4 +++ question/type/ordering/question.php | 30 +++++++++++-------- question/type/ordering/questiontype.php | 9 +++++- question/type/ordering/renderer.php | 17 +++++++++++ question/type/ordering/version.php | 4 +-- 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/question/type/ordering/lang/en/qtype_ordering.php b/question/type/ordering/lang/en/qtype_ordering.php index cc87a44fb42..ded811e55ec 100644 --- a/question/type/ordering/lang/en/qtype_ordering.php +++ b/question/type/ordering/lang/en/qtype_ordering.php @@ -17,6 +17,7 @@ $string['pluginnamesummary'] = 'Put jumbled items into a meaningful order.'; $string['absoluteposition'] = 'Absolute position'; $string['addmoreanswers'] = 'Add {$a} more items'; +$string['allornothing'] = 'All or nothing'; $string['answer'] = 'Item text'; $string['answerheader'] = 'Draggable item {no}'; $string['correctorder'] = 'The correct order for these items is as follows:'; @@ -25,6 +26,9 @@ $string['gradedetails'] = 'Grade details'; $string['gradingtype'] = 'Grading type'; $string['gradingtype_help'] = 'Choose the type of grading calculation. +**All or nothing** +: If all items are in the correct position, then full marks are awarded. Otherwise, the score is zero. + **Absolute position** : An item is considered correct if it is in the same position as in the correct answer. The highest possible score for the question is **the same as** the number of items displayed to the student. diff --git a/question/type/ordering/question.php b/question/type/ordering/question.php index dcbdd0013b0..f8f809e83de 100644 --- a/question/type/ordering/question.php +++ b/question/type/ordering/question.php @@ -41,13 +41,14 @@ class qtype_ordering_question extends question_graded_automatically { const LAYOUT_VERTICAL = 0; const LAYOUT_HORIZONTAL = 1; - const GRADING_ABSOLUTE_POSITION = 0; - const GRADING_RELATIVE_NEXT_EXCLUDE_LAST = 1; - const GRADING_RELATIVE_NEXT_INCLUDE_LAST = 2; - const GRADING_RELATIVE_ONE_PREVIOUS_AND_NEXT = 3; - const GRADING_RELATIVE_ALL_PREVIOUS_AND_NEXT = 4; - const GRADING_LONGEST_ORDERED_SUBSET = 5; - const GRADING_LONGEST_CONTIGUOUS_SUBSET = 6; + const GRADING_ALL_OR_NOTHING = -1; + const GRADING_ABSOLUTE_POSITION = 0; + const GRADING_RELATIVE_NEXT_EXCLUDE_LAST = 1; + const GRADING_RELATIVE_NEXT_INCLUDE_LAST = 2; + const GRADING_RELATIVE_ONE_PREVIOUS_AND_NEXT = 3; + const GRADING_RELATIVE_ALL_PREVIOUS_AND_NEXT = 4; + const GRADING_LONGEST_ORDERED_SUBSET = 5; + const GRADING_LONGEST_CONTIGUOUS_SUBSET = 6; /** fields from "qtype_ordering_options" */ public $correctfeedback; @@ -87,21 +88,21 @@ class qtype_ordering_question extends question_graded_automatically { // ensure consistency between "selecttype" and "selectcount" switch (true) { - case ($selecttype==0): $selectcount = $countanswers; break; - case ($selectcount==$countanswers): $selecttype = 0; break; + case ($selecttype==self::SELECT_ALL): $selectcount = $countanswers; break; + case ($selectcount==$countanswers): $selecttype = self::SELECT_ALL; break; } // extract answer ids switch ($selecttype) { - case 0: // all + case self::SELECT_ALL: $answerids = array_keys($answers); break; - case 1: // random subset + case self::SELECT_RANDOM: $answerids = array_rand($answers, $selectcount); break; - case 2: // contiguous subset + case self::SELECT_CONTIGUOUS: $answerids = array_keys($answers); $offset = mt_rand(0, $countanswers - $selectcount); $answerids = array_slice($answerids, $offset, $selectcount, true); @@ -172,6 +173,7 @@ class qtype_ordering_question extends question_graded_automatically { $options = $this->get_ordering_options(); switch ($options->gradingtype) { + case self::GRADING_ALL_OR_NOTHING: case self::GRADING_ABSOLUTE_POSITION: $correctresponse = $this->correctresponse; $currentresponse = $this->currentresponse; @@ -183,6 +185,9 @@ class qtype_ordering_question extends question_graded_automatically { } $countanswers++; } + if ($options->gradingtype==self::GRADING_ALL_OR_NOTHING && $countcorrect < $countanswers) { + $countcorrect = 0; + } break; case self::GRADING_RELATIVE_NEXT_EXCLUDE_LAST: @@ -472,6 +477,7 @@ class qtype_ordering_question extends question_graded_automatically { static public function get_grading_types($type=null) { $plugin = 'qtype_ordering'; $types = array( + self::GRADING_ALL_OR_NOTHING => get_string('allornothing', $plugin), self::GRADING_ABSOLUTE_POSITION => get_string('absoluteposition', $plugin), self::GRADING_RELATIVE_NEXT_EXCLUDE_LAST => get_string('relativenextexcludelast', $plugin), self::GRADING_RELATIVE_NEXT_INCLUDE_LAST => get_string('relativenextincludelast', $plugin), diff --git a/question/type/ordering/questiontype.php b/question/type/ordering/questiontype.php index 8e6eefa2778..77068bfb3f7 100644 --- a/question/type/ordering/questiontype.php +++ b/question/type/ordering/questiontype.php @@ -352,7 +352,8 @@ class qtype_ordering extends question_type { 'CONTIGUOUS|CONTIG)?'; $layouttype = '(?:HORIZONTAL|HORI|H|1|'. 'VERTICAL|VERT|V|0)?'; - $gradingtype = '(?:ABSOLUTE_POSITION|'. + $gradingtype = '(?:ALL_OR_NOTHING|'. + 'ABSOLUTE_POSITION|'. 'ABSOLUTE|ABS|'. 'RELATIVE_NEXT_EXCLUDE_LAST|'. 'RELATIVE_NEXT_INCLUDE_LAST|'. @@ -471,6 +472,9 @@ class qtype_ordering extends question_type { } switch ($question->options->gradingtype) { + case qtype_ordering_question::GRADING_ALL_OR_NOTHING: + $grading = 'ALL_OR_NOTHING'; + break; case qtype_ordering_question::GRADING_ABSOLUTE_POSITION: $grading = 'ABSOLUTE_POSITION'; break; @@ -711,6 +715,9 @@ class qtype_ordering extends question_type { // set "gradingtype" from $grading switch (strtoupper($grading)) { + case 'ALL_OR_NOTHING': + $gradingtype = qtype_ordering_question::GRADING_ALL_OR_NOTHING; + break; case 'ABS': case 'ABSOLUTE': case 'ABSOLUTE_POSITION': diff --git a/question/type/ordering/renderer.php b/question/type/ordering/renderer.php index eceffb0aeab..10bd0e9fc34 100644 --- a/question/type/ordering/renderer.php +++ b/question/type/ordering/renderer.php @@ -43,6 +43,8 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer { protected $currentinfo = null; protected $itemscores = array(); + protected $all_correct = null; + public function formulation_and_controls(question_attempt $qa, question_display_options $options) { global $CFG, $DB; @@ -275,6 +277,7 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer { $gradingtype = $question->options->gradingtype; switch ($gradingtype) { + case qtype_ordering_question::GRADING_ALL_OR_NOTHING: case qtype_ordering_question::GRADING_ABSOLUTE_POSITION: $this->correctinfo = $question->correctresponse; $this->currentinfo = $question->currentresponse; @@ -308,6 +311,13 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer { } } + protected function is_all_correct() { + if ($this->all_correct===null) { + $this->all_correct = ($this->correctinfo==$this->currentinfo); // array comparison + } + return $this->all_correct; + } + protected function get_ordering_item_score($question, $position, $answerid) { if (! isset($this->itemscores[$position])) { @@ -328,6 +338,13 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer { switch ($question->options->gradingtype) { + case qtype_ordering_question::GRADING_ALL_OR_NOTHING: + if ($this->is_all_correct()) { + $score = 1; + } + $maxscore = 1; + break; + case qtype_ordering_question::GRADING_ABSOLUTE_POSITION: if (isset($correctinfo[$position])) { if ($correctinfo[$position]==$answerid) { diff --git a/question/type/ordering/version.php b/question/type/ordering/version.php index 73e033dfe46..8f677fdd1e7 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 = 2016022441; -$plugin->release = '2016-02-24 (41)'; +$plugin->version = 2016022442; +$plugin->release = '2016-02-24 (42)';