All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

by Scott Andre -
Number of replies: 7

We are running Moodle 2.6 and will be upgrading to 2.7 soon (via Totara).

I can insert images (png, jpg) in other areas of this question type and have the images display fine when running a quiz however any image placed inside the "Combined Feedback" area do not display. Instead I see a placeholder for what looks like either a missing image or an image that cannot display.

Combined Feedback - Edit Mode       Preview Mode

Average of ratings: -
In reply to Scott Andre

Re: All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

by Jean-Michel Védrine -

Hello Scott,

I can reproduce the problem so you have found a bug. Unfortunately it was never reported so I hadn't noticed it sad.

Unfortunately all or nothing question type is a specific case for combined feedback because there is no "partially correct" feedback of course, so it can't reuse the same code that other questions types use, and I surely have made a mistake in that code.

I will study the problem and report.

In reply to Jean-Michel Védrine

Re: All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

by Jean-Michel Védrine -

Oops my bad, I have used the wrong component

        $options->correctfeedback = $this->import_or_save_files($question->correctfeedback,
                $context, 'qtype_multichoiceset', 'correctfeedback', $question->id);
        $options->correctfeedbackformat = $question->correctfeedback['format'];
        $options->incorrectfeedback = $this->import_or_save_files($question->incorrectfeedback,
                $context, 'qtype_multichoiceset', 'incorrectfeedback', $question->id);

the component should be 'question' not 'qtype_multichoiceset'

Tim, what do you suggest to fix the problem in the most "elegant" and user friendly way ?

  • simply correct the component in the code to use 'question', but existing all or nothing questions will be broken, can I add an upgrade step to move files to the new component ?
  • add a renderer to multichoiceset with a customized combined_feedback function and continue to use the qtype_multichoiceset component ?
  • some other way ...
In reply to Jean-Michel Védrine

Re: All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

by Jean-Michel Védrine -

I looked and it seems the component was qtype_multichoiceset since multichoiceset version for Moodle 2.0 written by Adriane.

Solution #2 is working if I not only overwrite the combined_feedback function in the renderer but also check_file_access in the qtype_multichoiceset_question class . Existing questions need no change. The drawback is that this is not compatible with other qtypes but multichoiceset is already a spacial case because it has no partiallycorrect feedback.

Solution #1 needs an upgrade step and also changes to some function like move_files, delete_files, ...

In reply to Jean-Michel Védrine

Re: All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

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

I think option 1 is the best solution in the long term, but as you say, you need things like upgrade code.

In reply to Tim Hunt

Re: All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

by Jean-Michel Védrine -

Thanks Tim,

I don't really know how to change the component from 'qtype_multichoiceset' to 'question' when filearea is 'correctfeedback' or 'incorrectfeedback' because I don't know if it would be safe to just do $DB->set_field on the files table, I looked at the file API without seeing a function I could use.

Maybe if it is not possible to use $DB->set_field, I could do something like (largely inspired from move_area_files_to_new_context)

use get_area_files to get the old files

and for each file use create_file_from_storedfile to create a new one with the new component

then delete old files

In reply to Jean-Michel Védrine

Re: All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

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

I think you can just call set_field on the files table in upgrade code.

In reply to Tim Hunt

Re: All-or-Nothing Multiple Choice: Images don't display in "Combined Feedback" area

by Jean-Michel Védrine -

Thanks Scott for reporting the problem and thanks Tim for all your help.

I have released a new version (version 1.4) that fix the problem. Existing files in existing questions are updated during the upgrade step, so they should display fine after this upgrade and I have corrected the code so that new question's files are correctly recorded in database.

Note that while working on this I have found a nasty typo in the upgrade code that prevented it to work correctly (why do I make so many stupid typos writing code sad ) so all users of the All or nothing question type should upgrade to this new version.

As usual, the new version is available both in the Moodle plugins Directory https://moodle.org/plugins/view/qtype_multichoiceset and in my github repository https://github.com/jmvedrine/moodle-qtype_multichoiceset/tree/master