This commit is contained in:
Andrew Nicols 2023-09-05 10:53:19 +08:00
commit ee81bfabe8
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
14 changed files with 482 additions and 60 deletions

View File

@ -110,6 +110,25 @@ class badge extends base {
->add_field("{$badgealias}.name")
->set_is_sortable(true);
// Name with link.
$columns[] = (new column(
'namewithlink',
new lang_string('namewithlink', 'core_badges'),
$this->get_entity_name()
))
->add_joins($this->get_joins())
->set_type(column::TYPE_TEXT)
->add_fields("{$badgealias}.name, {$badgealias}.id")
->set_is_sortable(true)
->add_callback(static function(?string $value, stdClass $row): string {
if (!$row->id) {
return '';
}
$url = new moodle_url('/badges/overview.php', ['id' => $row->id]);
return html_writer::link($url, $row->name);
});
// Description (note, this column contains plaintext so requires no post-processing).
$descriptionfieldsql = "{$badgealias}.description";
if ($DB->get_dbfamily() === 'oracle') {
@ -212,7 +231,11 @@ class badge extends base {
->add_field("{$badgealias}.status")
->set_is_sortable(true)
->add_callback(static function($status): string {
return $status ? get_string("badgestatus_{$status}", 'core_badges') : '';
if ($status === null) {
return '';
}
return get_string("badgestatus_{$status}", 'core_badges');
});
// Expiry date/period.

View File

@ -0,0 +1,297 @@
<?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\context\{course, system};
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 lang_string;
use moodle_url;
use pix_icon;
use stdClass;
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once("{$CFG->libdir}/badgeslib.php");
/**
* Badges 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 badges 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.
$badgeentity = new badge();
$entityalias = $badgeentity->get_table_alias('badge');
$this->set_main_table('badge', $entityalias);
$this->add_entity($badgeentity);
$paramtype = database::generate_param_name();
$context = $this->get_context();
if ($context instanceof system) {
$type = BADGE_TYPE_SITE;
$this->add_base_condition_sql("{$entityalias}.type = :$paramtype", [$paramtype => $type]);
} else {
$type = BADGE_TYPE_COURSE;
$paramcourseid = database::generate_param_name();
$this->add_base_condition_sql("{$entityalias}.type = :$paramtype AND {$entityalias}.courseid = :$paramcourseid",
[$paramtype => $type, $paramcourseid => $context->instanceid]);
}
// Any columns required by actions should be defined here to ensure they're always available.
$this->add_base_fields("{$entityalias}.id, {$entityalias}.type, {$entityalias}.courseid, {$entityalias}.status");
// Now we can call our helper methods to add the content we want to include in the report.
$this->add_columns($badgeentity);
$this->add_filters();
$this->add_actions();
// Set initial sorting by name.
$this->set_initial_sort_column('badge:namewithlink', SORT_ASC);
// 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_any_capability([
'moodle/badges:viewawarded',
'moodle/badges:createbadge',
'moodle/badges:awardbadge',
'moodle/badges:configurecriteria',
'moodle/badges:configuremessages',
'moodle/badges:configuredetails',
'moodle/badges:deletebadge'], $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.
*
* @param badge $badgeentity
*/
public function add_columns(badge $badgeentity): void {
$columns = [
'badge:image',
'badge:namewithlink',
'badge:status',
'badge:criteria',
];
$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(
'issued',
new lang_string('awards', 'core_badges'),
$badgeentity->get_entity_name()
))
->add_joins($this->get_joins())
->set_type(column::TYPE_INTEGER)
->add_field("(SELECT COUNT({$tempbadgealias}.userid)
FROM {badge_issued} {$tempbadgealias}
INNER JOIN {user} u
ON {$tempbadgealias}.userid = u.id
WHERE {$tempbadgealias}.badgeid = {$badgeentityalias}.id AND u.deleted = 0)", 'issued')
->set_is_sortable(true));
// Remove title from image column.
$this->get_column('badge:image')->set_title(null);
// Change title from namewithlink column.
$this->get_column('badge:namewithlink')->set_title(new lang_string('name'));
}
/**
* 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 = [
'badge:name',
'badge:status',
];
$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 ":id" placeholder which will be substituted according to actual values in the row
*/
protected function add_actions(): void {
// Activate badge.
$this->add_action((new action(
new moodle_url('/badges/action.php', [
'id' => ':id',
'sesskey' => sesskey(),
'activate' => true,
'return' => (new moodle_url(qualified_me()))->out_as_local_url(false),
]),
new pix_icon('t/show', '', 'core'),
[],
false,
new lang_string('activate', 'badges')
))->add_callback(static function(stdclass $row): bool {
$badge = new \core_badges\badge($row->id);
$context = self::get_badge_context((int)$row->type, (int)$row->courseid);
return has_capability('moodle/badges:configuredetails', $context) &&
$badge->has_criteria() &&
($row->status == BADGE_STATUS_INACTIVE || $row->status == BADGE_STATUS_INACTIVE_LOCKED);
}));
// Deactivate badge.
$this->add_action((new action(
new moodle_url('/badges/index.php', [
'lock' => ':id',
'sesskey' => sesskey(),
'type' => ':type',
'id' => ':courseid',
]),
new pix_icon('t/hide', '', 'core'),
[],
false,
new lang_string('deactivate', 'badges')
))->add_callback(static function(stdclass $row): bool {
$badge = new \core_badges\badge($row->id);
$context = self::get_badge_context((int)$row->type, (int)$row->courseid);
return has_capability('moodle/badges:configuredetails', $context) &&
$badge->has_criteria() &&
$row->status != BADGE_STATUS_INACTIVE && $row->status != BADGE_STATUS_INACTIVE_LOCKED;
}));
// Award badge manually.
$this->add_action((new action(
new moodle_url('/badges/award.php', [
'id' => ':id',
]),
new pix_icon('t/award', '', 'core'),
[],
false,
new lang_string('award', 'badges')
))->add_callback(static function(stdclass $row): bool {
$badge = new \core_badges\badge($row->id);
$context = self::get_badge_context((int)$row->type, (int)$row->courseid);
return $badge->has_manual_award_criteria() &&
has_capability('moodle/badges:awardbadge', $context) &&
$badge->is_active();
}));
// Edit action.
$this->add_action((new action(
new moodle_url('/badges/edit.php', [
'id' => ':id',
'action' => 'badge',
]),
new pix_icon('t/edit', '', 'core'),
[],
false,
new lang_string('edit', 'core')
))->add_callback(static function(stdclass $row): bool {
$context = self::get_badge_context((int)$row->type, (int)$row->courseid);
return has_capability('moodle/badges:configuredetails', $context);
}));
// Duplicate action.
$this->add_action((new action(
new moodle_url('/badges/action.php', [
'id' => ':id',
'copy' => 1,
'sesskey' => sesskey(),
]),
new pix_icon('t/copy', '', 'core'),
[],
false,
new lang_string('copy', 'badges')
))->add_callback(static function(stdclass $row): bool {
$context = self::get_badge_context((int)$row->type, (int)$row->courseid);
return has_capability('moodle/badges:createbadge', $context);
}));
// Delete action.
$this->add_action((new action(
new moodle_url('/badges/index.php', [
'delete' => ':id',
'type' => ':type',
'id' => ':courseid',
]),
new pix_icon('t/delete', '', 'core'),
[],
false,
new lang_string('delete', 'core')
))->add_callback(static function(stdclass $row): bool {
$context = self::get_badge_context((int)$row->type, (int)$row->courseid);
return has_capability('moodle/badges:deletebadge', $context);
}));
}
/**
* Return badge context based on type and courseid
*
* @param int $type
* @param int $courseid
* @return \core\context
* @throws \coding_exception
*/
private static function get_badge_context(int $type, int $courseid): \core\context {
switch ($type) {
case BADGE_TYPE_SITE:
return system::instance();
case BADGE_TYPE_COURSE:
return course::instance($courseid);
default:
throw new \coding_exception('Wrong context');
}
}
/**
* CSS classes to add to the row
*
* @param stdClass $row
* @return string
*/
public function get_row_class(stdClass $row): string {
return ($row->status == BADGE_STATUS_INACTIVE_LOCKED || $row->status == BADGE_STATUS_INACTIVE) ? 'text-muted' : '';
}
}

