0

Moodle has a Multichoice question-type plugin. These questions are used in Quizes.

I have different types of multiple choice questions which I want to be displayed. They are all basically MCQ's, but are rendered in different ways.

Forexample some are *simple MCQ'*s, while others have a reading passage associated with them (which the student has to read and find the answer from it) which needs to be displayed. Then the reading passage can be displayed in different ways in further different types of MCQ's.

So I need to render around 4 to 5 different types of MCQ's, which only differ in how they are rendered on the web-page.

Now, the solution to displaying a question in a different way is overriding the renderer of the plugin. But the problem is that:

If I override the renderer of the Multichoice question type such that it displays the reading passage, the renderer for displaying the simple MCQ will be overridden. This means I can only display the MCQ with the passage and not the simple MCQ any more.

But I need to display all kinds of MCQ's.

So please suggest me some way to work around it.


The biggest fear is: may be it needs writing question type plugins for each type of MCQ, and then when adding them in the part of the quiz where the teacher (or the admin who makes the quiz) is asked to choose the question type; and then the teacher selects the particular type of a question, and then in our code we get that type and do something like:

If question type is simple MCQ, then use the MCQ plugin's renderer, otherwise if it is an MCQ with a passage, use this renderer (our custom renderer which overrides the multichoice plugin renderer)

How should I go about it?


EDIT:- This is a picture of the form which takes the input from the admin who is adding a question to the quiz, on what type of question do they want to add?

Perhaps I further need to divide the multichoice question into the types I am interested in by identifying and then overriding the code which displays this form, and then identifying and the code which receives the input from this form, and then use that input to make a decision on how to render the ouput.

enter image description here

Solace
  • 8,612
  • 22
  • 95
  • 183
  • 1
    Face your Fear! your on the right path! google "polymorphism". – solidau Jul 17 '14 at 00:01
  • 1
    http://code.tutsplus.com/tutorials/understanding-and-applying-polymorphism-in-php--net-14362 – solidau Jul 17 '14 at 00:05
  • @Juventus18 Thank you very much. I just went through the article- very helpful. About facing the fear, this is a follow-up question: Can we write a plugin by basing it on an already present plugin (Multichoice question type plugin in this case) just like we extend already present themes by just adding the '_new_' functionality in the new theme, and the rest of all the functionality is extended on the already present theme which our new theme is extending? – Solace Jul 17 '14 at 11:49

3 Answers3

1

Why not put that logic into the renderer - in the functions write, if (type == originaltype) then call parent::function, otherwise do your custom output. Obviously you'd need to use whatever variable is relevant to figuring this out in your code (your question doesn't make it clear how you distinguish between the types).

davosmith
  • 6,037
  • 2
  • 14
  • 23
  • Firstly, thank you. Secondly, you're right my question does not clarify how to distinguish between the types- that's because I am not clear. Need to get some input from the user on what type of MCQ they want to add to the quiz. For that, I probably need to add those types in the form where the admin chooses the question type they want to add to the quiz (I am adding its picture to the question to make it clear) For that I need to override the part of the quiz renderer which displays the form, then the part which takes that input, then somehow get that input as the type to do if(type==st)... – Solace Jul 17 '14 at 10:35
1

Generally yes, you can extend an existing plugin:

Include_once("existingplugin.php")

Public CustomPlugin extends ExistingPlugin {
    Public override ExistingMethod() {
        //do something else
    }

    //methods not overridden do what they do. 
}
solidau
  • 4,021
  • 3
  • 24
  • 45
  • Thank you, and this! which file is `existingplugin.php`? Is it the renderer? If it is the `renderer`, then it essentially means we are simply overriding the `renderer`, but we can just do that in our custom theme rather than extending the plugin? What I was thinking was: (1) Find the renderer which renders the form posted in the question, then add more radio buttons for further types of MCQ's we want to add. (2) Find the code which takes the input from this form (3) Get that input in our theme's renderer (which is overriding the plugin's renderer already (4) And use it to decide the output. – Solace Jul 18 '14 at 11:25
  • Please tell me if I am still on the right path? Thank you. – Solace Jul 18 '14 at 11:26
0

I am replying very late. Thanks for the earlier answers. As far as the your concern is about distinguishing between the types of default(standard) and the custom one, you might use the feature of 'Tags' of question-type to differentiate between the questions. Just set your own custom tags for the questions that required to be overridden through renderer.

I checked moodle 2.6 onwards & this 'Tag' feature is available for question types. I have not checked 2.5 and other previous releases on Moodle for the availability of this 'Tag' features for question types.

Suraj Kumar
  • 564
  • 1
  • 3
  • 11