How to override a renderer such that the functionality of the overridden renderer also remains available?

社会主义新天地 提交于 2019-12-08 11:53:20

问题


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.


回答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).




回答2:


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. 
}



回答3:


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.



来源:https://stackoverflow.com/questions/24792170/how-to-override-a-renderer-such-that-the-functionality-of-the-overridden-rendere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!