Adding a plugin to quiz

Adding a plugin to quiz

by Tamara Dakic -
Number of replies: 9

I am working on integrating the Realtimequiz (https://moodle.org/plugins/mod_realtimequiz) module with the question bank and the grade book.  I have a (mostly) working prototype (https://github.com/tdakic/realtimequiz_prototype) that includes slightly modified code from the quiz module. This approach was quick and dirty, but obviously not the right way of doing this.

Functionally, the only real difference between my code and the quiz module code is in the way the quiz is administered: in Realtime quiz the teacher controls which question the students can attempt at any given time. It is meant for in-class quizzes.

I’ve been tying to figure out how to plug in my code (when it is cleaned up, improved and tested, of course) in the quiz module. One option I think might work would be to add an access rule and then implement the description method of the access_rule_base class to display the quiz controls to the teacher and display a page that can be controlled by the teacher to the students. This doesn’t seem right to me (it makes the description method into a hijacker). 

I am not proposing to change the core, but to add a plugin as  https://moodle.org/plugins/quizaccess_honestycheck or SEB plugin.

Anyone has a good idea?  

Thanks,

Tamara

Average of ratings: -
In reply to Tamara Dakic

Re: Adding a plugin to quiz

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Do you mean you want to change how the quiz engine works?  Or is it a fork of realtime quiz? You might get some ideas from this branch of the thing I am gradually working on.

https://github.com/marcusgreen/moodle-mod_qpractice/tree/moodle_400
In reply to Marcus Green

Re: Adding a plugin to quiz

by Tamara Dakic -
Thanks for the hint! I will look at the code soon.

What I am trying to accomplish is to have the Realtime quiz work with the question bank and the grade book.

One way of doing this is to use the quiz module code in the Realtime quiz module. My messy code could be adapted to do that with some pain as the sql table names in the quiz module are hardcoded and I think that it would not be right to use the quiz sql tables for a custom plugin. Please correct me if I am wrong here.

Another way of accomplishing the task is “the other way around”: use the Realtime quiz code in the quiz module and have an option in the quiz settings to specify if a quiz is a Realtime quiz. This makes sense to me as a Realtime quiz is a quiz that is administered differently. As a teacher, I see a lot of advantages of this approach. For example, students could review the Realtime quiz as they would any other quiz, students who missed the class where the Realtime quiz was administered could make up the quiz if the teacher switched it to a “regular” quiz, the teacher can choose to administer the same quiz in different ways for different classes/semesters, etc.

The issue I am having is how to properly implement the second option. Any suggestions are more than welcome.
In reply to Tamara Dakic

Re: Adding a plugin to quiz

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
In that case that link should be useful. QPractice always worked with Gradebook and the branch I linked to is an update to work with Moodle 4.X Quesiton Bank, which changed things significantly by comparison with Moodle 3.X. The main bit I am left to do is the stuff you refer to like look at their progress. I don't think the "other way round" is viable, tempting though it is as a solution.

I will be distracted from QPractice for a while while working on my ai/chatgpt essay response question.
In reply to Tamara Dakic

Re: Adding a plugin to 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
If you basically want all the features of mod quiz, with just one added feature: teacher controls when students can attempt each question in a classroom situation, I am wondering if creating a whole activitity which duplciates all the quiz funcitonality is the best approach.

I am wondering if you could build this by making a sub-plugin for the quiz. Sepecifically, could you do this using a Quiz access rule plugin? I don't know if that is acutally possible, since the quiz access rule system was not designed for this. However, people have done many creative things using Quiz access rules, which were not orgininally intended, so by creating (ab)use of the API, it might be possible.

https://docs.moodle.org/dev/Quiz_access_rules
Average of ratings: Useful (2)
In reply to Tim Hunt

Re: Adding a plugin to quiz

by Tamara Dakic -
Thanks for the repies!

I agree that creating the sub-plugin of the quiz module is the best approach. I considered adding an access rule and the best idea I had was to implement the description method of the access_rule_base class to display the quiz controls (start a question, end a question, display results etc..) for the teacher and the page that is controlled by polling the DB to the students.  What bugs me about this is that the way the quiz is administered would be changed by the method called description, which is intended for only displaying information to the students. I guess that is what you mean by the API abuse.

Any other ideas on a better API abuse are more than welcome.

Thanks,

Tamara
In reply to Tamara Dakic

Re: Adding a plugin to quiz

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Tamara, Tim is the main architect for Quiz, so his advice is worth listening to.
In reply to Marcus Green

Re: Adding a plugin to quiz

by Tamara Dakic -
Hi Marcus, I appreciate Tim’s feedback very much and I am totally ready to abuse the API. I just want to see if someone (likely Tim?) has a better idea on how to go about it than the one I outlined above.
Average of ratings: Useful (1)
In reply to Tamara Dakic

Re: Adding a plugin to 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 think using description would work. I agree that it feels wrong.

The other thing you could do is: Make a completely separate script mod/quiz/accessrule/realtime/teachercontrols.php to show the UI to the teacher, and then have the description method output a link to that for the teacher.

I think which of those is better depends on which is going to be the most usable interface for the teachers.

The other thing is how to make it work for students, but I guess you can use setup_attempt_page etc to add the necessary JavaScript.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Adding a plugin to quiz

by Tamara Dakic -
The code for the plugin mostly works (https://github.com/tdakic/tcquiz) so I have started working on using templates and amd. I am stuck on something that should be pretty simple according to https://moodledev.io/docs/guides/templates (non-empty lists). My template is not rendering my list.

In the function description of rule.php I have:

 $open_session = array();
$tmp_sess = array('joincode'=>'TESTING', 'timestamp'=>'NOW', 'currentquestion'=>10);
array_push($open_session, $tmp_sess);
$tmp_sess = array('joincode'=>'TESTING1', 'timestamp'=>'NOW AND THEN', 'currentquestion'=>20); array_push($open_session, $tmp_sess);
$data = new stdClass();
$data->opensess = array_values($open_session);
//$data = json_encode($data); $first = 222;
$messages[] = $OUTPUT->render_from_template('quizaccess_tcquiz/hello', ['first'=> $first, 'last' => "Woody", 'opensess' => $data]);

The $first and $last render properly, but $data doesn’t. Without json_encode I get the following error messages.

error. msg


If I do json_encode, $data is not rendered, although the json object looks fine (except for many " symbols). The exception in the above error message seems common.


The relevant part of the hello.mustache looks like this:

table template 
 I tried triple braces because the json object that comes through has many quot; chars.

Any help would be greatly appreciated. I am using '4.2.3 (Build: 20231009)'