Problem/Motivation

Question type may need to know when user retry a question — change question details, log incorrects, change max score, …

For sure, the module can alter the form to add custom element validate, … but it's not nice as include the logic in handler class.

Proposed resolution

Add new item to contract: QuizResponse(Interface)::onRepeatUntilCorrect()

  /**
   * Method is called when user retry.
   * @param Result $result
   * @param array $element
   */
  public function onRepeatUntiCorrect(Result $result, array &$element);

Comments

djdevin’s picture

This will already happen in #2391723: Normalize data storage for question responses. It won't be Question-specific, so I don't think the question types need to know about it. The logging of answers will happen the normal way that a Question stores the response. Will probably get into 5.x as well.

The build on last attempt functionality is already able to clone question responses regardless of the question type, so we will just keep writing question responses for each attempt.

thehong’s picture

My question type would like to do somethings:

- Log things, yeah just for this question type
- Says something to taker when they retry (until correct)
- Change the logic to display question on retry
- …

I think it's much easier with this event supporting.

djdevin’s picture

Don't we already have that, since you have the entity operation for quiz_result_answer?

I'm using this in production right now to do that sort of thing.

thehong’s picture

Ok, you decide it. But I want draft the code with & without this:


function my_module_quiz_result_answer_update($answer) {
  $question = quiz_question_load($answer->question_id);
  $quiz = $answer->getQuiz();
  if ($question->type = 'my_type' && $quiz->isAllowRepeatUntilCorrect()) {
    // …
  }
}

class MyQuestionHandler {
  public function onRepeatUntileCorrect() {
    
  }
}

djdevin’s picture

Sure you can just submit a patch and we will check it out.

The other thing to keep in mind is that if you want to build custom one off events like this you are going to lose out on things like Rules and stuff :(

djdevin’s picture

Status: Active » Closed (won't fix)

Instead of the custom solution proposed here, this was done in an Entity compatible way in #2391723: Normalize data storage for question responses