Merge branch 'MDL-73916-master' of https://github.com/dravek/moodle

This commit is contained in:
Shamim Rezaie 2022-06-09 13:45:12 +10:00 committed by Sara Arjona
commit dea18d2f47
4 changed files with 47 additions and 2 deletions

View File

@ -239,6 +239,9 @@ abstract class datasource extends base {
foreach ($conditionidentifiers as $uniqueidentifier) {
report::add_report_condition($reportid, $uniqueidentifier);
}
// Set the default condition values if they have been set in the datasource.
$this->set_condition_values($this->get_default_condition_values());
}
/**
@ -248,6 +251,18 @@ abstract class datasource extends base {
*/
abstract public function get_default_conditions(): array;
/**
* Return the default condition values that will be added to the report once is created
*
* For any of the default conditions returned by the method {@see get_default_conditions} is
* possible to set the initial values.
*
* @return array
*/
public function get_default_condition_values(): array {
return [];
}
/**
* Return all configured report conditions
*

View File

@ -5,7 +5,11 @@ Feature: Manage custom reports
I need to create new and edit existing reports
Scenario: Create custom report with default setup
Given I log in as "admin"
Given the following "users" exist:
| username | firstname | lastname | suspended |
| user1 | User | 1 | 1 |
| user2 | User | 2 | 0 |
And I log in as "admin"
And I change window size to "large"
When I navigate to "Reports > Report builder > Custom reports" in site administration
And I click on "New report" "button"
@ -19,11 +23,18 @@ Feature: Manage custom reports
And I should see "Full name" in the "reportbuilder-table" "table"
And I should see "Username" in the "reportbuilder-table" "table"
And I should see "Email address" in the "reportbuilder-table" "table"
# Confirm we only see not suspended users in the report.
And I should see "Admin User" in the "reportbuilder-table" "table"
And I should see "User 2" in the "reportbuilder-table" "table"
And I should not see "User 1" in the "reportbuilder-table" "table"
# Confirm we see the default conditions in the report.
And I click on "Show/hide 'Conditions'" "button"
Then I should see "Full name" in the "[data-region='settings-conditions']" "css_element"
Then I should see "Username" in the "[data-region='settings-conditions']" "css_element"
Then I should see "Email address" in the "[data-region='settings-conditions']" "css_element"
Then I should see "Suspended" in the "[data-region='settings-conditions']" "css_element"
And the following fields in the "Suspended" "core_reportbuilder > Condition" match these values:
| Suspended operator | No |
# Confirm we see the default filters in the report.
And I click on "Switch to preview mode" "button"
And I click on "Filters" "button" in the "[data-region='core_reportbuilder/report-header']" "css_element"

View File

@ -17,3 +17,5 @@ Information provided here is intended especially for developers.
* The following permission methods now accept an optional `$context` parameter (default system context):
- `[require_]can_view_reports_list`
- `[require_]can_create_report`
* New method `get_default_condition_values()` in base datasource class, to be overridden by sources that wish to
define default values for conditions upon report creation.

View File

@ -20,6 +20,7 @@ namespace core_user\reportbuilder\datasource;
use core_reportbuilder\datasource;
use core_reportbuilder\local\entities\user;
use core_reportbuilder\local\filters\boolean_select;
use core_reportbuilder\local\helpers\database;
/**
@ -87,6 +88,22 @@ class users extends datasource {
* @return string[]
*/
public function get_default_conditions(): array {
return ['user:fullname', 'user:username', 'user:email'];
return [
'user:fullname',
'user:username',
'user:email',
'user:suspended',
];
}
/**
* Return the conditions values that will be added to the report once is created
*
* @return array
*/
public function get_default_condition_values(): array {
return [
'user:suspended_operator' => boolean_select::NOT_CHECKED,
];
}
}