Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Quiz reports

From MoodleDocs

Quiz report sub-plugins can not only be used to display custom reports on the quiz data, but can also be used to plugin other functionality into the quiz module.

Overview

Theses sub-plugins have frankenstyle prefix quiz_, and live inside mod/quiz/report. (The prefix was a historical mistake. It would have been much better to use quizreport_, but it is too late to change now.)

A quiz report plugins just needs to implement one class

class quiz_name_report extends quiz_default_report {
    public function display($cm, $course, $quiz) {
        // Generate and display the report, or
        // other functionality.
    }
}

The base class is defined in mod/quiz/report/default.php and you just need to implement the display method. This gets called from mod/quiz/report.php after some basic set-up has been done.

What files make up a quiz report

mod/quiz/report/name/
    report.php            - Contains the implementation of the quiz_name_report class.
    version.php           - Normal Moodle plugin version.php file.
    lang/en/quiz_name.php - Language strings for your plugin.
    db/*                  - lets you define db tables, capabilities, etc.
    simpletest/*          - Unit tests.
  • It is possible to make a working plugin with only the first three of these.
  • The only lang strings you need to define are pluginname, reportname and namereport. (This should probably be simplified in the future.)


When a user view the report

The will go to a URL like http://.../mod/quiz/report.php?id=cmid&mode=name. There may also be additional parameters in the URL if your report contains several internal pages with links between them. The statistics and grading reports are good examples of this.

This leads to a call to the quiz_name_report::display($quiz, $cm, $course) method. You can put whatever code you like in there.


The attempts report classes

There are some useful helper classes in mod/quiz/report/attemptsreport.php. This is basically the common functionality that is used by both the overview and responses reports. If you want to make a similar report (with one row for each quiz attempt) you should probably build on these classes.

There are also useful helper functions in mod/quiz/report/reportlib.php.

See also