Merge branch 'MDL-82455-404' of https://github.com/paulholden/moodle into MOODLE_404_STABLE
This commit is contained in:
@@ -23,6 +23,7 @@ use core_badges\reportbuilder\local\entities\badge;
|
||||
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;
|
||||
@@ -42,6 +43,9 @@ require_once("{$CFG->libdir}/badgeslib.php");
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@@ -116,7 +120,6 @@ class badges extends system_report {
|
||||
$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(
|
||||
@@ -131,7 +134,14 @@ class badges extends system_report {
|
||||
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);
|
||||
@@ -289,6 +299,15 @@ class badges extends system_report {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
@@ -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 (moodle@example.com)"
|
||||
And I set the field "potentialrecipients[]" to "Admin User (moodle@example.com),User One (user1@example.com)"
|
||||
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 |
|
||||
|
||||
Reference in New Issue
Block a user