Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace qbank_viewquestiontext;
18
 
19
use core\output\datafilter;
20
use core_question\local\bank\condition;
21
 
22
/**
23
 * Filter for question text and question feedback text.
24
 *
25
 * @package    qbank_viewquestiontext
26
 * @copyright  2025 onwards Catalyst IT {@link http://www.catalyst-eu.net/}
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @author     Conn Warwicker <conn.warwicker@catalyst-eu.net>
29
 */
30
class questiontext_condition extends condition {
31
 
32
    #[\Override]
33
    public function get_title(): string {
34
        return get_string('questiontext_condition', 'qbank_viewquestiontext');
35
    }
36
 
37
    #[\Override]
38
    public static function get_condition_key(): string {
39
        return 'questiontext';
40
    }
41
 
42
    #[\Override]
43
    public function get_filter_class() {
44
        return 'core/datafilter/filtertypes/keyword';
45
    }
46
 
47
    #[\Override]
48
    public static function build_query_from_filter(array $filter): array {
49
 
50
        global $DB;
51
 
52
        // Are we inverting the search to look for where NOT like?
53
        $notlike = ($filter['jointype'] === datafilter::JOINTYPE_NONE);
54
 
55
        [$params, $conditions] = [[], []];
56
 
57
        // Loop through the values we've sent from the filter.
58
        foreach ($filter['values'] as $key => $value) {
59
 
60
            $params['questiontext_' . $key] = '%' . $value . '%';
61
            $params['questiontext_f_' . $key] = '%' . $value . '%';
62
 
63
            $condition = $DB->sql_like(
64
                'q.questiontext', ':questiontext_' . $key, false, true, $notlike
65
            );
66
            $condition .= ($notlike) ? ' AND ' : ' OR ';
67
            $condition .= $DB->sql_like(
68
                'q.generalfeedback', ':questiontext_f_' . $key, false, true, $notlike
69
            );
70
            $conditions[] = '(' . $condition . ')';
71
 
72
        }
73
 
74
        $delimiter = ($filter['jointype'] === datafilter::JOINTYPE_ANY) ? ' OR ' : ' AND ';
75
        return [
76
            implode($delimiter, $conditions),
77
            $params,
78
        ];
79
 
80
    }
81
}