mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-79346 cohort: add "visible" filter/condition to report source.
Add to report as part of default setup.
This commit is contained in:
parent
23b86254d3
commit
934a851705
@ -19,6 +19,7 @@ declare(strict_types=1);
|
||||
namespace core_cohort\reportbuilder\datasource;
|
||||
|
||||
use core_cohort\reportbuilder\local\entities\{cohort, cohort_member};
|
||||
use core_reportbuilder\local\filters\boolean_select;
|
||||
use core_reportbuilder\datasource;
|
||||
use core_reportbuilder\local\entities\user;
|
||||
|
||||
@ -103,7 +104,20 @@ class cohorts extends datasource {
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_default_conditions(): array {
|
||||
return [];
|
||||
return [
|
||||
'cohort:visible',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the condition values that will be set for the report upon creation
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_default_condition_values(): array {
|
||||
return [
|
||||
'cohort:visible_operator' => boolean_select::CHECKED,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,6 +23,7 @@ use context_helper;
|
||||
use lang_string;
|
||||
use stdClass;
|
||||
use core_reportbuilder\local\entities\base;
|
||||
use core_reportbuilder\local\filters\boolean_select;
|
||||
use core_reportbuilder\local\filters\date;
|
||||
use core_reportbuilder\local\filters\select;
|
||||
use core_reportbuilder\local\filters\text;
|
||||
@ -327,6 +328,16 @@ class cohort extends base {
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
// Visible filter.
|
||||
$filters[] = (new filter(
|
||||
boolean_select::class,
|
||||
'visible',
|
||||
new lang_string('visible', 'core_cohort'),
|
||||
$this->get_entity_name(),
|
||||
"{$tablealias}.visible"
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ use context_system;
|
||||
use core_customfield_generator;
|
||||
use core_reportbuilder_generator;
|
||||
use core_reportbuilder_testcase;
|
||||
use core_reportbuilder\local\filters\{date, select, text};
|
||||
use core_reportbuilder\local\filters\{boolean_select, date, select, text};
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -63,6 +63,13 @@ class cohorts_test extends core_reportbuilder_testcase {
|
||||
'description' => 'This is my category cohort',
|
||||
]);
|
||||
|
||||
// Non-visible cohort (excluded by default).
|
||||
$cohortnonvisible = $this->getDataGenerator()->create_cohort([
|
||||
'contextid' => $contextsystem->id,
|
||||
'name' => 'Non-visible',
|
||||
'visible' => false,
|
||||
]);
|
||||
|
||||
/** @var core_reportbuilder_generator $generator */
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
||||
$report = $generator->create_report(['name' => 'Cohorts', 'source' => cohorts::class, 'default' => 1]);
|
||||
@ -177,6 +184,12 @@ class cohorts_test extends core_reportbuilder_testcase {
|
||||
'Filter description (no match)' => ['cohort:description', [
|
||||
'cohort:description_operator' => text::IS_EMPTY,
|
||||
], false],
|
||||
'Filter visible' => ['cohort:visible', [
|
||||
'cohort:visible_operator' => boolean_select::CHECKED,
|
||||
], true],
|
||||
'Filter visible (no match)' => ['cohort:visible', [
|
||||
'cohort:visible_operator' => boolean_select::NOT_CHECKED,
|
||||
], false],
|
||||
|
||||
// Cohort member.
|
||||
'Filter time added' => ['cohort_member:timeadded', [
|
||||
|
Loading…
x
Reference in New Issue
Block a user