mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'MDL-77119' of https://github.com/paulholden/moodle
This commit is contained in:
commit
7695b4b18c
@ -25,10 +25,15 @@ use lang_string;
|
||||
use moodle_url;
|
||||
use stdClass;
|
||||
use core_reportbuilder\local\entities\base;
|
||||
use core_reportbuilder\local\filters\{date, text};
|
||||
use core_reportbuilder\local\filters\{boolean_select, date, select, text};
|
||||
use core_reportbuilder\local\helpers\format;
|
||||
use core_reportbuilder\local\report\{column, filter};
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/grouplib.php");
|
||||
|
||||
/**
|
||||
* Group entity
|
||||
*
|
||||
@ -170,6 +175,45 @@ class group extends base {
|
||||
->add_fields("{$groupsalias}.enrolmentkey")
|
||||
->set_is_sortable(true);
|
||||
|
||||
// Visibility column.
|
||||
$columns[] = (new column(
|
||||
'visibility',
|
||||
new lang_string('visibility', 'core_group'),
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_INTEGER)
|
||||
->add_fields("{$groupsalias}.visibility")
|
||||
->set_is_sortable(true)
|
||||
// It doesn't make sense to offer integer aggregation methods for this column.
|
||||
->set_disabled_aggregation(['avg', 'max', 'min', 'sum'])
|
||||
->set_callback(static function(?int $visibility): string {
|
||||
if ($visibility === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$options = [
|
||||
GROUPS_VISIBILITY_ALL => new lang_string('visibilityall', 'core_group'),
|
||||
GROUPS_VISIBILITY_MEMBERS => new lang_string('visibilitymembers', 'core_group'),
|
||||
GROUPS_VISIBILITY_OWN => new lang_string('visibilityown', 'core_group'),
|
||||
GROUPS_VISIBILITY_NONE => new lang_string('visibilitynone', 'core_group'),
|
||||
];
|
||||
|
||||
return (string) ($options[$visibility] ?? $visibility);
|
||||
});
|
||||
|
||||
// Participation column.
|
||||
$columns[] = (new column(
|
||||
'participation',
|
||||
new lang_string('participation', 'core_group'),
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_BOOLEAN)
|
||||
->add_fields("{$groupsalias}.participation")
|
||||
->set_is_sortable(true)
|
||||
->set_callback([format::class, 'boolean_as_text']);
|
||||
|
||||
// Picture column.
|
||||
$columns[] = (new column(
|
||||
'picture',
|
||||
@ -248,6 +292,32 @@ class group extends base {
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
// Visibility filter.
|
||||
$filters[] = (new filter(
|
||||
select::class,
|
||||
'visibility',
|
||||
new lang_string('visibility', 'core_group'),
|
||||
$this->get_entity_name(),
|
||||
"{$groupsalias}.visibility"
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_options([
|
||||
GROUPS_VISIBILITY_ALL => new lang_string('visibilityall', 'core_group'),
|
||||
GROUPS_VISIBILITY_MEMBERS => new lang_string('visibilitymembers', 'core_group'),
|
||||
GROUPS_VISIBILITY_OWN => new lang_string('visibilityown', 'core_group'),
|
||||
GROUPS_VISIBILITY_NONE => new lang_string('visibilitynone', 'core_group'),
|
||||
]);
|
||||
|
||||
// Participation filter.
|
||||
$filters[] = (new filter(
|
||||
boolean_select::class,
|
||||
'participation',
|
||||
new lang_string('participation', 'core_group'),
|
||||
$this->get_entity_name(),
|
||||
"{$groupsalias}.participation"
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
// Time created filter.
|
||||
$filters[] = (new filter(
|
||||
date::class,
|
||||
|
@ -20,7 +20,7 @@ namespace core_group\reportbuilder\datasource;
|
||||
|
||||
use core_reportbuilder_generator;
|
||||
use core_reportbuilder_testcase;
|
||||
use core_reportbuilder\local\filters\{date, text};
|
||||
use core_reportbuilder\local\filters\{boolean_select, date, select, text};
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -133,6 +133,8 @@ class groups_test extends core_reportbuilder_testcase {
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'group:idnumber']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'group:description']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'group:enrolmentkey']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'group:visibility']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'group:participation']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'group:picture']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'group:timecreated']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'group:timemodified']);
|
||||
@ -159,6 +161,8 @@ class groups_test extends core_reportbuilder_testcase {
|
||||
$groupidnumber,
|
||||
$groupdescription,
|
||||
$groupenrolmentkey,
|
||||
$groupvisibility,
|
||||
$groupparticipation,
|
||||
$grouppicture,
|
||||
$grouptimecreated,
|
||||
$grouptimemodified,
|
||||
@ -176,6 +180,8 @@ class groups_test extends core_reportbuilder_testcase {
|
||||
$this->assertEquals('G101', $groupidnumber);
|
||||
$this->assertEquals(format_text($group->description), $groupdescription);
|
||||
$this->assertEquals('S', $groupenrolmentkey);
|
||||
$this->assertEquals('Visible to all', $groupvisibility);
|
||||
$this->assertEquals('Yes', $groupparticipation);
|
||||
$this->assertEmpty($grouppicture);
|
||||
$this->assertNotEmpty($grouptimecreated);
|
||||
$this->assertNotEmpty($grouptimemodified);
|
||||
@ -223,6 +229,20 @@ class groups_test extends core_reportbuilder_testcase {
|
||||
'group:idnumber_operator' => text::IS_NOT_EQUAL_TO,
|
||||
'group:idnumber_value' => 'G101',
|
||||
], false],
|
||||
'Filter group visibility' => ['group:visibility', [
|
||||
'group:visibility_operator' => select::EQUAL_TO,
|
||||
'group:visibility_value' => 0, // Visible to all.
|
||||
], true],
|
||||
'Filter group visibility (no match)' => ['group:visibility', [
|
||||
'group:visibility_operator' => select::EQUAL_TO,
|
||||
'group:visibility_value' => 1, // Visible to members only.
|
||||
], false],
|
||||
'Filter group participation' => ['group:participation', [
|
||||
'group:participation_operator' => boolean_select::CHECKED,
|
||||
], true],
|
||||
'Filter group participation (no match)' => ['group:participation', [
|
||||
'group:participation_operator' => boolean_select::NOT_CHECKED,
|
||||
], false],
|
||||
'Filter group time created' => ['group:timecreated', [
|
||||
'group:timecreated_operator' => date::DATE_RANGE,
|
||||
'group:timecreated_from' => 1622502000,
|
||||
|
Loading…
x
Reference in New Issue
Block a user