diff --git a/badges/classes/reportbuilder/local/systemreports/badges.php b/badges/classes/reportbuilder/local/systemreports/badges.php index 832f374350f..01d0a8753fb 100644 --- a/badges/classes/reportbuilder/local/systemreports/badges.php +++ b/badges/classes/reportbuilder/local/systemreports/badges.php @@ -77,8 +77,8 @@ class badges extends system_report { $this->add_filters(); $this->add_actions(); - // Set initial sorting by name. $this->set_initial_sort_column('badge:namewithlink', SORT_ASC); + $this->set_default_no_results_notice(new lang_string('nomatchingbadges', 'core_badges')); // Set if report can be downloaded. $this->set_downloadable(false); @@ -155,13 +155,12 @@ class badges extends system_report { * unique identifier */ protected function add_filters(): void { - $filters = [ + $this->add_filters_from_entities([ 'badge:name', 'badge:version', 'badge:status', 'badge:expiry', - ]; - $this->add_filters_from_entities($filters); + ]); } /** diff --git a/badges/classes/reportbuilder/local/systemreports/course_badges.php b/badges/classes/reportbuilder/local/systemreports/course_badges.php index 3bb42aa68f6..f415e287b66 100644 --- a/badges/classes/reportbuilder/local/systemreports/course_badges.php +++ b/badges/classes/reportbuilder/local/systemreports/course_badges.php @@ -70,9 +70,12 @@ class course_badges extends system_report { $this->add_base_fields("{$badgeissuedalias}.uniquehash"); // Now we can call our helper methods to add the content we want to include in the report. - $this->add_columns($badgeissuedalias); + $this->add_columns(); $this->add_filters(); + $this->set_initial_sort_column('badge:name', SORT_ASC); + $this->set_default_no_results_notice(new lang_string('nomatchingbadges', 'core_badges')); + // Set if report can be downloaded. $this->set_downloadable(false); } @@ -91,18 +94,17 @@ class course_badges extends system_report { * * They are provided by the entities we previously added in the {@see initialise} method, referencing each by their * unique identifier. If custom columns are needed just for this report, they can be defined here. - * - * @param string $badgeissuedalias */ - public function add_columns(string $badgeissuedalias): void { - $columns = [ + protected function add_columns(): void { + $badgeissuedalias = $this->get_entity('badge_issued')->get_table_alias('badge_issued'); + + $this->add_columns_from_entities([ 'badge:image', 'badge:name', 'badge:description', 'badge:criteria', 'badge_issued:issued', - ]; - $this->add_columns_from_entities($columns); + ]); $this->get_column('badge_issued:issued') ->set_title(new lang_string('awardedtoyou', 'core_badges')) @@ -119,8 +121,6 @@ class course_badges extends system_report { $icon = new pix_icon('i/valid', get_string('dateearned', 'badges', $date)); return $OUTPUT->action_icon($badgeurl, $icon, null, null, true); }); - - $this->set_initial_sort_column('badge:name', SORT_ASC); } /** @@ -130,11 +130,9 @@ class course_badges extends system_report { * unique identifier */ protected function add_filters(): void { - $filters = [ + $this->add_filters_from_entities([ 'badge:name', 'badge_issued:issued', - ]; - - $this->add_filters_from_entities($filters); + ]); } } diff --git a/badges/classes/reportbuilder/local/systemreports/recipients.php b/badges/classes/reportbuilder/local/systemreports/recipients.php index b2b2fbb2d04..2b4837f90e9 100644 --- a/badges/classes/reportbuilder/local/systemreports/recipients.php +++ b/badges/classes/reportbuilder/local/systemreports/recipients.php @@ -62,6 +62,9 @@ class recipients extends system_report { $this->add_filters(); $this->add_actions(); + $this->set_initial_sort_column('badge_issued:issued', SORT_DESC); + $this->set_default_no_results_notice(new lang_string('nomatchingawards', 'core_badges')); + // Set if report can be downloaded. $this->set_downloadable(false); } @@ -81,14 +84,11 @@ class recipients extends system_report { * They are provided by the entities we previously added in the {@see initialise} method, referencing each by their * unique identifier. If custom columns are needed just for this report, they can be defined here. */ - public function add_columns(): void { - $columns = [ + protected function add_columns(): void { + $this->add_columns_from_entities([ 'user:fullnamewithlink', 'badge_issued:issued', - ]; - - $this->add_columns_from_entities($columns); - $this->set_initial_sort_column('badge_issued:issued', SORT_DESC); + ]); } /** @@ -98,12 +98,10 @@ class recipients extends system_report { * unique identifier */ protected function add_filters(): void { - $filters = [ + $this->add_filters_from_entities([ 'user:fullname', 'badge_issued:issued', - ]; - - $this->add_filters_from_entities($filters); + ]); } /** diff --git a/badges/index.php b/badges/index.php index f6946207ad2..c3a3b77eac4 100644 --- a/badges/index.php +++ b/badges/index.php @@ -89,6 +89,8 @@ if (!has_any_capability(array( } $PAGE->set_title($hdr); + +/** @var core_badges_renderer $output */ $output = $PAGE->get_renderer('core', 'badges'); if ($delete || $archive) { @@ -159,9 +161,8 @@ if ($msg !== '') { } $report = system_report_factory::create(badges::class, $PAGE->context); -$report->set_default_no_results_notice(new lang_string('nobadges', 'badges')); - echo $report->output(); + $PAGE->requires->js_call_amd('core_badges/actions', 'init'); echo $OUTPUT->footer(); diff --git a/badges/recipients.php b/badges/recipients.php index 6a1120a19db..12cac6eb3db 100644 --- a/badges/recipients.php +++ b/badges/recipients.php @@ -24,6 +24,9 @@ * @author Yuliya Bozhko */ +use core_badges\reportbuilder\local\systemreports\recipients; +use core_reportbuilder\system_report_factory; + require_once(__DIR__ . '/../config.php'); require_once($CFG->libdir . '/badgeslib.php'); @@ -63,6 +66,7 @@ $PAGE->set_heading($heading); $PAGE->set_title($badge->name); $PAGE->navbar->add($badge->name); +/** @var core_badges_renderer $output */ $output = $PAGE->get_renderer('core', 'badges'); echo $output->header(); @@ -73,9 +77,7 @@ echo $output->render_tertiary_navigation($actionbar); echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name); echo $output->print_badge_status_box($badge); -$report = \core_reportbuilder\system_report_factory::create(\core_badges\reportbuilder\local\systemreports\recipients::class, - $PAGE->context, '', '', 0, ['badgeid' => $badge->id]); -$report->set_default_no_results_notice(new lang_string('noawards', 'badges')); +$report = system_report_factory::create(recipients::class, $PAGE->context, '', '', 0, ['badgeid' => $badge->id]); echo $report->output(); echo $output->footer(); diff --git a/badges/tests/behat/add_badge.feature b/badges/tests/behat/add_badge.feature index d5d8f0ec025..346406f90f2 100644 --- a/badges/tests/behat/add_badge.feature +++ b/badges/tests/behat/add_badge.feature @@ -17,7 +17,7 @@ Feature: Add badges to the system And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" Given I click on "Site badges" "link" in the "Navigation" "block" - Then I should see "There are currently no badges available for users to earn." + Then I should see "There are no matching badges available for users to earn" @javascript @_file_upload Scenario: Add a site badge @@ -53,7 +53,7 @@ Feature: Add badges to the system And I should see "Math" And I should see "Physics" And I navigate to "Badges > Manage badges" in site administration - And I should not see "There are currently no badges available for users to earn." + And I should not see "There are no matching badges available for users to earn" @javascript @_file_upload Scenario: Add a badge related @@ -165,7 +165,7 @@ Feature: Add badges to the system And I should see "Alignments (0)" And I should not see "Create badge" And I navigate to "Badges > Manage badges" in site administration - And I should not see "There are currently no badges available for users to earn." + And I should not see "There are no matching badges available for users to earn" # See buttons from the "Site badges" page. And I am on homepage When I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index 3a6a99a9511..d6c2c8498e1 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -90,7 +90,7 @@ Feature: Award badges And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" And I click on "Site badges" "link" in the "Navigation" "block" - Then I should see "There are currently no badges available for users to earn." + Then I should see "There are no matching badges available for users to earn" And I should not see "Manage badges" And I should not see "Add a new badge" @@ -127,7 +127,6 @@ Feature: Award badges And I press "Update profile" And I follow "Profile" in the user menu Then I should see "Profile Badge" - And I should not see "There are currently no badges available for users to earn." @javascript Scenario: Award site badge diff --git a/badges/tests/behat/delete_awarded_badge.feature b/badges/tests/behat/delete_awarded_badge.feature index 39ae200b387..9d4b7c31a90 100644 --- a/badges/tests/behat/delete_awarded_badge.feature +++ b/badges/tests/behat/delete_awarded_badge.feature @@ -44,8 +44,7 @@ Feature: Delete course badge already awarded # Navigate to Badges page to confirm that no badges exist, hence, Manage badges would not exist And I navigate to "Badges" in current page administration # Confirm that badges are sucessfully deleted - And I should see "There are currently no badges available for users to earn." - + And I should see "There are no matching badges available for users to earn" Examples: | badgename | deleteoption | visibility | | Badge 1 | Delete and keep existing issued badges | should | diff --git a/badges/tests/behat/manage_badges.feature b/badges/tests/behat/manage_badges.feature index 21bf0d38b0a..e6c4f00be51 100644 --- a/badges/tests/behat/manage_badges.feature +++ b/badges/tests/behat/manage_badges.feature @@ -45,7 +45,7 @@ Feature: Manage badges And I navigate to "Badges > Manage badges" in site administration And I press "Delete" action in the "Badge #1" report row And I press "Delete and remove existing issued badges" - Then I should see "There are currently no badges available for users to earn" + Then I should see "There are no matching badges available for users to earn" Scenario Outline: Filter managed badges Given the following "core_badges > Badges" exist: diff --git a/badges/tests/behat/nobadge_navigation.feature b/badges/tests/behat/nobadge_navigation.feature index 119e2d9298c..bb22d9b2a5f 100644 --- a/badges/tests/behat/nobadge_navigation.feature +++ b/badges/tests/behat/nobadge_navigation.feature @@ -4,7 +4,7 @@ Feature: Manage badges is not shown when there are no existing badges. Scenario: Check navigation at site level with no badges Given I log in as "admin" When I navigate to "Badges > Manage badges" in site administration - And I should see "There are currently no badges available for users to earn" + And I should see "There are no matching badges available for users to earn" Then "Manage badges" "button" should not exist Scenario: Check navigation at course level with no badges @@ -99,7 +99,7 @@ Feature: Manage badges is not shown when there are no existing badges. And I follow "Badges" And "Manage badges" "button" should not exist And "Add a new badge" "button" should not exist - And I should not see "There are currently no badges available for users to earn." - And the following should exist in the "reportbuilder-table" table: + And I should not see "There are no matching badges available for users to earn" + And the following should exist in the "Course badges" table: | Name | Description | Criteria | | Testing course badge | Testing course badge description | Awarded by: Teacher | diff --git a/badges/view.php b/badges/view.php index ff734c9eaf7..9ce804abdcf 100644 --- a/badges/view.php +++ b/badges/view.php @@ -24,6 +24,9 @@ * @author Yuliya Bozhko */ +use core_badges\reportbuilder\local\systemreports\course_badges; +use core_reportbuilder\system_report_factory; + require_once(__DIR__ . '/../config.php'); require_once($CFG->libdir . '/badgeslib.php'); @@ -67,6 +70,8 @@ if ($type == BADGE_TYPE_SITE) { require_capability('moodle/badges:viewbadges', $PAGE->context); $PAGE->set_title($title); + +/** @var core_badges_renderer $output */ $output = $PAGE->get_renderer('core', 'badges'); // Display "Manage badges" button to users with proper capabilities. @@ -98,9 +103,8 @@ if ($course && $course->startdate > time()) { echo $OUTPUT->box(get_string('error:notifycoursedate', 'badges'), 'generalbox notifyproblem'); } -$report = \core_reportbuilder\system_report_factory::create(\core_badges\reportbuilder\local\systemreports\course_badges::class, - $PAGE->context, '', '', 0, ['type' => $type, 'courseid' => $courseid]); -$report->set_default_no_results_notice(new lang_string('nobadges', 'badges')); +$report = system_report_factory::create(course_badges::class, $PAGE->context, '', '', 0, + ['type' => $type, 'courseid' => $courseid]); echo $report->output(); // Trigger event, badge listing viewed. diff --git a/lang/en/badges.php b/lang/en/badges.php index f1c90b58d2d..d0bfe834c86 100644 --- a/lang/en/badges.php +++ b/lang/en/badges.php @@ -424,11 +424,13 @@ $string['newbadgedeprecated'] = 'You have been redirected from badges/newbadge.p $string['newimage'] = 'New image'; $string['noalignment'] = 'This badge does not have any external skills or standards specified.'; $string['noawards'] = 'This badge has not been earned yet.'; +$string['nomatchingawards'] = 'There are no matching recipients who have earned this badge yet'; $string['nobackpack'] = 'There is no backpack service connected to this account.
'; $string['nobackpackbadgessummary'] = 'There are no badges in the collections you have selected.'; $string['nobackpackcollectionssummary'] = 'No badge collections have been selected.'; $string['nobackpacks'] = 'There are no backpacks available'; $string['nobadges'] = 'There are currently no badges available for users to earn.'; +$string['nomatchingbadges'] = 'There are no matching badges available for users to earn'; $string['nocompetencies'] = 'No competencies selected.'; $string['nocriteria'] = 'Criteria for this badge have not been set up yet.'; $string['noendorsement'] = 'This badge does not have an endorsement.'; diff --git a/reportbuilder/classes/local/report/base.php b/reportbuilder/classes/local/report/base.php index c54145b149d..4b9c9bf4aa2 100644 --- a/reportbuilder/classes/local/report/base.php +++ b/reportbuilder/classes/local/report/base.php @@ -855,8 +855,9 @@ abstract class base { /** * Set the default lang string for the notice used when no results are found. * + * Note this should be called from within the report class instance itself (ideally it would be protected) + * * @param lang_string|null $notice string, or null to tell the report to omit the notice entirely. - * @return void */ public function set_default_no_results_notice(?lang_string $notice): void { $this->noresultsnotice = $notice;