From fd7a8af50bc98df66ee1367a44a12b96a2e91bb3 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 26 Feb 2015 17:13:59 +0000 Subject: [PATCH] MDL-40990 qbehaviours: method to say if attempts can finish naturally --- question/behaviour/behaviourbase.php | 10 +++++++ .../behaviour/immediatefeedback/behaviour.php | 4 +++ question/behaviour/interactive/behaviour.php | 4 +++ question/behaviour/upgrade.txt | 26 ++++++++++++++----- question/engine/questionattempt.php | 10 +++++++ question/engine/questionusage.php | 11 ++++++++ 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/question/behaviour/behaviourbase.php b/question/behaviour/behaviourbase.php index 3cd25118681..e89ae69d710 100644 --- a/question/behaviour/behaviourbase.php +++ b/question/behaviour/behaviourbase.php @@ -84,6 +84,16 @@ abstract class question_behaviour { return substr(get_class($this), 11); } + /** + * Whether the current attempt at this question could be completed just by the + * student interacting with the question, before $qa->finish() is called. + * + * @return boolean whether the attempt can finish naturally. + */ + public function can_finish_during_attempt() { + return false; + } + /** * Cause the question to be renderered. This gets the appropriate behaviour * renderer using {@link get_renderer()}, and adjusts the display diff --git a/question/behaviour/immediatefeedback/behaviour.php b/question/behaviour/immediatefeedback/behaviour.php index f12db5d90f4..37dd21c700b 100644 --- a/question/behaviour/immediatefeedback/behaviour.php +++ b/question/behaviour/immediatefeedback/behaviour.php @@ -46,6 +46,10 @@ class qbehaviour_immediatefeedback extends question_behaviour_with_save { return $question instanceof question_automatically_gradable; } + public function can_finish_during_attempt() { + return true; + } + public function get_min_fraction() { return $this->question->get_min_fraction(); } diff --git a/question/behaviour/interactive/behaviour.php b/question/behaviour/interactive/behaviour.php index 68b83d20f37..53ede5b8cc8 100644 --- a/question/behaviour/interactive/behaviour.php +++ b/question/behaviour/interactive/behaviour.php @@ -54,6 +54,10 @@ class qbehaviour_interactive extends question_behaviour_with_multiple_tries { return $question instanceof question_automatically_gradable; } + public function can_finish_during_attempt() { + return true; + } + public function get_right_answer_summary() { return $this->question->get_right_answer_summary(); } diff --git a/question/behaviour/upgrade.txt b/question/behaviour/upgrade.txt index 3cc770a46ba..1b496d8cd67 100644 --- a/question/behaviour/upgrade.txt +++ b/question/behaviour/upgrade.txt @@ -1,14 +1,26 @@ This files describes API changes for question behaviour plugins. +=== 2.9 === + +1) New method question_behaviour::can_finish_during_attempt. This returns false + by default. You should override it if, with your behaviour, questions may + finish just through the student interacting with them (e.g. by clicking the + Check button within the question.) + + === 2.7 === -1) question_behaviour_type has a new method allows_multiple_submitted_responses which defaults to false but should return - true if this question behaviour accepts multiple submissions of responses within one attempt eg. multiple tries for the - interactive or adaptive question behaviours. - question_behaviour has a new method step_has_a_submitted_response($step). For question behaviours where it is not only the - final response that is submitted by the student, you need to override this method to return true for other steps where a - student has submitted a response. See question_behaviour_with_multiple_tries::step_has_a_submitted_response($step) for - example. This method only needs to be overriden if you are returning true from allows_multiple_response_submissions +1) question_behaviour_type has a new method allows_multiple_submitted_responses + which defaults to false but should return true if this question behaviour + accepts multiple submissions of responses within one attempt eg. multiple + tries for the interactive or adaptive question behaviours. + question_behaviour has a new method step_has_a_submitted_response($step). For + question behaviours where it is not only the final response that is + submitted by the student, you need to override this method to return true + for other steps where a student has submitted a response. See + question_behaviour_with_multiple_tries::step_has_a_submitted_response($step) + for example. This method only needs to be overriden if you are returning + true from allows_multiple_response_submissions. === 2.6 === diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index 8a59289d595..8a43d90c745 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -1163,6 +1163,16 @@ class question_attempt { return $this->rightanswer; } + /** + * Whether this attempt at this question could be completed just by the + * student interacting with the question, before {@link finish()} is called. + * + * @return boolean whether this attempt can finish naturally. + */ + public function can_finish_during_attempt() { + return $this->behaviour->can_finish_during_attempt(); + } + /** * Perform the action described by $submitteddata. * @param array $submitteddata the submitted data the determines the action. diff --git a/question/engine/questionusage.php b/question/engine/questionusage.php index ddadbfb27cf..c4ce6e90489 100644 --- a/question/engine/questionusage.php +++ b/question/engine/questionusage.php @@ -271,6 +271,17 @@ class question_usage_by_activity { return $this->get_question_attempt($slot)->get_state_class($showcorrectness); } + /** + * Whether this attempt at a given question could be completed just by the + * student interacting with the question, before {@link finish_question()} is called. + * + * @param int $slot the number used to identify this question within this usage. + * @return boolean whether the attempt at the given question can finish naturally. + */ + public function can_question_finish_during_attempt($slot) { + return $this->get_question_attempt($slot)->can_finish_during_attempt(); + } + /** * Get the time of the most recent action performed on a question. * @param int $slot the number used to identify this question within this usage.