From be54872a2cf07699dcd5a7dbd02ce1320226b4b9 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 15 Feb 2022 11:21:11 +0000 Subject: [PATCH] MDL-73887 reportbuilder: make the select filter easier to extend. Allow custom filters to extend the filter, and override/set the operators/values fields internally. --- reportbuilder/classes/local/filters/select.php | 12 ++++++++---- reportbuilder/classes/local/report/filter.php | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/reportbuilder/classes/local/filters/select.php b/reportbuilder/classes/local/filters/select.php index aaaa4ddccf3..5aea41dcf3a 100644 --- a/reportbuilder/classes/local/filters/select.php +++ b/reportbuilder/classes/local/filters/select.php @@ -24,6 +24,11 @@ use core_reportbuilder\local\helpers\database; /** * Select report filter * + * The options for the select are defined when creating the filter by calling {@see set_options} or {@see set_options_callback} + * + * To extend this class in your own filter (e.g. to pre-populate available options), you should override the {@see get_operators} + * and/or {@see get_select_options} methods + * * @package core_reportbuilder * @copyright 2021 David Matamoros * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -44,7 +49,7 @@ class select extends base { * * @return array */ - private function get_operators(): array { + protected function get_operators(): array { $operators = [ self::ANY_VALUE => get_string('filterisanyvalue', 'core_reportbuilder'), self::EQUAL_TO => get_string('filterisequalto', 'core_reportbuilder'), @@ -55,12 +60,11 @@ class select extends base { } /** - * Return the options for the filter as an array, to be used to populate the select input field. These options should be - * specified when creating the filter via the {@see set_options} or {@see set_options_callback} method + * Return the options for the filter as an array, to be used to populate the select input field * * @return array */ - private function get_select_options(): array { + protected function get_select_options(): array { return (array) $this->filter->get_options(); } diff --git a/reportbuilder/classes/local/report/filter.php b/reportbuilder/classes/local/report/filter.php index b6d884354b3..d45466b70d3 100644 --- a/reportbuilder/classes/local/report/filter.php +++ b/reportbuilder/classes/local/report/filter.php @@ -262,7 +262,7 @@ final class filter { } /** - * Set the options for the filter to be returned by a callback (that recieves no arguments) in the format that the filter + * Set the options for the filter to be returned by a callback (that receives no arguments) in the format that the filter * class expects * * @param callable $callback