Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 25... Línea 25...
25
 * @copyright  2013 Ray Morris
25
 * @copyright  2013 Ray Morris
26
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
26
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
28
 */
29
abstract class condition {
29
abstract class condition {
30
 
-
 
31
    /** @var int The default filter type */
30
    /** @var int The default filter type */
32
    const JOINTYPE_DEFAULT = datafilter::JOINTYPE_ANY;
31
    const JOINTYPE_DEFAULT = datafilter::JOINTYPE_ANY;
Línea 33... Línea 32...
33
 
32
 
34
    /** @var ?array Filter properties for this condition. */
33
    /** @var ?array Filter properties for this condition. */
Línea 46... Línea 45...
46
     * @return string title of the condition
45
     * @return string title of the condition
47
     */
46
     */
48
    abstract public function get_title();
47
    abstract public function get_title();
Línea 49... Línea 48...
49
 
48
 
50
    /**
49
    /**
-
 
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
51
     * Return filter class associated with this condition
53
     * the full path to the Javascript module path for the class.
52
     *
54
     *
53
     * @return string filter class
55
     * @return ?string filter class
54
     */
56
     */
-
 
57
    public function get_filter_class() {
-
 
58
        return null;
Línea 55... Línea 59...
55
    abstract public function get_filter_class();
59
    }
56
 
60
 
57
    /**
61
    /**
58
     * Extract the required filter from the provided question bank view.
62
     * Extract the required filter from the provided question bank view and set the initial values.
-
 
63
     *
-
 
64
     * This will look for the filter matching {@see get_condition_key()} in the view's current filter parameter.
59
     *
65
     * If the filter is not being initialised to display the question bank UI (for example, to resolve a list of questions matching
-
 
66
     * a set of filters), then the `$qbank` argument may be null, and any usage of it to set the initial filter state is skipped.
60
     * This will look for the filter matching {@see get_condition_key()}
67
     *
61
     *
68
     * @param ?view $qbank The question bank view the filter is being rendered for. This may only be used for setting the
62
     * @param view|null $qbank
69
     *     initial state of the filter.
63
     */
70
     */
64
    public function __construct(view $qbank = null) {
71
    public function __construct(?view $qbank = null) {
65
        if (is_null($qbank)) {
72
        if (is_null($qbank)) {
66
            return;
73
            return;
67
        }
74
        }
Línea 138... Línea 145...
138
     * Use a unique string for the condition identifier, use string directly, dont need to use language pack.
145
     * Use a unique string for the condition identifier, use string directly, dont need to use language pack.
139
     * Using language pack might break the filter object for multilingual support.
146
     * Using language pack might break the filter object for multilingual support.
140
     *
147
     *
141
     * @return string
148
     * @return string
142
     */
149
     */
143
    public static function get_condition_key() {
150
    abstract public static function get_condition_key();
144
        return '';
-
 
145
    }
-
 
Línea 146... Línea 151...
146
 
151
 
147
    /**
152
    /**
148
     * Return an SQL fragment to be ANDed into the WHERE clause to filter which questions are shown.
153
     * Return an SQL fragment to be ANDed into the WHERE clause to filter which questions are shown.
149
     *
154
     *
Línea 199... Línea 204...
199
            datafilter::JOINTYPE_ALL,
204
            datafilter::JOINTYPE_ALL,
200
        ];
205
        ];
201
    }
206
    }
Línea 202... Línea 207...
202
 
207
 
-
 
208
    /**
-
 
209
     * Method to be overridden in condition classes to filter out anything invalid from the filterconditions array.
-
 
210
     *
-
 
211
     * This can be applied anywhere where the $filterconditions array exists, to let condition plugins remove elements
-
 
212
     *  from the array, based on their own internal logic/validation. For example, this is used on the
-
 
213
     *  /mod/quiz/editrandom.php page to filter out question categories which no longer exist, which previously
-
 
214
     *  broke the editrandom page.
-
 
215
     *
-
 
216
     * @param array $filterconditions
-
 
217
     * @return array
-
 
218
     */
-
 
219
    public function filter_invalid_values(array $filterconditions): array {
-
 
220
        return $filterconditions;
-
 
221
    }
-
 
222
 
203
    /**
223
    /**
204
     * Given an array of filters, pick the entry that matches the condition key and return it.
224
     * Given an array of filters, pick the entry that matches the condition key and return it.
205
     *
225
     *
206
     * @param array $filters Array of filters, keyed by condition.
226
     * @param array $filters Array of filters, keyed by condition.
207
     * @return ?array The filter that matches this condition
227
     * @return ?array The filter that matches this condition
208
     */
228
     */
209
    public static function get_filter_from_list(array $filters): ?array {
229
    public static function get_filter_from_list(array $filters): ?array {
210
        return $filters[static::get_condition_key()] ?? null;
230
        return $filters[static::get_condition_key()] ?? null;
Línea 211... Línea 231...
211
    }
231
    }
-
 
232
 
-
 
233
    /**
-
 
234
     * Return the SQL WHERE condition and parameters to be ANDed with other filter conditions.
212
 
235
     *
213
    /**
236
     * The $filter parameter recieves an array with a 'values' key, containing an array of the filter values selected,
214
     * Build query from filter value
237
     * and a 'jointype' key containing the selected join type.
215
     *
238
     *
216
     * @param array $filter filter properties
239
     * @param array $filter filter properties
217
     * @return array where sql and params
240
     * @return array ['SQL where condition', ['param1' => 'value1', 'param2' => 'value2', ...]]
218
     */
-
 
219
    public static function build_query_from_filter(array $filter): array {
-
 
220
        return ['', []];
241
     */