View File

@ -24,32 +24,20 @@
* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
*/
use core_badges\reportbuilder\local\systemreports\badges;
use core_reportbuilder\system_report_factory;
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/badgeslib.php');
$type = required_param('type', PARAM_INT);
$courseid = optional_param('id', 0, PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$deactivate = optional_param('lock', 0, PARAM_INT);
$sortby = optional_param('sort', 'name', PARAM_ALPHA);
$sorthow = optional_param('dir', 'ASC', PARAM_ALPHA);
$confirm = optional_param('confirm', false, PARAM_BOOL);
$delete = optional_param('delete', 0, PARAM_INT);
$archive = optional_param('archive', 0, PARAM_INT);
$msg = optional_param('msg', '', PARAM_TEXT);
if (!in_array($sortby, array('name', 'status'))) {
$sortby = 'name';
}
if ($sorthow != 'ASC' and $sorthow != 'DESC') {
$sorthow = 'ASC';
}
if ($page < 0) {
$page = 0;
}
require_login();
if (empty($CFG->enablebadges)) {
@ -61,13 +49,10 @@ if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) {
}
$err = '';
$urlparams = array('sort' => $sortby, 'dir' => $sorthow, 'page' => $page);
$urlparams = ['type' => $type];
if ($course = $DB->get_record('course', array('id' => $courseid))) {
$urlparams['type'] = $type;
if ($course = $DB->get_record('course', ['id' => $courseid])) {
$urlparams['id'] = $course->id;
} else {
$urlparams['type'] = $type;
}
$hdr = get_string('managebadges', 'badges');
@ -166,7 +151,6 @@ if ($type == BADGE_TYPE_SITE) {
echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection');
$totalcount = count(badges_get_badges($type, $courseid, '', '' , 0, 0));
$records = badges_get_badges($type, $courseid, $sortby, $sorthow, $page, BADGE_PERPAGE);
if ($totalcount) {
if ($course && $course->startdate > time()) {
@ -181,14 +165,8 @@ if ($totalcount) {
echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
}
$badges = new \core_badges\output\badge_management($records);
$badges->sort = $sortby;
$badges->dir = $sorthow;
$badges->page = $page;
$badges->perpage = BADGE_PERPAGE;
$badges->totalcount = $totalcount;
echo $output->render($badges);
$report = system_report_factory::create(badges::class, $PAGE->context);
echo $report->output();
} else {
echo $output->notification(get_string('nobadges', 'badges'), 'info');
}

View File

@ -265,8 +265,16 @@ class core_badges_renderer extends plugin_renderer_base {
return html_writer::div($display, null, array('id' => 'badge-overview'));
}
// Prints action icons for the badge.
/**
* Prints action icons for the badge.
*
* @deprecated sinde Moodle 4.3
* @param \core_badges\badge $badge
* @param \context $context
* @return string
*/
public function print_badge_table_actions($badge, $context) {
debugging("print_badge_table_actions() is deprecated.", DEBUG_DEVELOPER);
$actions = "";
if (has_capability('moodle/badges:configuredetails', $context) && $badge->has_criteria()) {
@ -481,10 +489,12 @@ class core_badges_renderer extends plugin_renderer_base {
/**
* Render a table of badges.
*
* @deprecated since Moodle 4.3
* @param \core_badges\output\badge_management $badges
* @return string
*/
protected function render_badge_management(\core_badges\output\badge_management $badges) {
debugging("render_badge_management() is deprecated.", DEBUG_DEVELOPER);
$paging = new paging_bar($badges->totalcount, $badges->page, $badges->perpage, $this->page->url, 'page');
// New badge button.

View File

@ -85,7 +85,7 @@ Feature: Test tertiary navigation as various users
When I am on the "C1" "Course" page logged in as "admin"
And I navigate to "Badges" in current page administration
And I click on "Manage badges" "button"
And I click on "Enable access" "link" in the "Testing course badge" "table_row"
And I press "Enable access" action in the "Testing course badge" report row
And I press "Continue"
And I log out
# Now student should see the Badges link.

View File

@ -25,7 +25,7 @@ Feature: Award badges based on cohort
| image | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I set the field "id_cohort_cohorts" to "One Cohort"
@ -62,7 +62,7 @@ Feature: Award badges based on cohort
| image | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I expand all fieldsets
@ -104,7 +104,7 @@ Feature: Award badges based on cohort
| image | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I set the field "id_cohort_cohorts" to "One Cohort"
@ -142,7 +142,7 @@ Feature: Award badges based on cohort
| image | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I set the field "id_cohort_cohorts" to "One Cohort"
@ -195,7 +195,7 @@ Feature: Award badges based on cohort
| image | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I set the field "id_cohort_cohorts" to "One Cohort"
@ -254,7 +254,7 @@ Feature: Award badges based on cohort
| image | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I set the field "id_cohort_cohorts" to "One Cohort"
@ -313,7 +313,7 @@ Feature: Award badges based on cohort
| image | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I expand all fieldsets
@ -372,7 +372,7 @@ Feature: Award badges based on cohort
| Site Badge 2 | 0 | Site badge description | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge 1" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I set the field "id_cohort_cohorts" to "One Cohort"
@ -381,7 +381,7 @@ Feature: Award badges based on cohort
When I press "Continue"
And I should see "Recipients (1)"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge 2" "table_row"
And I press "Edit" action in the "Site Badge 2" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I set the field "id_cohort_cohorts" to "Two Cohort"
@ -429,7 +429,7 @@ Feature: Award badges based on cohort
| Site Badge 2 | 0 | Site badge description | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge 1" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I expand all fieldsets
@ -440,7 +440,7 @@ Feature: Award badges based on cohort
When I press "Continue"
And I should see "Recipients (1)"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge 2" "table_row"
And I press "Edit" action in the "Site Badge 2" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Cohort membership"
And I expand all fieldsets

View File

@ -94,7 +94,7 @@ Feature: Award badges based on competency completion
And I click on "Add" "button" in the "Competency picker" "dialogue"
# Add a badge to the site
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
# Set the competency as a criteria for the badge
And I set the field "type" to "Competencies"
@ -147,7 +147,7 @@ Feature: Award badges based on competency completion
And I click on "Add" "button" in the "Competency picker" "dialogue"
# Add a badge to the site
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
# Set the competency as a criteria for the badge
And I set the field "type" to "Competencies"

View File

@ -16,7 +16,7 @@ Feature: Award badges based on user profile field
| image | badges/tests/behat/badge.png |
And I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I click on "Edit" "link" in the "Site Badge" "table_row"
And I press "Edit" action in the "Site Badge" report row
And I select "Criteria" from the "jump" singleselect
And I set the field "type" to "Profile completion"
And I set the field "id_field_picture" to "1"

View File

@ -0,0 +1,91 @@
@core @core_badges @javascript
Feature: Manage badges
In order to manage badges in the system
As an admin
I need to be able to edit, copy, enable/disable access, delete and award badges
Background:
Given the following "core_badges > Badge" exists:
| name | Badge #1 |
| status | 0 |
| version | 1 |
| language | en |
| description | Test badge description |
| image | badges/tests/behat/badge.png |
| imageauthorurl | http://author.example.com |
| imagecaption | Test caption image |
Scenario: Copy a badge
Given I log in as "admin"
And I navigate to "Badges > Manage badges" in site administration
And I press "Copy" action in the "Badge #1" report row
And I should see "Copy of Badge #1"
And I press "Save changes"
And I click on "Back" "button"
Then the following should exist in the "reportbuilder-table" table:
| Name | Badge status |
| Badge #1 | Not available |
| Copy of Badge #1 | Not available |
Scenario: Edit a badge
Given 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 set the field "Name" to "New Badge #1"
And I press "Save changes"
And I click on "Back" "button"
Then the following should exist in the "reportbuilder-table" table:
| Name | Badge status |
| New Badge #1 | Not available |
Scenario: Delete a badge
Given I log in as "admin"
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"
Scenario: Enable and disable access to a badge
Given 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
And I set the field "type" to "Manual issue by role"
And I set the field "Manager" to "1"
And I press "Save"
And I navigate to "Badges > Manage badges" in site administration
And I open the action menu in "Badge #1" "table_row"
And I choose "Enable access" in the open action menu
And I should see "Changes in badge access"
And I press "Continue"
And I should see "Access to the badges was successfully enabled"
Then the following should exist in the "reportbuilder-table" table:
| Name | Badge status |
| Badge #1 | Available |
And I open the action menu in "Badge #1" "table_row"
And I choose "Disable access" in the open action menu
And I should see "Access to the badges was successfully disabled"
And the following should exist in the "reportbuilder-table" table:
| Name | Badge status |
| Badge #1 | Not available |
Scenario: Award a badge
Given 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
And I set the field "type" to "Manual issue by role"
And I set the field "Manager" to "1"
And I press "Save"
And I navigate to "Badges > Manage badges" in site administration
And I open the action menu in "Badge #1" "table_row"
And I choose "Enable access" in the open action menu
And I press "Continue"
And I open the action menu in "Badge #1" "table_row"
And I choose "Award badge" in the open action menu
And I set the field "potentialrecipients[]" to "Admin User (moodle@example.com)"
And I press "Award badge"
And I navigate to "Badges > Manage badges" in site administration
And the following should exist in the "reportbuilder-table" table:
| Name | Badge status | Recipients |
| Badge #1 | Available | 1 |

View File

@ -38,7 +38,7 @@ Feature: Manage badges is not shown when there are no existing badges.
# Badge is not enabled so is not listed.
And I should not see "Testing course badge"
And I click on "Manage badges" "button"
And I click on "Edit" "link" in the "Testing course badge" "table_row"
And I press "Edit" action in the "Testing course badge" report row
And I click on "Add criteria" "button"
And I set the field "type" to "Manual issue by role"
And I expand all fieldsets
@ -51,7 +51,7 @@ Feature: Manage badges is not shown when there are no existing badges.
# Badge is not enabled yet so is not listed.
And I should not see "Testing course badge"
And I click on "Manage badges" "button"
And I click on "Enable access" "link" in the "Testing course badge" "table_row"
And I press "Enable access" action in the "Testing course badge" report row
And I click on "Continue" "button"
And I should see "Testing course badge"
And I click on "Back" "button"
@ -91,7 +91,7 @@ Feature: Manage badges is not shown when there are no existing badges.
And I am on the "C1" "Course" page logged in as "admin"
And I navigate to "Badges" in current page administration
And I click on "Manage badges" "button"
And I click on "Enable access" "link" in the "Testing course badge" "table_row"
And I press "Enable access" action in the "Testing course badge" report row
And I press "Continue"
And I log out
# Now student should see the Badges link.

View File

@ -124,6 +124,7 @@ class badges_test extends core_reportbuilder_testcase {
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:name', 'sortenabled' => 1]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname', 'sortenabled' => 1]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:namewithlink']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:criteria']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:image']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:language']);
@ -141,11 +142,15 @@ class badges_test extends core_reportbuilder_testcase {
$content = $this->get_custom_report_content($report->get('id'));
$this->assertCount(3, $content);
$expectedbadgeonelink = \html_writer::link(new \moodle_url('/badges/overview.php',
['id' => $badgeone->id]), ($badgeone->name));
// First badge, issued to user one.
[$badgename, $fullname, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires, $visible, $coursename]
= array_values($content[0]);
[$badgename, $fullname, $namewithlink, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires,
$visible, $coursename] = array_values($content[0]);
$this->assertEquals($badgeone->name, $badgename);
$this->assertEquals(fullname($user1), $fullname);
$this->assertEquals($expectedbadgeonelink, $namewithlink);
$this->assertStringContainsString('Awarded by: Manager', $criteria);
$this->assertStringContainsString('Image caption', $image);
$this->assertEquals('German', $language);
@ -158,10 +163,11 @@ class badges_test extends core_reportbuilder_testcase {
$this->assertEquals('PHPUnit test site', $coursename);
// First badge, issued to user two.
[$badgename, $fullname, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires, $visible, $coursename]
= array_values($content[1]);
[$badgename, $fullname, $namewithlink, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires,
$visible, $coursename] = array_values($content[1]);
$this->assertEquals($badgeone->name, $badgename);
$this->assertEquals(fullname($user2), $fullname);
$this->assertEquals($expectedbadgeonelink, $namewithlink);
$this->assertStringContainsString('Awarded by: Manager', $criteria);
$this->assertStringContainsString('Image caption', $image);
$this->assertEquals('German', $language);
@ -173,11 +179,15 @@ class badges_test extends core_reportbuilder_testcase {
$this->assertEquals('Yes', $visible);
$this->assertEquals('PHPUnit test site', $coursename);
$expectedbadgetwolink = \html_writer::link(new \moodle_url('/badges/overview.php',
['id' => $badgetwo->id]), ($badgetwo->name));
// Course badge, not issues to any users.
[$badgename, $fullname, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires, $visible, $coursename]
= array_values($content[2]);
[$badgename, $fullname, $namewithlink, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires,
$visible, $coursename] = array_values($content[2]);
$this->assertEquals($badgetwo->name, $badgename);
$this->assertEmpty($fullname);
$this->assertEquals($expectedbadgetwolink, $namewithlink);
$this->assertEquals('Criteria for this badge have not been set up yet.', $criteria);
$this->assertStringContainsString('Image caption', $image);
$this->assertEquals('English', $language);

View File

@ -122,6 +122,7 @@ class users_test extends core_reportbuilder_testcase {
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname', 'sortenabled' => 1]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:name', 'sortenabled' => 1]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:namewithlink']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:criteria']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:image']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:language']);
@ -155,11 +156,15 @@ class users_test extends core_reportbuilder_testcase {
$this->assertEmpty($visible);
$this->assertEmpty($coursename);
$expectedbadgesitelink = \html_writer::link(new \moodle_url('/badges/overview.php',
['id' => $badgesite->id]), ($badgesite->name));
// User issued site badge.
[$fullname, $badgename, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires, $visible, $coursename]
= array_values($content[1]);
[$fullname, $badgename, $namewithlink, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires,
$visible, $coursename] = array_values($content[1]);
$this->assertEquals(fullname($user), $fullname);
$this->assertEquals($badgesite->name, $badgename);
$this->assertEquals($expectedbadgesitelink, $namewithlink);
$this->assertStringContainsString('Awarded by: Manager', $criteria);
$this->assertStringContainsString('Image caption', $image);
$this->assertEquals('German', $language);
@ -171,11 +176,15 @@ class users_test extends core_reportbuilder_testcase {
$this->assertEquals('Yes', $visible);
$this->assertEquals('PHPUnit test site', $coursename);
// User issued site badge.
[$fullname, $badgename, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires, $visible, $coursename]
= array_values($content[2]);
$expectedbadgecourselink = \html_writer::link(new \moodle_url('/badges/overview.php',
['id' => $badgecourse->id]), ($badgecourse->name));
// User issued course badge.
[$fullname, $badgename, $namewithlink, $criteria, $image, $language, $version, $status, $expiry, $tag, $expires,
$visible, $coursename] = array_values($content[2]);
$this->assertEquals(fullname($user), $fullname);
$this->assertEquals($badgecourse->name, $badgename);
$this->assertEquals($expectedbadgecourselink, $namewithlink);
$this->assertEquals('Criteria for this badge have not been set up yet.', $criteria);
$this->assertStringContainsString('Image caption', $image);
$this->assertEquals('English', $language);

View File

@ -7,6 +7,8 @@ information provided here is intended especially for developers.
- `badges_check_backpack_accessibility`
- `badges_setup_backpack_js`
- `badges_local_backpack_js`
* Functions render_badge_management and print_badge_table_actions have been deprecated when converting the
section "Manage badges" to a Report Builder system report.
=== 4.0 ===
* Function print_badge_tabs has been deprecated in favour of manage_badge_action_bar instead

View File

@ -193,6 +193,7 @@ $string['connected'] = 'Connected';
$string['connecting'] = 'Connecting...';
$string['contact'] = 'Contact';
$string['contact_help'] = 'An email address associated with the badge issuer.';
$string['copy'] = 'Copy';
$string['copyof'] = 'Copy of {$a}';
$string['course'] = 'Course: {$a}';
$string['coursebadgesdisabled'] = 'Course badges are not enabled on this site.';
@ -416,6 +417,7 @@ $string['month'] = 'Month(s)';
$string['moredetails'] = 'More details';
$string['mybadges'] = 'My badges';
$string['mybackpack'] = 'My backpack settings';
$string['namewithlink'] = 'Name with link';
$string['never'] = 'Never';
$string['newbackpack'] = 'Add a new backpack';
$string['newbadge'] = 'Add a new badge';