How to access "Quiz" plugin's variables' values in a local plugin

How to access "Quiz" plugin's variables' values in a local plugin

by Shreyans Jain -
Number of replies: 6

Hi!

I am creating a plugin in which I require the values of variables that are present in "Quiz" plugin. My plugin injects buttons to the attempt page of the quiz which in turn generates a QR. More details about the project can be found here: https://github.com/PearlMiglani/Moodle-QR-Based-Image-Upload-Activity

For this project to work, I need some values of variables present in the "Quiz" plugin, for eg: attemptid, uniqueid, slot, questionid, etc.
So for example, a student is attempting a quiz. That student is going to have a unique attemptid and uniqueid, then the question they are attempting so will have a question id and etc. This data is required in order to generate a UNIQUE QR for each student's each attempt's to a particular question.

Please guide as to how this can be accessed and achieved.


Thanks!

Average of ratings: -
In reply to Shreyans Jain

Re: How to access "Quiz" plugin's variables' values in a local plugin

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
How are you adding your buttons to the quiz attempt page?
In reply to Tim Hunt

Re: How to access "Quiz" plugin's variables' values in a local plugin

by Shreyans Jain -
When the plugin detects that the page is "attempt.php", it injects javascript using $PAGE->requires->js() and this adds the buttons to the page.
In reply to Shreyans Jain

Re: How to access "Quiz" plugin's variables' values in a local plugin

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, when you include the JavaScript, you should pass the necessary data to the JavaScript (which would be easier if you were using $PAGE->requires->js_call_amd()).

Anyway, probably the least-bad option is to cheat and do

global $attemptobj;

in your code. That is alwas defined on attempt.php, and you will find that it is an instance of the quiz_attempt class (which is in mod/quiz/attemptlib.php) and that can probably give you all the information you need.
In reply to Tim Hunt

Re: How to access "Quiz" plugin's variables' values in a local plugin

by Shreyans Jain -
I already have a version that works fine but doesn't pass Moodle's guidelines. I wanted to make one for the masses and to make it available in the plugin store.

The way you suggested, will it work in such a way that Moodle doesn't disallow it?
In reply to Shreyans Jain

Re: How to access "Quiz" plugin's variables' values in a local plugin

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't really comment without seeing the code that was rejected and the reasons why your approach was considered unsuitable.