Quiz reports: Difference between revisions
m (moved How to write a quiz report plugin to Quiz reports) |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{Quiz developer docs}} | ||
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 <tt>quiz_</tt>, and live inside <tt>mod/quiz/report</tt>. (The prefix was a historical mistake. It would have been much better to use <tt>quizreport_</tt>, 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 <tt>mod/quiz/report/default.php</tt> and you just need to implement the <tt>display</tt> method. This gets called from <tt>mod/quiz/report.php</tt> 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 <tt>pluginname</tt>, <tt>report''name''</tt> and <tt>''name''report</tt>. (This should probably be simplified in the future.) | |||
==When a user view the report== | |||
The will go to a URL like <tt>http://.../mod/quiz/report.php?id=''cmid''&mode=''name''</tt>. 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 <tt>quiz_''name''_report::display($quiz, $cm, $course)</tt> method. You can put whatever code you like in there. | |||
==The attempts report classes== | |||
There are some useful helper classes in <tt>mod/quiz/report/attemptsreport.php</tt>. This is basically the common functionality that is used by both the <tt>overview</tt> and <tt>responses</tt> 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 <tt>mod/quiz/report/reportlib.php</tt>. | |||
==See also== | ==See also== | ||
*[[ | * Most quiz reports use [[lib/tablelib.php]]. | ||
*[[ | * [http://git.moodle.org/gw?p=moodle.git;a=tree;f=mod/quiz/report;h=b748acaba34655e2efe659475dec3e301541dec1;hb=HEAD The standard quiz reports code in git]. | ||
* [http://moodle.org/plugins/browse.php?list=category&id=13 Contributed quiz reports]. | |||
[[Category:Quiz]] | [[Category:Quiz]] | ||
[[Category:Plugins]] |
Latest revision as of 13:46, 23 March 2018
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
- Most quiz reports use lib/tablelib.php.
- The standard quiz reports code in git.
- Contributed quiz reports.