moodleou / moodle-quiz_answersheets

A Moodle quiz report to allow quiz attempts to be exported
8 stars 15 forks source link

Update renderer.php #32

Open joe-baudisch opened 2 years ago

joe-baudisch commented 2 years ago

Fixing https://github.com/moodleou/moodle-quiz_answersheets/issues/31

mod/quiz/report/answersheets/classes/output/multichoice/renderer.php inherits from qtype_multichoice_single_renderer

but you can overwrite the question type if you insert following lines, right after you get the input attributes. I explicitly commented the lines of code only here.

        global $DB;
        // every question has its unique id
        $questionid = $qa->get_question_id();
        //   Because we have a multicoice question, it is either a single and therefore is rendered originally as radio-button
        //   or it is a not a single, because more than one answer is possible, then it is originally rendered as checkbox.
        //   the type can be retrieved from the database table  qtype_multichoice_options
        $specific_type = $DB->get_record('qtype_multichoice_options', ['questionid' => $questionid], 'single', MUST_EXIST);
        if ($specific_type->single == 0){
            $inputattributes['type'] = 'checkbox';
        }

This fix renders a radio button if it is a single multichoice and renders a checkbox if it is not a single multichoice.

timhunt commented 2 years ago

Please can you writea proper commit comment to explain what the fix is doing.

joe-baudisch commented 2 years ago

Please can you writea proper commit comment to explain what the fix is doing.

Do you need more comments? Thanks, Joe