Note:

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

Report builder API: Difference between revisions

From MoodleDocs
m (Protected "Report builder API": Developer Docs Migration ([Edit=Allow only administrators] (indefinite)))
 
(18 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Report Builder API overview ==
{{Template:Migrated|newDocId=/docs/apis/core/reportbuilder/}}
 
== System Reports ==
 
=== Introduction ===
 
=== Column ===
 
==== Column types ====
==== Creating columns ====
 
=== Filter ===
 
==== Filter types ====
 
* '''Text'''  (reportbuilder/classes/local/filters/text.php)
* '''Date'''  (reportbuilder/classes/local/filters/date.php)
* '''Number'''  (reportbuilder/classes/local/filters/number.php)
* '''Boolean Select'''  (reportbuilder/classes/local/filters/boolean_select.php)
* '''Select'''  (reportbuilder/classes/local/filters/select.php)
* '''Course selector'''  (reportbuilder/classes/local/filters/course_selector.php)
 
==== Creating filters ====
 
To create a new filter, just create a new instance of '''reportbuilder/classes/local/report/filter.php''' class with:<br />
<code php>
* string $filterclass
* string $name
* lang_string $header
* string $entityname
* string $fieldsql = ''
* array $fieldparams = []
</code>
 
Example:
 
<code php>
$filters[] = (new filter(
            course_selector::class,
            'courseselector',
            new lang_string('courses'),
            $this->get_entity_name(),
            "{$tablealias}.id"
        ))
            ->add_joins($this->get_joins());
</code>
 
=== Entity ===
 
An Entity is a collection of elements where an element is a column or a filter. An entity is re-usable across many system reports and we can add only the entity columns or filters that we need on each report.
 
==== Create an entity ====
 
To create an entity, the new entity class must extend '''/reportbuilder/classes/local/entities/base.php''' class and must include these methods:
 
<code php>
get_default _table_aliases()
get_default_entity_title()
get_default_entity_name()
initialise()
get_all_columns()
get_all_filters()
</code>
 
===== get_default _table_aliases() =====
Defines the SQL alias for the database tables the entity uses.
 
===== get_default_entity_title() =====
Defines the default title for this entity.
 
===== get_default_entity_name() =====
Defines the default internal name for this entity that will be used to manage columns and filters.
 
===== initialise() =====
This is where we '''add''' the entity columns and filters.
 
===== get_all_columns() and get_all_filters() =====
This is where we '''define''' the entity columns and filters.
 
==== Examples ====
 
Report Builder has two entities as an example to start building reports:
 
'''User entity''': reportbuilder/classes/local/entities/user.php<br />
'''Course entity''': reportbuilder/classes/local/entities/course.php
 
=== Actions ===
 
=== System reports ===
 
==== Use an entity ====

Latest revision as of 16:01, 23 May 2023

Important:

This content of this page has been updated and migrated to the new Moodle Developer Resources. The information contained on the page should no longer be seen up-to-date.

Why not view this page on the new site and help us to migrate more content to the new site!