mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 05:28:30 +01:00
MDL-80052 badges: Convert Badge recipients report to use Report builder
This commit is contained in:
parent
513f3b02c7
commit
982581d5eb
@ -107,7 +107,6 @@ class manage_badge_action_bar extends base_action_bar {
|
||||
],
|
||||
'bawards' => [
|
||||
'url' => '/badges/recipients.php',
|
||||
'additionalparams' => ['sort' => 'dateissued', 'dir' => 'DESC'],
|
||||
'capability' => 'moodle/badges:viewawarded'
|
||||
],
|
||||
'bendorsement' => [
|
||||
|
125
badges/classes/reportbuilder/local/systemreports/recipients.php
Normal file
125
badges/classes/reportbuilder/local/systemreports/recipients.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_badges\reportbuilder\local\systemreports;
|
||||
|
||||
use core_badges\reportbuilder\local\entities\badge_issued;
|
||||
use core_reportbuilder\local\report\action;
|
||||
use core_reportbuilder\system_report;
|
||||
use lang_string;
|
||||
use moodle_url;
|
||||
use pix_icon;
|
||||
|
||||
/**
|
||||
* Badge recipients system report class implementation
|
||||
*
|
||||
* @package core_badges
|
||||
* @copyright 2023 David Carrillo <davidmc@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class recipients extends system_report {
|
||||
|
||||
/**
|
||||
* Initialise report, we need to set the main table, load our entities and set columns/filters
|
||||
*/
|
||||
protected function initialise(): void {
|
||||
// Our main entity, it contains all of the column definitions that we need.
|
||||
$badgeissuedentity = new badge_issued();
|
||||
$entityalias = $badgeissuedentity->get_table_alias('badge_issued');
|
||||
|
||||
$this->set_main_table('badge_issued', $entityalias);
|
||||
$this->add_entity($badgeissuedentity);
|
||||
|
||||
$userentity = new \core_reportbuilder\local\entities\user();
|
||||
$entityuseralias = $userentity->get_table_alias('user');
|
||||
$this->add_entity($userentity
|
||||
->add_joins($userentity->get_joins())
|
||||
->add_join("JOIN {user} {$entityuseralias}
|
||||
ON {$entityuseralias}.id = {$entityalias}.userid")
|
||||
);
|
||||
|
||||
$this->add_base_condition_simple('badgeid', $this->get_parameter('badgeid', 0, PARAM_INT));
|
||||
|
||||
$this->add_base_fields("{$entityalias}.uniquehash");
|
||||
|
||||
// Now we can call our helper methods to add the content we want to include in the report.
|
||||
$this->add_columns();
|
||||
$this->add_filters();
|
||||
$this->add_actions();
|
||||
|
||||
// Set if report can be downloaded.
|
||||
$this->set_downloadable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates access to view this report
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function can_view(): bool {
|
||||
return has_capability('moodle/badges:viewawarded', $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the columns we want to display in the 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 = [
|
||||
'user:fullnamewithlink',
|
||||
'badge_issued:issued',
|
||||
];
|
||||
|
||||
$this->add_columns_from_entities($columns);
|
||||
$this->set_initial_sort_column('badge_issued:issued', SORT_DESC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the filters we want to display in the report
|
||||
*
|
||||
* They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
||||
* unique identifier
|
||||
*/
|
||||
protected function add_filters(): void {
|
||||
$filters = [
|
||||
'user:fullname',
|
||||
'badge_issued:issued',
|
||||
];
|
||||
|
||||
$this->add_filters_from_entities($filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the system report actions. An extra column will be appended to each row, containing all actions added here
|
||||
*
|
||||
* Note the use of ":uniquehash" placeholder which will be substituted according to actual values in the row
|
||||
*/
|
||||
protected function add_actions(): void {
|
||||
$this->add_action((new action(
|
||||
new moodle_url('/badges/badge.php', [
|
||||
'hash' => ':uniquehash',
|
||||
]),
|
||||
new pix_icon('i/search', '', 'core'),
|
||||
[],
|
||||
false,
|
||||
new lang_string('viewbadge', 'badges')
|
||||
)));
|
||||
}
|
||||
}
|
@ -28,9 +28,6 @@ require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
$badgeid = required_param('id', PARAM_INT);
|
||||
$sortby = optional_param('sort', 'dateissued', PARAM_ALPHA);
|
||||
$sorthow = optional_param('dir', 'DESC', PARAM_ALPHA);
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
|
||||
require_login();
|
||||
|
||||
@ -38,18 +35,6 @@ if (empty($CFG->enablebadges)) {
|
||||
throw new \moodle_exception('badgesdisabled', 'badges');
|
||||
}
|
||||
|
||||
if (!in_array($sortby, array('firstname', 'lastname', 'dateissued'))) {
|
||||
$sortby = 'dateissued';
|
||||
}
|
||||
|
||||
if ($sorthow != 'ASC' and $sorthow != 'DESC') {
|
||||
$sorthow = 'DESC';
|
||||
}
|
||||
|
||||
if ($page < 0) {
|
||||
$page = 0;
|
||||
}
|
||||
|
||||
$badge = new badge($badgeid);
|
||||
$context = $badge->get_context();
|
||||
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
|
||||
@ -73,7 +58,7 @@ if ($badge->type == BADGE_TYPE_COURSE) {
|
||||
}
|
||||
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url('/badges/recipients.php', array('id' => $badgeid, 'sort' => $sortby, 'dir' => $sorthow));
|
||||
$PAGE->set_url('/badges/recipients.php', ['id' => $badgeid]);
|
||||
$PAGE->set_heading($heading);
|
||||
$PAGE->set_title($badge->name);
|
||||
$PAGE->navbar->add($badge->name);
|
||||
@ -88,28 +73,9 @@ echo $output->render_tertiary_navigation($actionbar);
|
||||
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
|
||||
echo $output->print_badge_status_box($badge);
|
||||
|
||||
$userfieldsapi = \core_user\fields::for_name();
|
||||
$namefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
|
||||
$sql = "SELECT b.userid, b.dateissued, b.uniquehash, $namefields
|
||||
FROM {badge_issued} b INNER JOIN {user} u
|
||||
ON b.userid = u.id
|
||||
WHERE b.badgeid = :badgeid AND u.deleted = 0
|
||||
ORDER BY $sortby $sorthow";
|
||||
|
||||
$totalcount = $DB->count_records('badge_issued', array('badgeid' => $badge->id));
|
||||
|
||||
if ($badge->has_awards()) {
|
||||
$users = $DB->get_records_sql($sql, array('badgeid' => $badge->id), $page * BADGE_PERPAGE, BADGE_PERPAGE);
|
||||
$recipients = new core_badges\output\badge_recipients($users);
|
||||
$recipients->sort = $sortby;
|
||||
$recipients->dir = $sorthow;
|
||||
$recipients->page = $page;
|
||||
$recipients->perpage = BADGE_PERPAGE;
|
||||
$recipients->totalcount = $totalcount;
|
||||
|
||||
echo $output->render($recipients);
|
||||
} else {
|
||||
echo $output->notification(get_string('noawards', 'badges'));
|
||||
}
|
||||
$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'));
|
||||
echo $report->output();
|
||||
|
||||
echo $output->footer();
|
||||
|
@ -784,8 +784,12 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
*
|
||||
* @param \core_badges\output\badge_recipients $recipients
|
||||
* @return string
|
||||
*
|
||||
* @deprecated since Moodle 4.4
|
||||
* @todo MDL-80455 this will be removed in Moodle 4.8
|
||||
*/
|
||||
protected function render_badge_recipients(\core_badges\output\badge_recipients $recipients) {
|
||||
debugging('The method render_badge_recipients() has been deprecated', DEBUG_DEVELOPER);
|
||||
$paging = new paging_bar($recipients->totalcount, $recipients->page, $recipients->perpage, $this->page->url, 'page');
|
||||
$htmlpagingbar = $this->render($paging);
|
||||
$table = new html_table();
|
||||
|
@ -38,7 +38,8 @@ Feature: Display badges
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I follow "Testing system badge"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
When I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
And I open the action menu in "Student 1" "table_row"
|
||||
And I choose "View issued badge" in the open action menu
|
||||
Then I should see "Awarded to Student 1"
|
||||
And I should see "This badge has to be awarded by a user with the following role:"
|
||||
And I should not see "Expired"
|
||||
@ -63,7 +64,8 @@ Feature: Display badges
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I follow "Testing system badge"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
When I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
And I open the action menu in "Student 1" "table_row"
|
||||
And I choose "View issued badge" in the open action menu
|
||||
Then I should see "Awarded to Student 1"
|
||||
And I should see "Complete ALL of the listed requirements."
|
||||
And I should see "This badge has to be awarded by a user with the following role:"
|
||||
@ -84,7 +86,8 @@ Feature: Display badges
|
||||
And I press "Continue"
|
||||
# Check badge details are displayed.
|
||||
And I select "Recipients (2)" from the "jump" singleselect
|
||||
When I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
And I open the action menu in "Student 1" "table_row"
|
||||
And I choose "View issued badge" in the open action menu
|
||||
Then I should see "Awarded to Student 1"
|
||||
And I should see "Complete ANY of the listed requirements."
|
||||
And I should see "This badge has to be awarded by a user with the following role:"
|
||||
@ -112,7 +115,8 @@ Feature: Display badges
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I follow "Testing system badge"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
And I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
And I open the action menu in "Student 1" "table_row"
|
||||
And I choose "View issued badge" in the open action menu
|
||||
Then I should see "Expires"
|
||||
And I should not see "Expired"
|
||||
|
||||
@ -136,6 +140,7 @@ Feature: Display badges
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I follow "Testing system badge"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
And I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
And I open the action menu in "Student 1" "table_row"
|
||||
And I choose "View issued badge" in the open action menu
|
||||
Then I should see "Expired"
|
||||
And I should not see "Expires"
|
||||
|
Loading…
x
Reference in New Issue
Block a user