Skip to content

Commit

Permalink
Merge branch 'MDL-80329' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Dec 18, 2023
2 parents 9251242 + e56e9cd commit e6b01af
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions admin/classes/reportbuilder/local/filters/courserole.php
Expand Up @@ -53,7 +53,7 @@ public function setup_form(MoodleQuickForm $mform): void {

// 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);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public function get_sql_filter(array $values): array {
}

// Course.
$course = $values["{$this->name}_course"] ?? '';
$course = trim($values["{$this->name}_course"] ?? '');
if ($course !== '') {
$selects[] = "{$coursealias}.shortname = :{$courseparam}";
$params[$courseparam] = $course;
Expand Down
Expand Up @@ -47,6 +47,7 @@ public static function get_sql_filter_provider(): array {
'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']],
];
}

Expand Down
12 changes: 4 additions & 8 deletions reportbuilder/classes/local/filters/text.php
Expand Up @@ -94,7 +94,7 @@ public function setup_form(\MoodleQuickForm $mform): void {

$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);
Expand All @@ -103,19 +103,15 @@ public function setup_form(\MoodleQuickForm $mform): void {
/**
* 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();
Expand Down
6 changes: 6 additions & 0 deletions reportbuilder/tests/local/filters/text_test.php
Expand Up @@ -53,6 +53,12 @@ public function get_sql_filter_simple_provider(): array {
[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],
];
}

Expand Down

0 comments on commit e6b01af

Please sign in to comment.