Author - Pawandeep Kaur Post Views - 8 views

Creating a Custom Report Source in Totara

In this post, we will discuss how to create a custom Report Builder source in Totara, drawing inspiration from the existing Seminar Room report and modifying it to display only empty rooms for future bookings.

Step 1: Copy an Existing Report Source

Locate the existing Seminar Room report source and create a new one inside your required plugin. For example, in our case, we are making it inside the Sequence plugin. Copy the file /mod/sequence/rb_sources/rb_source_sequence_rooms.php and rename it to rb_source_sequence_available_rooms.php.

Step 2: Rename the Report Source Class

Open the new file and update the class name like this:

Original: class rb_source_sequence_rooms extends rb_base_source {
Changed: class rb_source_sequence_available_rooms extends rb_base_source {

Step 3: Update the Source Title

Update the source title so it appears correctly in Report Builder. You can do this in two ways.

The first approach is to set the title using a language string, which is the recommended method. The second approach is to set the title directly inside the constructor of the newly created report source file. Below, both approaches are shown. The first function retrieves the title from the language file, while the second sets the title directly in the report source.

 

 

public function get_source_title() {

    return get_string(‘availablerooms’, ‘rb_source_sequence_rooms’);

}

Add the language string:

$string[‘availablerooms’] = ‘Available Rooms’;

Another way to add an inside construct function in new created file.

$this->sourcetitle = ‘Available Rooms’

 

Step 4: Reuse Sequence Room Base and Columns

Keep the same base table and column definitions used in the Seminar Room report.

Example:

protected function define_base() {

    $this->base = ‘{sequence_room}’;

}

Existing room-related columns, such as room name, capacity, and location, can be reused without changes. If you want to add custom columns inside the define_defaultcolumns() function, add columns like this:

$defaultcolumns = array(
            array(
                ‘type’ => ‘room’,
                ‘value’ => ‘custom_field_1’,
                ‘heading’ => null,
            ),
            array(
                ‘type’ => ‘room’,
                ‘value’ => ‘custom_field_2’,
                  ‘heading’ => null,
            )
   );


Step 5: Update Availability Logic for Future Bookings

Modify the availability logic so the report shows only rooms that are empty for future bookings. This is typically done by adding a condition that excludes rooms with future sessions. The logic looks like this:

WHERE NOT EXISTS (

    SELECT 1

    FROM {sequence_sessions} s

    WHERE s.roomid = base.id

      AND s.starttime >= :now

)

This ensures that only rooms with no upcoming bookings are included in the report. Then reuse the existing Room Availability filter from the Sequence Room report. The default behaviour shows available rooms, while still allowing users to filter by a specific date range if needed.

Step 6: Purge Caches

After creating the new report source, purge caches:

Site administration → Development → Purge caches

Step 7: Create the Report in Report Builder

    1. Go to Site administration → Reports → Report builder
    2. Click Create report
    3. Select Available Rooms as the report source
    4. Add required columns and filters; if not, then the default columns and filters that are mentioned in code will appear.
    5. Save the report

By copying and slightly modifying the existing base Seminar Room report source, we can quickly create a custom Available Rooms report that focuses on future availability while reusing existing logic and structure. This approach keeps the implementation simple, maintainable, and consistent with other Totara reports.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri