Skip to content

Commit

Permalink
Merge branch 'MDL-82455-404' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_404_STABLE
  • Loading branch information
sarjona committed Aug 19, 2024
2 parents d559cde + fafeeda commit 24e196b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
23 changes: 21 additions & 2 deletions badges/classes/reportbuilder/local/systemreports/badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use core_reportbuilder\local\helpers\database;
use core_reportbuilder\local\report\{action, column};
use core_reportbuilder\system_report;
use html_writer;
use lang_string;
use moodle_url;
use pix_icon;
Expand All @@ -42,6 +43,9 @@
*/
class badges extends system_report {

/** @var int $badgeid The ID of the current badge row */
private int $badgeid;

/**
* Initialise report, we need to set the main table, load our entities and set columns/filters
*/
Expand Down Expand Up @@ -116,7 +120,6 @@ public function add_columns(badge $badgeentity): void {
$this->add_columns_from_entities($columns);

// Issued badges column.
// TODO: Move this column to the entity when MDL-76392 is integrated.
$tempbadgealias = database::generate_alias();
$badgeentityalias = $badgeentity->get_table_alias('badge');
$this->add_column((new column(
Expand All @@ -131,7 +134,14 @@ public function add_columns(badge $badgeentity): void {
INNER JOIN {user} u
ON {$tempbadgealias}.userid = u.id
WHERE {$tempbadgealias}.badgeid = {$badgeentityalias}.id AND u.deleted = 0)", 'issued')
->set_is_sortable(true));
->set_is_sortable(true)
->set_callback(function(int $count): string {
if (!has_capability('moodle/badges:viewawarded', $this->get_context())) {
return (string) $count;
}

return html_writer::link(new moodle_url('/badges/recipients.php', ['id' => $this->badgeid]), $count);
}));

// Remove title from image column.
$this->get_column('badge:image')->set_title(null);
Expand Down Expand Up @@ -289,6 +299,15 @@ private static function get_badge_context(int $type, int $courseid): \core\conte
}
}

/**
* Store the ID of the badge within each row
*
* @param stdClass $row
*/
public function row_callback(stdClass $row): void {
$this->badgeid = (int) $row->id;
}

/**
* CSS classes to add to the row
*
Expand Down
16 changes: 12 additions & 4 deletions badges/tests/behat/manage_badges.feature
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ Feature: Manage badges
| Badge #1 | Not available |

Scenario: Award a badge
Given I log in as "admin"
Given the following "users" exist:
| username | firstname | lastname | email |
| user1 | User | One | user1@example.com |
When I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I press "Edit" action in the "Badge #1" report row
And I select "Criteria" from the "jump" singleselect
Expand All @@ -101,9 +104,14 @@ Feature: Manage badges
And I press "Enable access" action in the "Badge #1" report row
And I press "Continue"
And I press "Award badge" action in the "Badge #1" report row
And I set the field "potentialrecipients[]" to "Admin User ([email protected])"
And I set the field "potentialrecipients[]" to "Admin User ([email protected]),User One ([email protected])"
And I press "Award badge"
And I navigate to "Badges > Manage badges" in site administration
Then the following should exist in the "reportbuilder-table" table:
Then the following should exist in the "Badges" table:
| Name | Badge status | Recipients |
| Badge #1 | Available | 1 |
| Badge #1 | Available | 2 |
And I click on "2" "link" in the "Badge #1" "table_row"
And the following should exist in the "Recipients" table:
| -1- |
| Admin User |
| User One |

0 comments on commit 24e196b

Please sign in to comment.