moodle 2.1 question engine :: how to access question behaviour from within a quiz

moodle 2.1 question engine :: how to access question behaviour from within a quiz

by Joseph Rézeau -
Number of replies: 5
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

A question for Tim!

I am currently updating my REGEXP question type for moodle 2.1 (shortly after updating it for 2.0...) and I have a question.

In the renderer.php file, I am overriding public function feedbackegg with one change:

if ($options->feedback) {
            $output .= html_writer::nonempty_tag('div', $this->specific_feedback($qa, $options), etc.

This is because, in public function specific_feedback(question_attempt $qa, question_display_options $options), I need to retrieve the behaviour of the actual question. I still have to find my way through all the - new to 2.1 - question behaviours. But that is not the problem.

My problem is as follows.

1.- In the question preview popup window, it is now possible to select "behaviour being used" from the How questions behave dropdown list. That is a great feature, thanks Tim!

With the override explained above, I can easily retrieve $options->behaviour and use that property for my special feedback needs... That is fine.

2.- However, I also need to retrieve the actual question's behaviour when a question is included in a quiz. Unfortunately, in the renderer.php file, inside public function specific_feedback(question_attempt $qa, question_display_options $options), $options->behaviour is not available. I get this error notice:

Notice: Undefined property: mod_quiz_display_options::$behaviour

What should I do?

Joseph

Average of ratings: -
In reply to Joseph Rézeau

Re: moodle 2.1 question engine :: how to access question behaviour from within a quiz

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

Your question type must not do anything different depending on the behaviour. That is against the rules.*

In your renderer, you may only access the fields of $options that are defined in the question_display_options class: https://github.com/moodle/moodle/blob/master/question/engine/lib.php#L388.

That is, you must classify every bit of output you generate as question text / specific feedback / general feedback, etc. You must then trust that the behaviour has correctly set up $options so that only things it is sensible to display now are visible, based on the current state of the question, and the settings on the quiz.

The fact that $options->behaviour happens to be available when previewing a question is an implementation detail of the preview pop-up and should not be relied upon.

If you think the rules are too strict for you needs, then please explain what result you are trying to achieve.

 

* Why is it against the rules? Well, you don't konw what other behaviours people will create in the future, and your question type must work with all those too.

In reply to Tim Hunt

Re: moodle 2.1 question engine :: how to access question behaviour from within a quiz

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Thanks for your help, Tim. I realize I have to get a better understanding of the - new to Moodle 2.1 - questions behaviour feature first of all.

As for "the result I am trying to achieve", I need to display a kind of "extra feedback" by showing the student a copy of their answer with wrong bits colored red and strikedthrough. For more info see the regexp question documentation, Automatic formatted extra feedback. At the moment (in moodle 1.9.x and 2.0) I can achieve this by knowing the quiz/question mode (i.e. adaptative or not adaptive) when displaying the feedback. But I might find another solution.

I will post again in this discussion if I need further help.

ATB

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 question engine :: how to access question behaviour from within a quiz

by Jamie Pratt -

Hi Joesph,

Would it be correct to do something like what the match question type does Joseph and Tim? For each hint you can override the display options for the renderer using question_hint::adjust_display_options. You have hints as part of the feedback in the interactive multiple tries question behaviours and these hints can affect the options when rendering the rest of the question. The match question type uses question_hint_with_parts which clears wrong answers.

Jamie

In reply to Jamie Pratt

Re: moodle 2.1 question engine :: how to access question behaviour from within a quiz

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Thanks for the hint, Jamie. I'll have a look at the match question type renderer.

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 question engine :: how to access question behaviour from within a quiz

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 can think of several ways you might want to handle this:

1. You could say that that is specific feedback, and that it is useful to display it even in deferred feedback mode, after the quiz is submitted, so the student can see exactly how well they did. Therefore, you control the display of this sort of feedback using $options->feedback.

2. You could handle this in the same way that match handles numpartscorrect (actually most of the code for that is in the base class) - or clearwrong. Of course, you would have to call the checkboxes on the question editing form something different. Perhaps I should have chosen a less specific name than $options->numpartscorrect. Search the code for ->clearwrong and/or ->numpartscorrect.

(Also, https://github.com/timhunt/moodle-qtype_oumultiresponse and https://github.com/timhunt/moodle-qtype_ddwtos use these facilities.)