Offline quiz rendering issues

Re: Offline quiz rendering issues

by Mohanish Nagarkar -
Number of replies: 0

Once you have installed the offline quiz plugin

Go to the plugin directory: https://yoursite/moodle/mod/offlinequiz

Here you will have to modify the following files (for generating different formats of your quiz).

  • locallib.php
  • pdflib.php
  • docxlib.php

I edited 1st and 2nd as I did not need DOCx.

In locallib.php, you will have to make changes to the offlinequiz_print_question_preview method

In pdflib.php, you will modify offlinequiz_create_pdf_question method


For locallib.php, follow the following steps:

1. Include the filter file

  • moodle/filter/wiris/filter.php

2. Add the filter to your array of filters that are already applied

$filters = filter_get_active_in_context($context);

if (array_key_exists('wiris', $filters)) {
$wirisfilter = new filter_wiris($context, array());
}
3. And then apply the wiris filter to your data:

if ($wirisfilter) {
$text = $wirisfilter->filter($text);
if ($question->qtype != 'description') {
foreach ($choiceorder as $key => $answer) {
$question->options->answers[$answer]->answer = $wirisfilter->filter($question->options->answers[$answer]->answer);
}
}
}

For pdflib.php:

1. Include the filter file as you did above.


2. Create a new wirisfilter variable:

$wirisfilter = new filter_wiris($context, array());


3. Find pdf->checkpoint() in your code and add the wirisfilter:
$pdf->checkpoint();

$questiontext = $question->questiontext;

if (!empty($texfilter)) {
$questiontext = $texfilter->filter($questiontext);
}

//Add this filter. The above code will be already be there.
if (!empty($wirisfilter)) {
$questiontext = $wirisfilter->filter($questiontext);
}
We added this to our question text only. We still need to apply to the answers/options yet.


4. Find the foreach loop (shown below) and add the filter to answers/choices

foreach ($order as $key => $answer) {

//Add this filter code inside the loop
if (!empty($wirisfilter)) {
$answertext = $wirisfilter->filter($answertext);
}
5. Wherever you find any other filter (in my case 'texfilter') already applied in your code, include the wirisfilter there.


These are all the steps I followed to get the rendering proper.


Regards,

Mohanish

Average of ratings: Useful (1)