Skip to content

Commit c65d069

Browse files
committed
MDL-83859 core_question: Update filter condition API
This corrects some definitions of the methods in the base condition class to make things more obvious to developers implementing new filters. Previously if your filter wanted to use the default `core/datafilter/filtertype` class, you still had to implement `get_filter_class` to return `null`, since it was declared as abstract. This change defines it as returning `null` by default, so this is no longer necessary. Also, this removes the default definitions for `get_condition_key` and `build_query_from_functions`, and declares them abstract. Currently it is necessary to override these to implement a functional filter so it doesn't make sense to have a useless default definition. This will not cause any breakages with existing filters. All filters must already be defining the methods that are now abstract, otherwise they will not function. Any filter that is now overriding `get_filter_class` to return `null` will continue to work as before, even though this is no longer necessary.
1 parent a798b1d commit c65d069

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
issueNumber: MDL-83859
2+
notes:
3+
core_question:
4+
- message: >
5+
The definition of the abstract `core_question\local\bank\condition`
6+
class has changed to make it clearer which methods are required
7+
in child classes.
8+
9+
The `get_filter_class` method is no longer declared as abstract, and
10+
will return `null` by default to use the base
11+
`core/datafilter/filtertype` class. If you have defined this method
12+
to return `null` in your own class, it will continue to work, but
13+
it is no longer necessary.
14+
15+
`build_query_from_filter` and `get_condition_key` are now declared as
16+
abstract, since all filter condition classes must define these
17+
(as well as existing abstract methods) to function. Again, exsiting
18+
child classes will continue to work if they did before, as they
19+
already needed these methods.
20+
type: changed

question/classes/local/bank/condition.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2828
*/
2929
abstract class condition {
30-
3130
/** @var int The default filter type */
3231
const JOINTYPE_DEFAULT = datafilter::JOINTYPE_ANY;
3332

@@ -48,11 +47,16 @@ abstract class condition {
4847
abstract public function get_title();
4948

5049
/**
51-
* Return filter class associated with this condition
50+
* Return the Javascript filter class to provide the UI for this condition.
51+
*
52+
* If left as null, this will use the default core/datafilter/filtertype class. Otherwise, override it to return
53+
* the full path to the Javascript module path for the class.
5254
*
5355
* @return string filter class
5456
*/
55-
abstract public function get_filter_class();
57+
public function get_filter_class() {
58+
return null;
59+
}
5660

5761
/**
5862
* Extract the required filter from the provided question bank view.
@@ -140,9 +144,7 @@ public function get_condition_class() {
140144
*
141145
* @return string
142146
*/
143-
public static function get_condition_key() {
144-
return '';
145-
}
147+
abstract public static function get_condition_key();
146148

147149
/**
148150
* Return an SQL fragment to be ANDed into the WHERE clause to filter which questions are shown.
@@ -211,12 +213,13 @@ public static function get_filter_from_list(array $filters): ?array {
211213
}
212214

213215
/**
214-
* Build query from filter value
216+
* Return the SQL WHERE condition and parameters to be ANDed with other filter conditions.
217+
*
218+
* The $filter parameter recieves an array with a 'values' key, containing an array of the filter values selected,
219+
* and a 'jointype' key containing the selected join type.
215220
*
216221
* @param array $filter filter properties
217-
* @return array where sql and params
222+
* @return array ['SQL where condition', ['param1' => 'value1', 'param2' => 'value2', ...]]
218223
*/
219-
public static function build_query_from_filter(array $filter): array {
220-
return ['', []];
221-
}
224+
abstract public static function build_query_from_filter(array $filter);
222225
}

0 commit comments

Comments
 (0)