diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index fa110dd..d8bc826 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -408,6 +408,21 @@ class question_attempt { return end($this->steps); } + + /** + * Return the second last step in this question_attempt. + * For internal/test code use only. + * @return question_attempt_step + */ + public function get_second_last_step() { + if (count($this->steps) == 0) { + return new question_null_step(); + } + end($this->steps); + return prev($this->steps); + } + + /** * @return boolean whether this question_attempt has autosaved data from * some time in the past. @@ -1230,6 +1245,16 @@ class question_attempt { public function process_action($submitteddata, $timestamp = null, $userid = null, $existingstepid = null) { $pendingstep = new question_attempt_pending_step($submitteddata, $timestamp, $userid, $existingstepid); $this->discard_autosaved_step(); + + /** While clearing the quiz option,we are trying to bring the question state to 'todo' + * and question attempt step data to '_order' and we could find that '_order' data only in initial step + * i.e step[0] **/ + if( empty($submitteddata)){ + // $pendingstep->set_state(question_state::$todo); + $step_zero_data= $this->steps[0]->get_all_data(); + $pendingstep->set_data($step_zero_data); + } + if ($this->behaviour->process_action($pendingstep) == self::KEEP) { $this->add_step($pendingstep); if ($pendingstep->response_summary_changed()) { diff --git a/question/engine/questionattemptstep.php b/question/engine/questionattemptstep.php index c0bb6fd..9b45ccd 100644 --- a/question/engine/questionattemptstep.php +++ b/question/engine/questionattemptstep.php @@ -358,6 +358,7 @@ class question_attempt_step { return $result; } + /** * Get all the data. behaviour variables have the - at the start of * their name. This is only intended for internal use, for example by @@ -370,6 +371,12 @@ class question_attempt_step { return $this->data; } + /** Setting Step Data **/ + public function set_data($data){ + $this->data = $data; + } + + /** * Set a metadata variable. * diff --git a/question/type/multichoice/question.php b/question/type/multichoice/question.php index 09b9493..443b1c7 100644 --- a/question/type/multichoice/question.php +++ b/question/type/multichoice/question.php @@ -259,7 +259,15 @@ class qtype_multichoice_single_question extends qtype_multichoice_base { } public function get_response(question_attempt $qa) { - return $qa->get_last_qt_var('answer', -1); + $laststep = $qa->get_last_step(); // getting last step data instead of just getting step containing latest 'answer' + $laststep_name = key($laststep->get_all_data()); + if($laststep_name == '-finish'){ + $second_laststep = $qa->get_second_last_step(); + $second_laststep_name = key($second_laststep->get_all_data()); + return $qa->get_last_qt_var($second_laststep_name, -1); + } else { + return $qa->get_last_qt_var($laststep_name, -1); + } } public function is_choice_selected($response, $value) {