reportbuilder/API: Difference between revisions
From MoodleDocs
John Okely (talk | contribs) (Created page with "==Overview==") |
John Okely (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
[[reportbuilder|Back to Index]] | |||
==Overview== | ==Overview== | ||
The report builder API enables plugin contributors and moodle core developers to create new sources that can be used by site administrators and teachers to generate and customise reports. | |||
==How to create a source== | |||
To create a source, create a file called rb_source_SOURCE_NAME.php in a subfolder of your plug-in, or the relevant core class. The class name must start with 'rb_source_', and the class name and filename must match. The class must be a child of rb_base_source. | |||
The following is an example of a Report Builder source: | |||
<pre> | |||
<?php | |||
class rb_source_example1 extends rb_base_source { | |||
public $base, $joinlist, $columnoptions, $filteroptions; | |||
function __construct() { | |||
$this->base = '{course}'; | |||
$this->joinlist = array( | |||
new rb_join( | |||
'course_category', | |||
'LEFT', | |||
'{course_categories}', | |||
'course_category.id = base.category' | |||
) | |||
); | |||
$this->columnoptions = array( | |||
new rb_column_option( | |||
'course', | |||
'fullname', | |||
'Course Fullname', | |||
'base.fullname' | |||
) | |||
); | |||
$this->filteroptions = array(); | |||
$this->sourcetitle = "Example1"; | |||
parent::__construct(); | |||
} | |||
} | |||
?> | |||
</pre> |
Revision as of 02:59, 3 June 2014
Overview
The report builder API enables plugin contributors and moodle core developers to create new sources that can be used by site administrators and teachers to generate and customise reports.
How to create a source
To create a source, create a file called rb_source_SOURCE_NAME.php in a subfolder of your plug-in, or the relevant core class. The class name must start with 'rb_source_', and the class name and filename must match. The class must be a child of rb_base_source.
The following is an example of a Report Builder source:
<?php class rb_source_example1 extends rb_base_source { public $base, $joinlist, $columnoptions, $filteroptions; function __construct() { $this->base = '{course}'; $this->joinlist = array( new rb_join( 'course_category', 'LEFT', '{course_categories}', 'course_category.id = base.category' ) ); $this->columnoptions = array( new rb_column_option( 'course', 'fullname', 'Course Fullname', 'base.fullname' ) ); $this->filteroptions = array(); $this->sourcetitle = "Example1"; parent::__construct(); } } ?>