diff --git a/lang/en/reportbuilder.php b/lang/en/reportbuilder.php index e57310a6a64..bf0a2319fc8 100644 --- a/lang/en/reportbuilder.php +++ b/lang/en/reportbuilder.php @@ -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'; diff --git a/reportbuilder/classes/local/systemreports/report_schedules.php b/reportbuilder/classes/local/systemreports/report_schedules.php index 38cc002f798..98a8f307a1c 100644 --- a/reportbuilder/classes/local/systemreports/report_schedules.php +++ b/reportbuilder/classes/local/systemreports/report_schedules.php @@ -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, + ]) + ); } /** diff --git a/reportbuilder/classes/local/systemreports/reports_list.php b/reportbuilder/classes/local/systemreports/reports_list.php index 550b478f607..8fa43595246 100644 --- a/reportbuilder/classes/local/systemreports/reports_list.php +++ b/reportbuilder/classes/local/systemreports/reports_list.php @@ -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, diff --git a/reportbuilder/tests/behat/customreports.feature b/reportbuilder/tests/behat/customreports.feature index eaf71361d01..1544015fb54 100644 --- a/reportbuilder/tests/behat/customreports.feature +++ b/reportbuilder/tests/behat/customreports.feature @@ -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 | diff --git a/reportbuilder/tests/behat/schedules.feature b/reportbuilder/tests/behat/schedules.feature index 1b9c5bc1593..1ff6daf9bf0 100644 --- a/reportbuilder/tests/behat/schedules.feature +++ b/reportbuilder/tests/behat/schedules.feature @@ -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 "" "core_reportbuilder > Filter" to these values: + | operator | Range | + | from | ##2 days ago## | + | 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: