mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-73916 reportbuilder: Allow to set default condition values
- Changes on datasource class to allow to set default condition values - Added default condition 'suspended' set to 'no' on users datasource
This commit is contained in:
parent
5500d143f4
commit
c6777c9cbf
4 changed files with 47 additions and 2 deletions
|
@ -239,6 +239,9 @@ abstract class datasource extends base {
|
||||||
foreach ($conditionidentifiers as $uniqueidentifier) {
|
foreach ($conditionidentifiers as $uniqueidentifier) {
|
||||||
report::add_report_condition($reportid, $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;
|
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
|
* Return all configured report conditions
|
||||||
*
|
*
|
||||||
|
|
|
@ -5,7 +5,11 @@ Feature: Manage custom reports
|
||||||
I need to create new and edit existing reports
|
I need to create new and edit existing reports
|
||||||
|
|
||||||
Scenario: Create custom report with default setup
|
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"
|
And I change window size to "large"
|
||||||
When I navigate to "Reports > Report builder > Custom reports" in site administration
|
When I navigate to "Reports > Report builder > Custom reports" in site administration
|
||||||
And I click on "New report" "button"
|
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 "Full name" in the "reportbuilder-table" "table"
|
||||||
And I should see "Username" 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"
|
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.
|
# Confirm we see the default conditions in the report.
|
||||||
And I click on "Show/hide 'Conditions'" "button"
|
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 "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 "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 "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.
|
# Confirm we see the default filters in the report.
|
||||||
And I click on "Switch to preview mode" "button"
|
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"
|
And I click on "Filters" "button" in the "[data-region='core_reportbuilder/report-header']" "css_element"
|
||||||
|
|
|
@ -11,3 +11,5 @@ Information provided here is intended especially for developers.
|
||||||
* The base aggregation `format_value` method has a `$columntype` argument in order to preserve type during aggregation. When
|
* The base aggregation `format_value` method has a `$columntype` argument in order to preserve type during aggregation. When
|
||||||
defining column callbacks, strict typing will now be preserved in your callback methods when the column is being aggregated
|
defining column callbacks, strict typing will now be preserved in your callback methods when the column is being aggregated
|
||||||
* The method `get_joins()` in the base entity class is now public, allowing for easier joins within reports
|
* The method `get_joins()` in the base entity class is now public, allowing for easier joins within reports
|
||||||
|
* 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.
|
||||||
|
|
|
@ -20,6 +20,7 @@ namespace core_user\reportbuilder\datasource;
|
||||||
|
|
||||||
use core_reportbuilder\datasource;
|
use core_reportbuilder\datasource;
|
||||||
use core_reportbuilder\local\entities\user;
|
use core_reportbuilder\local\entities\user;
|
||||||
|
use core_reportbuilder\local\filters\boolean_select;
|
||||||
use core_reportbuilder\local\helpers\database;
|
use core_reportbuilder\local\helpers\database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,6 +88,22 @@ class users extends datasource {
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function get_default_conditions(): array {
|
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,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue