From 2e473e62734f5339fd57184b8ffc33fd1ed90cfd Mon Sep 17 00:00:00 2001 From: Gordon Bateson Date: Thu, 29 Nov 2018 23:11:15 +0900 Subject: [PATCH] MDL-79863 qtype_ordering: qtype/ordering fix detection of Longest ordered/contiguous subset where two or more such subsets exist --- question/type/ordering/question.php | 29 ++++++++++++++++++++--------- question/type/ordering/version.php | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/question/type/ordering/question.php b/question/type/ordering/question.php index e5ebd636124..a6c60ca03c7 100644 --- a/question/type/ordering/question.php +++ b/question/type/ordering/question.php @@ -700,8 +700,11 @@ class qtype_ordering_question extends question_graded_automatically { * @param integer $imax the length of the $positions array * @param integer $imin (optional, default = 0) the index in $position at which to start checking values * @param integer $previous (optional, default = -1) the minimum allowed value. Any values less than this will be skipped. + * @param integer $initial (optional, default = -1) the value of the initial item in this subset. Values less than this will be skipped. + * + * @return array of ordered subsets from within the positions array */ - public function get_ordered_subsets($positions, $contiguous, $imax, $imin=0, $previous=-1) { + public function get_ordered_subsets($positions, $contiguous, $imax, $imin=0, $previous=-1, $initial=-1) { // Var $subsets is the collection of all subsets within $positions. $subsets = array(); @@ -714,25 +717,33 @@ class qtype_ordering_question extends question_graded_automatically { switch (true) { - case ($previous < 0 || $current == ($previous + 1)): - // First item, or next item in a contiguous sequence - // there is no need to search for $tailsets. + case ($current < $initial): + // Current item is less than the initial item, so ignore it. + $tailsets = array(); + $prependsubset = false; + $appendtosubset = false; + break; + + case ($previous < 0): + case ($current == ($previous + 1)): + // First item, or next item in a contiguous sequence. + // There is no need to search for $tailsets. $tailsets = array(); $prependsubset = false; $appendtosubset = true; break; - case ($current < $previous || ($contiguous && $current > ($previous + 1))): + case ($current < $previous): + case ($contiguous && $current > ($previous + 1)): // Here $current breaks the sequence, so look for subsets that start here. - $tailsets = $this->get_ordered_subsets($positions, $contiguous, $imax, $i); + $tailsets = $this->get_ordered_subsets($positions, $contiguous, $imax, $i, -1, $current); $prependsubset = false; $appendtosubset = false; break; case ($current > $previous): - // A non-contiguous sequence, - // so search for subsets in the tail. - $tailsets = $this->get_ordered_subsets($positions, $contiguous, $imax, $i + 1, $previous); + // A non-contiguous sequence, so search for subsets in the tail. + $tailsets = $this->get_ordered_subsets($positions, $contiguous, $imax, $i + 1, $previous, $current); $prependsubset = true; $appendtosubset = true; break; diff --git a/question/type/ordering/version.php b/question/type/ordering/version.php index 42706fa075d..d17f4c2a77f 100644 --- a/question/type/ordering/version.php +++ b/question/type/ordering/version.php @@ -29,5 +29,5 @@ $plugin->cron = 0; $plugin->component = 'qtype_ordering'; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2010112400; // Moodle 2.0 -$plugin->version = 2018112674; -$plugin->release = '2018-11-26 (74)'; +$plugin->version = 2018112975; +$plugin->release = '2018-11-29 (75)';