mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-80329 reportbuilder: trim whitespace in text filter content.
This commit is contained in:
parent
bffb5524a6
commit
e56e9cd6de
@ -53,7 +53,7 @@ class courserole extends base {
|
||||
|
||||
// Course.
|
||||
$elements['course'] = $mform->createElement('text', "{$this->name}_course", get_string('shortnamecourse'));
|
||||
$mform->setType("{$this->name}_course", PARAM_RAW);
|
||||
$mform->setType("{$this->name}_course", PARAM_RAW_TRIMMED);
|
||||
|
||||
$mform->addElement('group', "{$this->name}_group", '', $elements, '', false);
|
||||
}
|
||||
@ -85,7 +85,7 @@ class courserole extends base {
|
||||
}
|
||||
|
||||
// Course.
|
||||
$course = $values["{$this->name}_course"] ?? '';
|
||||
$course = trim($values["{$this->name}_course"] ?? '');
|
||||
if ($course !== '') {
|
||||
$selects[] = "{$coursealias}.shortname = :{$courseparam}";
|
||||
$params[$courseparam] = $course;
|
||||
|
@ -47,6 +47,7 @@ class courserole_test extends advanced_testcase {
|
||||
'Filter by category' => ['', 'cat2', '', ['user1', 'user2', 'user3']],
|
||||
'Filter by category and course' => ['', 'cat2', 'course2', ['user1', 'user2']],
|
||||
'Filter by course' => ['', '', 'course3', ['user3']],
|
||||
'Filter by course (ensure whitespace is trimmed)' => ['', '', ' course3 ', ['user3']],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ class text extends base {
|
||||
|
||||
$mform->addElement('group', $this->name . '_group', '', $elements, '', false);
|
||||
|
||||
$mform->setType($this->name . '_value', PARAM_RAW);
|
||||
$mform->setType($this->name . '_value', PARAM_RAW_TRIMMED);
|
||||
$mform->hideIf($this->name . '_value', $this->name . '_operator', 'eq', self::ANY_VALUE);
|
||||
$mform->hideIf($this->name . '_value', $this->name . '_operator', 'eq', self::IS_EMPTY);
|
||||
$mform->hideIf($this->name . '_value', $this->name . '_operator', 'eq', self::IS_NOT_EMPTY);
|
||||
@ -103,19 +103,15 @@ class text extends base {
|
||||
/**
|
||||
* Return filter SQL
|
||||
*
|
||||
* @param array|null $values
|
||||
* @param array $values
|
||||
* @return array array of two elements - SQL query and named parameters
|
||||
*/
|
||||
public function get_sql_filter(?array $values) : array {
|
||||
public function get_sql_filter(array $values): array {
|
||||
global $DB;
|
||||
$name = database::generate_param_name();
|
||||
|
||||
if (!$values) {
|
||||
return ['', []];
|
||||
}
|
||||
|
||||
$operator = (int) ($values["{$this->name}_operator"] ?? self::ANY_VALUE);
|
||||
$value = $values["{$this->name}_value"] ?? '';
|
||||
$value = trim($values["{$this->name}_value"] ?? '');
|
||||
|
||||
$fieldsql = $this->filter->get_field_sql();
|
||||
$params = $this->filter->get_field_params();
|
||||
|
@ -53,6 +53,12 @@ class text_test extends advanced_testcase {
|
||||
[text::STARTS_WITH, 'sunlight', false],
|
||||
[text::ENDS_WITH, 'looking for?', true],
|
||||
[text::ENDS_WITH, 'your heart', false],
|
||||
|
||||
// Ensure whitespace is trimmed.
|
||||
[text::CONTAINS, ' looking for ', true],
|
||||
[text::IS_EQUAL_TO, ' Hello, is it me you\'re looking for? ', true],
|
||||
[text::STARTS_WITH, ' Hello, is it me ', true],
|
||||
[text::ENDS_WITH, ' you\'re looking for? ', true],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user