Highlight correct answers during Review Question

Highlight correct answers during Review Question

by Han Sheng Ler -
Number of replies: 8

Hi Guys,

When the user has done their quiz, they are given the rights to review the questions.

For MCQ, the choice options will be:

  1. highlighted green with a tick behind when user answered CORRECT
  2. highlighted red with a cross behind when user answered WRONG

When the user has got the choice wrong, during review, can he also see the CORRECT choice?

i.e. he should see both

  1.  the highlighted green to indicate the correct answer
  2. the highlighted red to indicate the wrong answer he chose


Do you know where to change this settings? I've tried to look into \question\engine\renderer.php and seems not able to do that.

Average of ratings: -
In reply to Han Sheng Ler

Re: Highlight correct answers during Review Question

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In the quiz settings, Review options section, have you turned on the 'Correct answer' option?

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Highlight correct answers during Review Question

by Han Sheng Ler -

Hi Tim,

This is my option page:

review_options

The user is reviewing his wrong answers. And he only sees this:

review_wrong_answer

The correct answer "c. All of the above" is not highlighted in green with the tick available.

Is there a css code to add that in? It is very useful to visualize the correct answer.

Attachment review_options.png
In reply to Han Sheng Ler

Re: Highlight correct answers during Review Question

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, the only indication of the right answer is the text in the yellow box.

I suppose it might be a good idea to also hilight the correct response. The code that hilights the selected respons is here: https://github.com/moodle/moodle/blob/master/question/type/multichoice/renderer.php#L116. I think you would need to modify the PHP code to also hilight the correct response (if $options->rightanswer is true).

Average of ratings: Useful (2)
In reply to Tim Hunt

Re: Highlight correct answers during Review Question

by Han Sheng Ler -

Thanks tim, for the insight. Shall try on Monday! Cheers.

In reply to Tim Hunt

Re: Highlight correct answers during Review Question

by Han Sheng Ler -

Hi Tim,

I just commented this line 116 in the \question\type\multichoice\renderer.php

            if ($options->correctness /*&& $isselected*/) {

Maybe we can make it an option for the system. =)

In reply to Han Sheng Ler

Re: Highlight correct answers during Review Question

by Han Sheng Ler -

hi guys,

removing the isselected will always cross all non-selected choice. kinda confusing for users. So, i have done using another check in bold:

            if ($options->correctness && $isselected) {

                $feedbackimg[] = $this->feedback_image($this->is_right($ans));

                $class .= ' ' . $this->feedback_class($this->is_right($ans));               

            } else if ($this->is_right($ans)==1 && !$isselected){

                $feedbackimg[] = $this->feedback_image($this->is_right($ans));

                $class .= ' ' . $this->feedback_class($this->is_right($ans));

            } else {

                $feedbackimg[] = '';

            }


I wonder if $this->is_right($ans)==1 is the correct way to check whether the option is correct.

Average of ratings: Useful (1)
In reply to Han Sheng Ler

Re: Highlight correct answers during Review Question

by Han Sheng Ler -

OMG, I tested the above and during quiz, the students see the highlighted answers!!! Need to add this condition:

            } else if ($options->correctness && $this->is_right($ans)==1 && !$isselected){

                $feedbackimg[] = $this->feedback_image($this->is_right($ans));

                $class .= ' ' . $this->feedback_class($this->is_right($ans));

            } else {


So, we must always add $options->correctness

In reply to Han Sheng Ler

Re: Highlight correct answers during Review Question

by FeKuLa Novi -

Thank you Han, It works!

Do you know if It's possible to put that code in my theme?

I just created renderers.php file in my folder theme and I put this code, but doesn't work:

<?php
require_once($CFG->dirroot . '/question/type/multichoice/renderer.php');

class theme_NAMEOFTHEME_qtype_multichoice_renderer_base extends qtype_with_combined_feedback_renderer {

    public function formulation_and_controls(question_attempt $qa,
            question_display_options $options) {

        $question = $qa->get_question();
        $response = $question->get_response($qa);

        $inputname = $qa->get_qt_field_name('answer');
        $inputattributes = array(
            'type' => $this->get_input_type(),
            'name' => $inputname,
        );

        if ($options->readonly) {
            $inputattributes['disabled'] = 'disabled';
        }

        $radiobuttons = array();
        $feedbackimg = array();
        $feedback = array();
        $classes = array();
        foreach ($question->get_order($qa) as $value => $ansid) {
            $ans = $question->answers[$ansid];
            $inputattributes['name'] = $this->get_input_name($qa, $value);
            $inputattributes['value'] = $this->get_input_value($value);
            $inputattributes['id'] = $this->get_input_id($qa, $value);
            $isselected = $question->is_choice_selected($response, $value);
            if ($isselected) {
                $inputattributes['checked'] = 'checked';
            } else {
                unset($inputattributes['checked']);
            }
            $hidden = '';
            if (!$options->readonly && $this->get_input_type() == 'checkbox') {
                $hidden = html_writer::empty_tag('input', array(
                    'type' => 'hidden',
                    'name' => $inputattributes['name'],
                    'value' => 0,
                ));
            }
            $radiobuttons[] = $hidden . html_writer::empty_tag('input', $inputattributes) .
                    html_writer::tag('label',
                        $this->number_in_style($value, $question->answernumbering) .
                        $question->make_html_inline($question->format_text(
                                $ans->answer, $ans->answerformat,
                                $qa, 'question', 'answer', $ansid)),
                    array('for' => $inputattributes['id']));

            // Param $options->suppresschoicefeedback is a hack specific to the
            // oumultiresponse question type. It would be good to refactor to
            // avoid refering to it here.
            if ($options->feedback && empty($options->suppresschoicefeedback) &&
                    $isselected && trim($ans->feedback)) {
                $feedback[] = html_writer::tag('div',
                        $question->make_html_inline($question->format_text(
                                $ans->feedback, $ans->feedbackformat,
                                $qa, 'question', 'answerfeedback', $ansid)),
                        array('class' => 'specificfeedback'));
            } else {
                $feedback[] = '';
            }
            $class = 'r' . ($value % 2);
            if ($options->correctness && $isselected) {
                $feedbackimg[] = $this->feedback_image($this->is_right($ans));
                $class .= ' ' . $this->feedback_class($this->is_right($ans));              
            } else if ($options->correctness && $this->is_right($ans)==1 && !$isselected){
                $feedbackimg[] = $this->feedback_image($this->is_right($ans));
                $class .= ' ' . $this->feedback_class($this->is_right($ans));
            } else {
                $feedbackimg[] = '';
                $classes[] = $class;
            }
        }

        $result = '';
        $result .= html_writer::tag('div', $question->format_questiontext($qa),
                array('class' => 'qtext'));

        $result .= html_writer::start_tag('div', array('class' => 'ablock'));
        $result .= html_writer::tag('div', $this->prompt(), array('class' => 'prompt'));

        $result .= html_writer::start_tag('div', array('class' => 'answer'));
        foreach ($radiobuttons as $key => $radio) {
            $result .= html_writer::tag('div', $radio . ' ' . $feedbackimg[$key] . $feedback[$key],
                    array('class' => $classes[$key])) . "\n";
        }
        $result .= html_writer::end_tag('div'); // Answer.

        $result .= html_writer::end_tag('div'); // Ablock.

        if ($qa->get_state() == question_state::$invalid) {
            $result .= html_writer::nonempty_tag('div',
                    $question->get_validation_error($qa->get_last_qt_data()),
                    array('class' => 'validationerror'));
        }

        return $result;
    }

}
?>