From badbf47fb392b2da0eef30929314b173854d28f8 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Thu, 21 Nov 2024 16:53:27 +1100 Subject: [PATCH] issue #100: add filters for rules table --- .../local/entities/rule_entity.php | 57 +++++++++++++++++++ .../local/systemreports/rules.php | 5 ++ lang/en/tool_dynamic_cohorts.php | 1 + version.php | 4 +- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/classes/reportbuilder/local/entities/rule_entity.php b/classes/reportbuilder/local/entities/rule_entity.php index efaaa18..8812255 100644 --- a/classes/reportbuilder/local/entities/rule_entity.php +++ b/classes/reportbuilder/local/entities/rule_entity.php @@ -17,7 +17,10 @@ namespace tool_dynamic_cohorts\reportbuilder\local\entities; use core_reportbuilder\local\entities\base; +use core_reportbuilder\local\filters\boolean_select; +use core_reportbuilder\local\filters\text; use core_reportbuilder\local\report\column; +use core_reportbuilder\local\report\filter; use lang_string; use tool_dynamic_cohorts\rule; @@ -57,6 +60,10 @@ public function initialise(): base { $this->add_column($column); } + foreach ($this->get_all_filters() as $filter) { + $this->add_filter($filter); + } + return $this; } @@ -174,4 +181,54 @@ protected function get_all_columns(): array { return $columns; } + + /** + * Return list of all available filters + * + * @return filter[] + */ + protected function get_all_filters(): array { + $tablealias = $this->get_table_alias('tool_dynamic_cohorts'); + + // Name filter. + $filters[] = (new filter( + text::class, + 'name', + new lang_string('name', 'core_cohort'), + $this->get_entity_name(), + "{$tablealias}.name" + )) + ->add_joins($this->get_joins()); + + // Bulk processing filter. + $filters[] = (new filter( + boolean_select::class, + 'bulkprocessing', + new lang_string('rule_entity.bulkprocessing', 'tool_dynamic_cohorts'), + $this->get_entity_name(), + "{$tablealias}.bulkprocessing" + )) + ->add_joins($this->get_joins()); + + // Broken filter. + $filters[] = (new filter( + boolean_select::class, + 'broken', + new lang_string('broken', 'tool_dynamic_cohorts'), + $this->get_entity_name(), + "{$tablealias}.broken" + )) + ->add_joins($this->get_joins()); + + // Enabled filter. + $filters[] = (new filter( + boolean_select::class, + 'enabled', + new lang_string('enabled', 'tool_dynamic_cohorts'), + $this->get_entity_name(), + "{$tablealias}.enabled" + )) + ->add_joins($this->get_joins()); + return $filters; + } } diff --git a/classes/reportbuilder/local/systemreports/rules.php b/classes/reportbuilder/local/systemreports/rules.php index 572b5c2..295fa09 100644 --- a/classes/reportbuilder/local/systemreports/rules.php +++ b/classes/reportbuilder/local/systemreports/rules.php @@ -114,6 +114,11 @@ protected function initialise(): void { $cohortentity->get_column('name') ->set_title(new lang_string('cohort', 'tool_dynamic_cohorts')); + $this->add_filter_from_entity('rule_entity:name'); + $this->add_filter_from_entity('rule_entity:bulkprocessing'); + $this->add_filter_from_entity('rule_entity:broken'); + $this->add_filter_from_entity('rule_entity:enabled'); + $this->set_initial_sort_column('rule_entity:name', SORT_ASC); } diff --git a/lang/en/tool_dynamic_cohorts.php b/lang/en/tool_dynamic_cohorts.php index 18f8640..9ad2c1b 100644 --- a/lang/en/tool_dynamic_cohorts.php +++ b/lang/en/tool_dynamic_cohorts.php @@ -32,6 +32,7 @@ $string['any'] = 'Any'; $string['backtolistofrules'] = 'Back to the list of rules'; $string['before'] = 'Before'; +$string['broken'] = 'Broken'; $string['brokenruleswarning'] = 'There are some broken rules require your attention.
To fix a broken rule you should remove all broken conditions.
Sometimes a rule becomes broken when matching users SQL failed. In this case all condition are ok, but the rule is marked as broken. You should check Moodle logs for "Matching users failed" event and related SQL errors.
Please note, that in any case you have to re-save the rule to mark it as unbroken.'; $string['bulkprocessing'] = 'Bulk processing'; $string['bulkprocessing_help'] = 'If this option is enabled, users will be added and removed from cohort in bulk. This will significantly improve processing performance. However, using this option will suppress triggering events when users added or removed from cohort.'; diff --git a/version.php b/version.php index ee6c2ef..5e3aa8e 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'tool_dynamic_cohorts'; -$plugin->release = 2024110701; -$plugin->version = 2024110701; +$plugin->release = 2024112100; +$plugin->version = 2024112100; $plugin->requires = 2022112800; $plugin->supported = [404, 405]; $plugin->maturity = MATURITY_STABLE;