Not display right answer when user gaveup the question in quiz

Not display right answer when user gaveup the question in quiz

umer Ahmed -
Number of replies: 5

I have requirement where in the quiz review I need to not display the right answer when user gave up the quiz question i.e he didnt choose any answer , this is for all qtype. do you know which function / class or file this can be updated. I am thinking it would be an if stmt to do with question state , when question state is gaveup dont set the answer, struggling to locate the piece of code where the answers are save and then displayed on the review page once the quiz has been submitted

Thank you in advance for your help


Ngā whakawākanga toharite: -
In reply to umer Ahmed

Re: Not display right answer when user gaveup the question in quiz

Tim Hunt -
Pikitia o Core developers Pikitia o Documentation writers Pikitia o Particularly helpful Moodlers Pikitia o Peer reviewers Pikitia o Plugin developers

The best way to do this would be to make a new question behaviour plugin (https://docs.moodle.org/dev/Question_behaviours). You could do one based on standard deferred feedback behaviour.

They key method to override to achieve what you want is adjust_display_options. Here is the default implementation in the base class: https://github.com/moodle/moodle/blob/master/question/behaviour/behaviourbase.php#L150.


Ngā whakawākanga toharite: Useful (1)
In reply to Tim Hunt

Re: Not display right answer when user gaveup the question in quiz

umer Ahmed -

Thanks you Tim ,  your directions were very helpful . I was able to get it work per the requirements i.e. When user gives up a question  the right answer should not display.  Added the below lines in adjust_display_options at the end.

        if ($this->qa->get_state()->is_gave_up()){

            $options->rightanswer = 0;

        }

Ngā whakawākanga toharite: -
In reply to umer Ahmed

Re: Not display right answer when user gaveup the question in quiz

Tim Hunt -
Pikitia o Core developers Pikitia o Documentation writers Pikitia o Particularly helpful Moodlers Pikitia o Peer reviewers Pikitia o Plugin developers
You might also want to set $options->generalfeedback = 0; depending of what sort of general feedback your questions have.
Ngā whakawākanga toharite: Useful (1)
In reply to Tim Hunt

Re: Not display right answer when user gaveup the question in quiz

umer Ahmed -
Yes, thank you . A quick question. Where is the rightanswer that is displayed on the review page coming from? I have tried manipulating it at couple of different objects like $attemtObj and in quba and qustionattempt and few other places but the output does not change , the string is displayed as comma separated string (the way its stored in the database. Trying to replace ";" with dashes "-"
Ngā whakawākanga toharite: -
In reply to umer Ahmed

Re: Not display right answer when user gaveup the question in quiz

umer Ahmed -
I found what I was looking for. The right answer are in an array . Under question/type/multichoice/render.php the correct_choices function implode the choices as long comma separated string. My requirement was to get a bullet list. so added the list tags in implode

/**
* Function returns string based on number of correct answers
* @param array $right An Array of correct responses to the current question
* @return string based on number of correct responses
*/
protected function correct_choices(array $right) {
// Return appropriate string for single/multiple correct answer(s).
if (count($right) == 1) {
return get_string('correctansweris', 'qtype_multichoice',
"".implode(' ', $right)."");
} else if (count($right) > 1) {
return get_string('correctanswersare', 'qtype_multichoice',
"".implode(' ', $right)."");
} else {
return "";
}
}
Ngā whakawākanga toharite: -