mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-74456 reportbuilder: format report/schedule names in actions.
Ensure audience names are also formatted in scheduling form.
This commit is contained in:
parent
ad6dc71c56
commit
509bdf4bc5
reportbuilder
classes
tests/behat
@ -136,14 +136,14 @@ class schedule extends dynamic_form {
|
||||
$persistent = $audience->get_persistent();
|
||||
|
||||
// Check for a custom name, otherwise fall back to default.
|
||||
if ('' === $audiencelabel = (string) $persistent->get('heading')) {
|
||||
if ('' === $audiencelabel = $persistent->get_formatted_heading($context)) {
|
||||
$audiencelabel = get_string('audiencelabel', 'core_reportbuilder', (object) [
|
||||
'name' => $audience->get_name(),
|
||||
'description' => $audience->get_description(),
|
||||
]);
|
||||
}
|
||||
|
||||
$audiencecheckboxes[] = $mform->createElement('checkbox', $audience->get_persistent()->get('id'), $audiencelabel);
|
||||
$audiencecheckboxes[] = $mform->createElement('checkbox', $persistent->get('id'), $audiencelabel);
|
||||
}
|
||||
|
||||
$mform->addElement('group', 'audiences', '', $audiencecheckboxes, html_writer::div('', 'w-100 mb-2'));
|
||||
|
@ -18,6 +18,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\systemreports;
|
||||
|
||||
use context;
|
||||
use lang_string;
|
||||
use moodle_url;
|
||||
use pix_icon;
|
||||
@ -62,7 +63,9 @@ class report_schedules extends system_report {
|
||||
$this->add_join('JOIN {' . report::TABLE . '} rb ON rb.id = sc.reportid');
|
||||
|
||||
$this->add_base_condition_simple('sc.reportid', $this->get_parameter('reportid', 0, PARAM_INT));
|
||||
$this->add_base_fields('sc.id, sc.name, sc.enabled'); // Necessary for actions/row class.
|
||||
|
||||
// Select fields required for actions, permission checks, and row class callbacks.
|
||||
$this->add_base_fields('sc.id, sc.name, sc.enabled, rb.contextid');
|
||||
|
||||
// Join user entity for "User modified" column.
|
||||
$entityuser = new user();
|
||||
@ -280,21 +283,39 @@ class report_schedules extends system_report {
|
||||
));
|
||||
|
||||
// Send now action.
|
||||
$this->add_action(new action(
|
||||
$this->add_action((new action(
|
||||
new moodle_url('#'),
|
||||
new pix_icon('t/email', ''),
|
||||
['data-action' => 'schedule-send', 'data-schedule-id' => ':id', 'data-schedule-name' => ':name'],
|
||||
false,
|
||||
new lang_string('sendschedule', 'core_reportbuilder')
|
||||
));
|
||||
))
|
||||
->add_callback(function(stdClass $row): bool {
|
||||
|
||||
// Ensure data name attribute is properly formatted.
|
||||
$row->name = (new schedule(0, $row))->get_formatted_name(
|
||||
context::instance_by_id($row->contextid));
|
||||
|
||||
return true;
|
||||
})
|
||||
);
|
||||
|
||||
// Delete action.
|
||||
$this->add_action(new action(
|
||||
$this->add_action((new action(
|
||||
new moodle_url('#'),
|
||||
new pix_icon('t/delete', ''),
|
||||
['data-action' => 'schedule-delete', 'data-schedule-id' => ':id', 'data-schedule-name' => ':name'],
|
||||
false,
|
||||
new lang_string('deleteschedule', 'core_reportbuilder')
|
||||
));
|
||||
))
|
||||
->add_callback(function(stdClass $row): bool {
|
||||
|
||||
// Ensure data name attribute is properly formatted.
|
||||
$row->name = (new schedule(0, $row))->get_formatted_name(
|
||||
context::instance_by_id($row->contextid));
|
||||
|
||||
return true;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -64,9 +64,10 @@ class reports_list extends system_report {
|
||||
*/
|
||||
protected function initialise(): void {
|
||||
$this->set_main_table('reportbuilder_report', 'rb');
|
||||
|
||||
$this->add_base_condition_simple('rb.type', self::TYPE_CUSTOM_REPORT);
|
||||
$this->add_base_fields('rb.id, rb.name, rb.source, rb.type, rb.usercreated'); // Necessary for actions/row class.
|
||||
|
||||
// Select fields required for actions, permission checks, and row class callbacks.
|
||||
$this->add_base_fields('rb.id, rb.name, rb.source, rb.type, rb.usercreated, rb.contextid');
|
||||
|
||||
// If user can't view all reports, limit the returned list to those reports they can see.
|
||||
[$where, $params] = $this->filter_by_allowed_reports_sql();
|
||||
@ -244,7 +245,7 @@ class reports_list extends system_report {
|
||||
new lang_string('editreportcontent', 'core_reportbuilder')
|
||||
))
|
||||
->add_callback(function(stdClass $row): bool {
|
||||
return $this->report_source_valid($row->source) && permission::can_edit_report($this->get_report_from_row($row));
|
||||
return $this->report_source_valid($row->source) && permission::can_edit_report(new report(0, $row));
|
||||
})
|
||||
);
|
||||
|
||||
@ -257,7 +258,7 @@ class reports_list extends system_report {
|
||||
new lang_string('editreportdetails', 'core_reportbuilder')
|
||||
))
|
||||
->add_callback(function(stdClass $row): bool {
|
||||
return $this->report_source_valid($row->source) && permission::can_edit_report($this->get_report_from_row($row));
|
||||
return $this->report_source_valid($row->source) && permission::can_edit_report(new report(0, $row));
|
||||
})
|
||||
);
|
||||
|
||||
@ -271,7 +272,7 @@ class reports_list extends system_report {
|
||||
))
|
||||
->add_callback(function(stdClass $row): bool {
|
||||
// We check this only to give the action to editors, because normal users can just click on the report name.
|
||||
return $this->report_source_valid($row->source) && permission::can_edit_report($this->get_report_from_row($row));
|
||||
return $this->report_source_valid($row->source) && permission::can_edit_report(new report(0, $row));
|
||||
})
|
||||
);
|
||||
|
||||
@ -284,8 +285,13 @@ class reports_list extends system_report {
|
||||
new lang_string('deletereport', 'core_reportbuilder')
|
||||
))
|
||||
->add_callback(function(stdClass $row): bool {
|
||||
|
||||
// Ensure data name attribute is properly formatted.
|
||||
$report = new report(0, $row);
|
||||
$row->name = $report->get_formatted_name();
|
||||
|
||||
// We don't check whether report is valid to ensure editor can always delete them.
|
||||
return permission::can_edit_report($this->get_report_from_row($row));
|
||||
return permission::can_edit_report($report);
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -300,23 +306,6 @@ class reports_list extends system_report {
|
||||
return manager::report_source_exists($source, datasource::class) && manager::report_source_available($source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to return the report persistent from the row object.
|
||||
*
|
||||
* Note that this persistent, for performance reasons, is not complete and only contains id/type/usercreated fields, which
|
||||
* are needed for the permission methods.
|
||||
*
|
||||
* @param stdClass $row
|
||||
* @return report
|
||||
*/
|
||||
private function get_report_from_row(stdClass $row): report {
|
||||
return new report(0, (object)[
|
||||
'id' => $row->id,
|
||||
'type' => $row->type,
|
||||
'usercreated' => $row->usercreated,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the list of reports to return only the ones the user has access to
|
||||
*
|
||||
|
@ -111,6 +111,18 @@ Feature: Configure access to reports based on intended audience
|
||||
And I reload the page
|
||||
Then I should see "All my lovely users" in the "[data-region='audience-card']" "css_element"
|
||||
|
||||
Scenario: Rename report audience using filters
|
||||
Given the "multilang" filter is "on"
|
||||
And the "multilang" filter applies to "content and headings"
|
||||
And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
|
||||
And I click on the "Audience" dynamic tab
|
||||
And I click on "Add audience 'All users'" "link"
|
||||
And I press "Save changes"
|
||||
When I set the field "Rename audience 'All users'" to "<span class=\"multilang\" lang=\"en\">English</span><span class=\"multilang\" lang=\"es\">Spanish</span>"
|
||||
And I reload the page
|
||||
Then I should see "English" in the "[data-region='audience-card']" "css_element"
|
||||
And I should not see "Spanish" in the "[data-region='audience-card']" "css_element"
|
||||
|
||||
Scenario: Delete report audience
|
||||
Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
|
||||
And I click on the "Audience" dynamic tab
|
||||
|
@ -69,6 +69,23 @@ Feature: Manage custom reports
|
||||
| Name | Report source |
|
||||
| My renamed report | Users |
|
||||
|
||||
Scenario: Rename custom report using filters
|
||||
Given the "multilang" filter is "on"
|
||||
And the "multilang" filter applies to "content and headings"
|
||||
And the following "core_reportbuilder > Reports" exist:
|
||||
| name | source |
|
||||
| My report | 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 set the field "Edit report name" in the "My report" "table_row" to "<span class=\"multilang\" lang=\"en\">English</span><span class=\"multilang\" lang=\"es\">Spanish</span>"
|
||||
And I reload the page
|
||||
Then I should see "English" in the "reportbuilder-table" "table"
|
||||
And I should not see "Spanish" in the "reportbuilder-table" "table"
|
||||
# Confirm report name is correctly shown in action.
|
||||
And I press "Delete report" action in the "English" report row
|
||||
And I should see "Are you sure you want to delete the report 'English' and all associated data?" in the "Delete report" "dialogue"
|
||||
And I click on "Cancel" "button" in the "Delete report" "dialogue"
|
||||
|
||||
Scenario: Edit custom report from the custom reports page
|
||||
Given the following "core_reportbuilder > Reports" exist:
|
||||
| name | source |
|
||||
|
@ -44,6 +44,18 @@ Feature: Manage custom report schedules
|
||||
| Name | Starting from | Time last sent | Modified by |
|
||||
| My schedule | ##tomorrow 11:00##%A, %d %B %Y, %H:%M## | Never | Admin User |
|
||||
|
||||
Scenario: Create report schedule for audience renamed using filters
|
||||
Given the "multilang" filter is "on"
|
||||
And the "multilang" filter applies to "content and headings"
|
||||
And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
|
||||
And I click on the "Audience" dynamic tab
|
||||
And I set the field "Rename audience 'All users'" to "<span class=\"multilang\" lang=\"en\">English</span><span class=\"multilang\" lang=\"es\">Spanish</span>"
|
||||
When I click on the "Schedules" dynamic tab
|
||||
And I press "New schedule"
|
||||
Then I should see "English" in the "New schedule" "dialogue"
|
||||
And I should not see "Spanish" in the "New schedule" "dialogue"
|
||||
And I click on "Cancel" "button" in the "New schedule" "dialogue"
|
||||
|
||||
Scenario: Rename report schedule
|
||||
Given the following "core_reportbuilder > Schedule" exists:
|
||||
| report | My report |
|
||||
@ -54,6 +66,26 @@ Feature: Manage custom report schedules
|
||||
And I reload the page
|
||||
Then I should see "My renamed schedule" in the "reportbuilder-table" "table"
|
||||
|
||||
Scenario: Rename report schedule using filters
|
||||
Given the "multilang" filter is "on"
|
||||
And the "multilang" filter applies to "content and headings"
|
||||
And the following "core_reportbuilder > Schedule" exists:
|
||||
| report | My report |
|
||||
| name | My schedule |
|
||||
And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
|
||||
And I click on the "Schedules" dynamic tab
|
||||
When I set the field "Edit schedule name" in the "My schedule" "table_row" to "<span class=\"multilang\" lang=\"en\">English</span><span class=\"multilang\" lang=\"es\">Spanish</span>"
|
||||
And I reload the page
|
||||
Then I should see "English" in the "reportbuilder-table" "table"
|
||||
And I should not see "Spanish" in the "reportbuilder-table" "table"
|
||||
# Confirm schedule name is correctly shown in actions.
|
||||
And I press "Send schedule" action in the "English" report row
|
||||
And I should see "Are you sure you want to queue the schedule 'English' for sending immediately?" in the "Send schedule" "dialogue"
|
||||
And I click on "Cancel" "button" in the "Send schedule" "dialogue"
|
||||
And I press "Delete schedule" action in the "English" report row
|
||||
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: Toggle report schedule
|
||||
Given the following "core_reportbuilder > Schedules" exist:
|
||||
| report | name |
|
||||
|
Loading…
x
Reference in New Issue
Block a user