MDL-82088 reportbuilder: improve filtering by report schedule data.

This commit is contained in:
Paul Holden 2024-09-19 11:51:52 +01:00
parent d015c4c213
commit 791eefd450
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
5 changed files with 103 additions and 27 deletions

View File

@ -272,6 +272,7 @@ $string['timeadded'] = 'Time added';
$string['timecreated'] = 'Time created';
$string['timelastsent'] = 'Time last sent';
$string['timemodified'] = 'Time modified';
$string['timenextsend'] = 'Time next send';
$string['uniquerows'] = 'Remove any duplicate rows';
$string['uniquerows_help'] = 'If the report source contains duplicate rows, should these be removed from this report? This setting has no effect if report columns are aggregated.';
$string['userany'] = 'Any user';

View File

@ -161,18 +161,6 @@ class report_schedules extends system_report {
})
);
// Time scheduled column.
$this->add_column((new column(
'timescheduled',
new lang_string('startingfrom'),
$this->get_schedule_entity_name()
))
->set_type(column::TYPE_TIMESTAMP)
->add_fields("{$tablealias}.timescheduled")
->set_is_sortable(true)
->add_callback([format::class, 'userdate'])
);
// Time last sent column.
$this->add_column((new column(
'timelastsent',
@ -191,6 +179,24 @@ class report_schedules extends system_report {
})
);
// Time next send column.
$this->add_column((new column(
'timenextsend',
new lang_string('timenextsend', 'core_reportbuilder'),
$this->get_schedule_entity_name()
))
->set_type(column::TYPE_TIMESTAMP)
->add_fields("{$tablealias}.timenextsend")
->set_is_sortable(true)
->add_callback(static function(int $timenextsend, stdClass $row): string {
if ($timenextsend < time()) {
return get_string('never');
}
return format::userdate($timenextsend, $row);
})
);
// Format column.
$this->add_column((new column(
'format',
@ -256,7 +262,7 @@ class report_schedules extends system_report {
"{$tablealias}.name"
)));
// Time created filter.
// Time last sent filter.
$this->add_filter((new filter(
date::class,
'timelastsent',
@ -267,12 +273,31 @@ class report_schedules extends system_report {
->set_limited_operators([
date::DATE_ANY,
date::DATE_EMPTY,
date::DATE_NOT_EMPTY,
date::DATE_RANGE,
date::DATE_PREVIOUS,
date::DATE_BEFORE,
date::DATE_LAST,
date::DATE_CURRENT,
])
);
// Time next send filter.
$this->add_filter((new filter(
date::class,
'timenextsend',
new lang_string('timenextsend', 'core_reportbuilder'),
$this->get_schedule_entity_name(),
"{$tablealias}.timenextsend"
))
->set_limited_operators([
date::DATE_ANY,
date::DATE_RANGE,
date::DATE_PAST,
date::DATE_NEXT,
date::DATE_AFTER,
date::DATE_CURRENT,
])
);
}
/**

View File

@ -27,15 +27,9 @@ use core_reportbuilder\datasource;
use core_reportbuilder\manager;
use core_reportbuilder\system_report;
use core_reportbuilder\local\entities\user;
use core_reportbuilder\local\filters\date;
use core_reportbuilder\local\filters\tags;
use core_reportbuilder\local\filters\text;
use core_reportbuilder\local\filters\select;
use core_reportbuilder\local\helpers\audience;
use core_reportbuilder\local\helpers\format;
use core_reportbuilder\local\report\action;
use core_reportbuilder\local\report\column;
use core_reportbuilder\local\report\filter;
use core_reportbuilder\local\filters\{boolean_select, date, tags, text, select};
use core_reportbuilder\local\helpers\{audience, format};
use core_reportbuilder\local\report\{action, column, filter};
use core_reportbuilder\output\report_name_editable;
use core_reportbuilder\local\models\report;
use core_reportbuilder\permission;
@ -232,6 +226,15 @@ class reports_list extends system_report {
})
);
// Schedules filter.
$this->add_filter((new filter(
boolean_select::class,
'schedules',
new lang_string('schedules', 'core_reportbuilder'),
$this->get_report_entity_name(),
"CASE WHEN EXISTS (SELECT 1 FROM {reportbuilder_schedule} WHERE reportid = {$tablealias}.id) THEN 1 ELSE 0 END"
)));
// Tags filter.
$this->add_filter((new filter(
tags::class,

View File

@ -222,6 +222,27 @@ Feature: Manage custom reports
| Time created |
| Time modified |
Scenario: Filter custom reports by schedule presence
Given the following "core_reportbuilder > Reports" exist:
| name | source |
| My users | core_user\reportbuilder\datasource\users |
| My courses | core_course\reportbuilder\datasource\courses |
And the following "core_reportbuilder > Schedules" exist:
| report | name |
| My users | My schedule |
And I log in as "admin"
When I navigate to "Reports > Report builder > Custom reports" in site administration
And I click on "Filters" "button"
And I set the field "Schedules operator" in the "Schedules" "core_reportbuilder > Filter" to "Yes"
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
Then I should see "Filters applied"
And I should see "My users" in the "Reports list" "table"
And I should not see "My courses" in the "Reports list" "table"
And I set the field "Schedules operator" in the "Schedules" "core_reportbuilder > Filter" to "No"
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
And I should see "My courses" in the "Reports list" "table"
And I should not see "My users" in the "Reports list" "table"
Scenario: Reset filters in system report
Given the following "core_reportbuilder > Report" exists:
| name | My report |

View File

@ -41,8 +41,8 @@ Feature: Manage custom report schedules
And I click on "Save" "button" in the "New schedule" "dialogue"
Then I should see "Schedule created"
And the following should exist in the "Report schedules" table:
| Name | Starting from | Time last sent | Modified by |
| My schedule | ##tomorrow 11:00##%A, %d %B %Y, %H:%M## | Never | Admin User |
| Name | Time last sent | Time next send | Modified by |
| My schedule | Never | ##tomorrow 11:00##%A, %d %B %Y, %H:%M## | Admin User |
Scenario: Create report schedule for audience renamed using filters
Given the "multilang" filter is "on"
@ -86,6 +86,27 @@ Feature: Manage custom report schedules
And I should see "Are you sure you want to delete the schedule 'English'?" in the "Delete schedule" "dialogue"
And I click on "Cancel" "button" in the "Delete schedule" "dialogue"
Scenario Outline: Filter report schedules by date
Given the following "core_reportbuilder > Schedules" exist:
| report | name | timescheduled | timelastsent |
| My report | My schedule 1 | ##yesterday## | ##yesterday## |
| My report | My schedule 2 | ##tomorrow## | 0 |
And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
When I click on the "Schedules" dynamic tab
And I click on "Filters" "button"
And I set the following fields in the "<filter>" "core_reportbuilder > Filter" to these values:
| <filter> operator | Range |
| <filter> from | ##2 days ago## |
| <filter> to | ##today## |
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
Then I should see "Filters applied"
And I should see "My schedule 1" in the "Report schedules" "table"
And I should not see "My schedule 2" in the "Report schedules" "table"
Examples:
| filter |
| Time last sent |
| Time next send |
Scenario: Toggle report schedule
Given the following "core_reportbuilder > Schedules" exist:
| report | name |
@ -110,8 +131,8 @@ Feature: Manage custom report schedules
And I click on "Save" "button" in the "Edit schedule details" "dialogue"
Then I should see "Schedule updated"
And the following should exist in the "Report schedules" table:
| Name | Starting from |
| My updated schedule | ##tomorrow 11:00##%A, %d %B %Y, %H:%M## |
| Name | Time last sent | Time next send | Modified by |
| My updated schedule | Never | ##tomorrow 11:00##%A, %d %B %Y, %H:%M## | Admin User |
Scenario: Send report schedule
Given the following "core_reportbuilder > Schedules" exist:
@ -122,6 +143,11 @@ Feature: Manage custom report schedules
When I press "Send schedule" action in the "My schedule" report row
And I click on "Confirm" "button" in the "Send schedule" "dialogue"
Then I should see "Schedule sent"
And I run all adhoc tasks
And I reload the page
And the following should exist in the "Report schedules" table:
| Name | Time last sent |
| My schedule | ##today##%A## |
Scenario: Delete report schedule
Given the following "core_reportbuilder > Schedules" exist: