Add new functionality to quiz settings page

Add new functionality to quiz settings page

by Chandira Punchihewa -
Number of replies: 6

First of all I'm a beginner to moodle development.

One of my client has requested he needs a functionality to be introduced to quiz settings page. The following is the functionality he needs,

1. Add a new field and dropdown to quiz settings page,

Default wrong answers grade - a dropdown list which gives a similar functionality like grade dropdown in each question edit form. It must give only negative percentages -25%, -50% etc. The reason for this functionality is, client has over 300 questions for quiz and he doesn't have time to go through each and every question and edit the grade to the minus values for wrong answers. Instead he needs to enter that negative value in the quiz settings and it should affect all the questions related to that quiz. 

I think of creating a plugin by extending the functionality and adding an override for a render class. But I went through renderer files and mustache templates but, I cannot find the form or mustache file which can be used to extend the quiz settings form. Can anyone advice me which exact file I should use? Can any advise how I should implement this feature? 

Average of ratings: -
In reply to Chandira Punchihewa

Re: Add new functionality to quiz settings page

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Unfortunately you do not say which question types are in that quiz nor what the question behaviour is.
In reply to Joseph Rézeau

Re: Add new functionality to quiz settings page

by Chandira Punchihewa -
It is of multiple choice question type. Question behavior is Deferred feedback.
In reply to Chandira Punchihewa

Re: Add new functionality to quiz settings page

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

Is your problem related to this discussion?

Does your client want to extend the default Moodle question $rawfractions (in file moodle\question\engine\bank.php) to include negative marks beyond -100%? 

Something like:

correct answer 100%

incorrect answer -100%

very incorrect answer -250%

If that is the case, I have some solutions.

 

In reply to Joseph Rézeau

Re: Add new functionality to quiz settings page

by Chandira Punchihewa -
Thanks for the comment. But what he wants is to include this negative marks for the quiz, not for the individual questions.  What he basically wants is once you select the penalty value from custom field of quiz(which we need to implement) all the incorrect questions will affect that penalty for that particular quiz only. For example if quiz 1 has this option set to -25% then every incorrect question that was attempted by the user will get -25% penalty per each question associated with that quiz only. But there can be other quizes without penalties which will work without penalties. It should be a configuration option for quiz not for the questions.


In reply to Chandira Punchihewa

Re: Add new functionality to quiz settings page

by Daniel Thies -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I have a couple more examples where I worked on something like this before changing wrong answer values (or right answers) from quiz settings. Grades for questions can be changed by developing a question behaviour like Deferred feedback (all or nothing). Choosing this behaviour effectively imposes a 100% penalty on wrong answers. I do not thing that you can add setting with a question behavior, but you can easily with a question access plugin. I used a combination of the two to penalize late quiz attempts see https://github.com/dthies/moodle-qbehaviour_deferredpenalty and https://github.com/dthies/moodle-quizaccess_changebehaviour.
In reply to Chandira Punchihewa

Re: Add new functionality to quiz settings page

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

You need to undestand how the Moodle software is acutally structured, and not imagine that it should be sructured in a way that makes your one specific feature request easy to implement. Wishful thinking never gets you anywhere in software development.

So, in Moodle, questions are re-usable, self-contain, bits of functionality. The grade for each option is a properly of each question. You have to accept that.

So, in terms of something that could be implemented in Moodle, what you want is a tool which:

  1. For a given quiz.
  2. Finds all the multiple choice questions in that quiz.
  3. And then sets the grade for all the wrong choices in that question, to a given value.

It is probably not difficult to develop something like this. There is a question of how best to hook into Moodle's navigation. I would probably do it as a Quiz report plugin, event though it is not a report. https://github.com/moodleou/moodle-quiz_editquizsettings is an example of a plugin which abuses this plugin type to hook some random functionality into the quiz.

Then you need to develop the feature. To find what questions are in the quiz, look at the quiz_slots database table. Before altering those, it might be good to get your code to check that they are not used in any other quizzes.

And, there is not a nice API for altering questions. You may end up having to directly edit the data in the quiz_answers DB table. If you do, then you need to call question_bank::notify_question_edited($questionid) for each question you change, or the changes won't show up because of caching.

Average of ratings: Useful (3)