Skip to content

Commit

Permalink
MDL-40990 qbehaviours: method to say if attempts can finish naturally
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Mar 13, 2015
1 parent 06122e4 commit fd7a8af
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
10 changes: 10 additions & 0 deletions question/behaviour/behaviourbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public function get_name() {
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
Expand Down
4 changes: 4 additions & 0 deletions question/behaviour/immediatefeedback/behaviour.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function is_compatible_question(question_definition $question) {
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();
}
Expand Down
4 changes: 4 additions & 0 deletions question/behaviour/interactive/behaviour.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public function is_compatible_question(question_definition $question) {
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();
}
Expand Down
26 changes: 19 additions & 7 deletions question/behaviour/upgrade.txt
Original file line number Diff line number Diff line change
@@ -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 ===
Expand Down
10 changes: 10 additions & 0 deletions question/engine/questionattempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,16 @@ public function get_right_answer_summary() {
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.
Expand Down
11 changes: 11 additions & 0 deletions question/engine/questionusage.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ public function get_question_state_class($slot, $showcorrectness) {
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.
Expand Down

0 comments on commit fd7a8af

Please sign in to comment.