From f466b40ca616e7b3f5d35553a5c5dfaa240cb07a Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 19 Sep 2024 11:17:30 +0100 Subject: [PATCH] MDL-83202 reportbuilder: report list filtering by time/user modified. --- .../local/systemreports/reports_list.php | 25 +++++++++++++ .../tests/behat/customreports.feature | 37 ++++++++++++++++--- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/reportbuilder/classes/local/systemreports/reports_list.php b/reportbuilder/classes/local/systemreports/reports_list.php index 9cf21f88da2..550b478f607 100644 --- a/reportbuilder/classes/local/systemreports/reports_list.php +++ b/reportbuilder/classes/local/systemreports/reports_list.php @@ -258,8 +258,33 @@ class reports_list extends system_report { ->set_limited_operators([ date::DATE_ANY, date::DATE_RANGE, + date::DATE_BEFORE, + date::DATE_LAST, + date::DATE_CURRENT, ]) ); + + // Time modified filter. + $this->add_filter((new filter( + date::class, + 'timemodified', + new lang_string('timemodified', 'core_reportbuilder'), + $this->get_report_entity_name(), + "{$tablealias}.timemodified", + )) + ->set_limited_operators([ + date::DATE_ANY, + date::DATE_RANGE, + date::DATE_BEFORE, + date::DATE_LAST, + date::DATE_CURRENT, + ]) + ); + + // User modified filter. + $this->add_filter_from_entity('user:userselect') + ->set_header(new lang_string('usermodified', 'reportbuilder')) + ->set_is_available(has_capability('moodle/user:viewalldetails', $this->get_context())); } /** diff --git a/reportbuilder/tests/behat/customreports.feature b/reportbuilder/tests/behat/customreports.feature index 88285d76879..eaf71361d01 100644 --- a/reportbuilder/tests/behat/customreports.feature +++ b/reportbuilder/tests/behat/customreports.feature @@ -178,24 +178,49 @@ Feature: Manage custom reports | Report source | Users | | Tags | Cat | - Scenario: Filter custom reports by date + Scenario: Filter custom reports by user + Given the following "users" exist: + | username | firstname | lastname | + | user1 | User | 1 | + And the following "core_reportbuilder > Report" exists: + | name | My report | + | source | core_user\reportbuilder\datasource\users | + 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 following fields in the "Modified by" "core_reportbuilder > Filter" to these values: + | Modified by operator | Select | + | Modified by value | Admin User | + 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 report" in the "Reports list" "table" + And I set the field "Modified by value" in the "Modified by" "core_reportbuilder > Filter" to "User 1" + And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element" + And I should see "Nothing to display" + And "Reports list" "table" should not exist + + Scenario Outline: Filter custom reports by date Given the following "core_reportbuilder > Report" exists: | name | My report | | source | core_user\reportbuilder\datasource\users | 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 following fields in the "Time created" "core_reportbuilder > Filter" to these values: - | Time created operator | Range | - | Time created from | ##2 days ago## | - | Time created to | ##tomorrow## | + And I set the following fields in the "" "core_reportbuilder > Filter" to these values: + | operator | Range | + | from | ##2 days ago## | + | to | ##tomorrow## | 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 report" in the "Reports list" "table" - And I set the field "Time created to" in the "Time created" "core_reportbuilder > Filter" to "##yesterday##" + And I set the field " to" in the "" "core_reportbuilder > Filter" to "##yesterday##" And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element" And I should see "Nothing to display" And "Reports list" "table" should not exist + Examples: + | filter | + | Time created | + | Time modified | Scenario: Reset filters in system report Given the following "core_reportbuilder > Report" exists: