mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 05:28:30 +01:00
Merge branch 'MDL-81073' of https://github.com/paulholden/moodle
This commit is contained in:
commit
0d7af68082
@ -26,7 +26,8 @@ use lang_string;
|
||||
use moodle_url;
|
||||
use stdClass;
|
||||
use core_reportbuilder\local\entities\base;
|
||||
use core_reportbuilder\local\filters\{select, text};
|
||||
use core_reportbuilder\local\filters\{date, select, text};
|
||||
use core_reportbuilder\local\helpers\database;
|
||||
use core_reportbuilder\local\report\{column, filter};
|
||||
|
||||
defined('MOODLE_INTERNAL') or die;
|
||||
@ -295,6 +296,16 @@ class badge extends base {
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
// Version.
|
||||
$filters[] = (new filter(
|
||||
text::class,
|
||||
'version',
|
||||
new lang_string('version', 'core_badges'),
|
||||
$this->get_entity_name(),
|
||||
"{$badgealias}.version"
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
// Status.
|
||||
$filters[] = (new filter(
|
||||
select::class,
|
||||
@ -312,6 +323,30 @@ class badge extends base {
|
||||
BADGE_STATUS_ARCHIVED => new lang_string('badgestatus_4', 'core_badges'),
|
||||
]);
|
||||
|
||||
// Expiry date/period.
|
||||
[$parammaxint, $paramtime] = database::generate_param_names(2);
|
||||
$filters[] = (new filter(
|
||||
date::class,
|
||||
'expiry',
|
||||
new lang_string('expirydate', 'core_badges'),
|
||||
$this->get_entity_name(),
|
||||
"CASE
|
||||
WHEN {$badgealias}.expiredate IS NULL AND {$badgealias}.expireperiod IS NULL THEN :{$parammaxint}
|
||||
ELSE COALESCE({$badgealias}.expiredate, {$badgealias}.expireperiod + :{$paramtime})
|
||||
END",
|
||||
[$parammaxint => 2147483647, $paramtime => time()]
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_limited_operators([
|
||||
date::DATE_ANY,
|
||||
date::DATE_RANGE,
|
||||
date::DATE_LAST,
|
||||
date::DATE_CURRENT,
|
||||
date::DATE_NEXT,
|
||||
date::DATE_PAST,
|
||||
date::DATE_FUTURE,
|
||||
]);
|
||||
|
||||
// Type.
|
||||
$filters[] = (new filter(
|
||||
select::class,
|
||||
|
@ -108,6 +108,7 @@ class badges extends system_report {
|
||||
$columns = [
|
||||
'badge:image',
|
||||
'badge:namewithlink',
|
||||
'badge:version',
|
||||
'badge:status',
|
||||
'badge:criteria',
|
||||
];
|
||||
@ -148,7 +149,9 @@ class badges extends system_report {
|
||||
protected function add_filters(): void {
|
||||
$filters = [
|
||||
'badge:name',
|
||||
'badge:version',
|
||||
'badge:status',
|
||||
'badge:expiry',
|
||||
];
|
||||
$this->add_filters_from_entities($filters);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ Feature: Manage badges
|
||||
Given the following "core_badges > Badge" exists:
|
||||
| name | Badge #1 |
|
||||
| status | 0 |
|
||||
| version | 1 |
|
||||
| version | 1.0 |
|
||||
| language | en |
|
||||
| description | Test badge description |
|
||||
| image | badges/tests/behat/badge.png |
|
||||
@ -23,20 +23,22 @@ Feature: Manage badges
|
||||
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 |
|
||||
| Name | Version | Badge status |
|
||||
| Badge #1 | 1.0 | Not available |
|
||||
| Copy of Badge #1 | 1.0 | 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 set the following fields to these values:
|
||||
| Name | New Badge #1 |
|
||||
| Version | 1.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 |
|
||||
| Name | Version | Badge status |
|
||||
| New Badge #1 | 1.1 | Not available |
|
||||
|
||||
Scenario: Delete a badge
|
||||
Given I log in as "admin"
|
||||
@ -45,6 +47,26 @@ Feature: Manage badges
|
||||
And I press "Delete and remove existing issued badges"
|
||||
Then I should see "There are currently no badges available for users to earn"
|
||||
|
||||
Scenario Outline: Filter managed badges
|
||||
Given the following "core_badges > Badges" exist:
|
||||
| name | status | version |
|
||||
| Badge #2 | 1 | 2.0 |
|
||||
And I log in as "admin"
|
||||
When I navigate to "Badges > Manage badges" in site administration
|
||||
And I click on "Filters" "button"
|
||||
And I set the following fields in the "<filter>" "core_reportbuilder > Filter" to these values:
|
||||
| <filter> operator | Is equal to |
|
||||
| <filter> value | <value> |
|
||||
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
|
||||
Then I should see "Filters applied"
|
||||
And I should see "Badge #1" in the "Badges" "table"
|
||||
And I should not see "Badge #2" in the "Badges" "table"
|
||||
Examples:
|
||||
| filter | value |
|
||||
| Name | Badge #1 |
|
||||
| Version | 1.0 |
|
||||
| Badge status | Not available |
|
||||
|
||||
Scenario: Enable and disable access to a badge
|
||||
Given I log in as "admin"
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
|
@ -216,6 +216,14 @@ class badges_test extends core_reportbuilder_testcase {
|
||||
'badge:name_operator' => text::IS_EQUAL_TO,
|
||||
'badge:name_value' => 'Other badge',
|
||||
], false],
|
||||
'Filter badge version' => ['badge:version', [
|
||||
'badge:version_operator' => text::IS_EQUAL_TO,
|
||||
'badge:version_value' => '2.0',
|
||||
], true],
|
||||
'Filter badge version (no match)' => ['badge:version', [
|
||||
'badge:version_operator' => text::IS_EQUAL_TO,
|
||||
'badge:version_value' => '1.0',
|
||||
], false],
|
||||
'Filter badge status' => ['badge:status', [
|
||||
'badge:status_operator' => select::EQUAL_TO,
|
||||
'badge:status_value' => BADGE_STATUS_ACTIVE_LOCKED,
|
||||
@ -224,6 +232,14 @@ class badges_test extends core_reportbuilder_testcase {
|
||||
'badge:status_operator' => select::EQUAL_TO,
|
||||
'badge:status_value' => BADGE_STATUS_ACTIVE,
|
||||
], false],
|
||||
'Filter badge expiry' => ['badge:expiry', [
|
||||
'badge:expiry_operator' => date::DATE_RANGE,
|
||||
'badge:expiry_from' => 1622502000,
|
||||
], true],
|
||||
'Filter badge expiry (no match)' => ['badge:expiry', [
|
||||
'badge:expiry_operator' => date::DATE_RANGE,
|
||||
'badge:expiry_to' => 1622502000,
|
||||
], false],
|
||||
'Filter badge type' => ['badge:type', [
|
||||
'badge:type_operator' => select::EQUAL_TO,
|
||||
'badge:type_value' => BADGE_TYPE_COURSE,
|
||||
@ -307,6 +323,7 @@ class badges_test extends core_reportbuilder_testcase {
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_badges');
|
||||
$badge = $generator->create_badge([
|
||||
'name' => 'Course badge',
|
||||
'version' => '2.0',
|
||||
'type' => BADGE_TYPE_COURSE,
|
||||
'courseid' => $course->id,
|
||||
'expireperiod' => HOURSECS,
|
||||
|
Loading…
x
Reference in New Issue
Block a user