This commit is contained in:
Huong Nguyen
2025-02-24 10:09:15 +07:00
14 changed files with 67 additions and 30 deletions
@@ -409,7 +409,7 @@ class course extends base {
* @return array
*/
public static function get_options_for_theme(): array {
return array_map(
return ['' => get_string('forceno')] + array_map(
fn(theme_config $theme) => $theme->get_theme_name(),
get_list_of_themes(),
);
@@ -421,7 +421,7 @@ class course extends base {
* @return array
*/
public static function get_options_for_lang(): array {
return get_string_manager()->get_list_of_translations();
return ['' => get_string('forceno')] + get_string_manager()->get_list_of_translations();
}
/**
@@ -430,7 +430,7 @@ class course extends base {
* @return array
*/
public static function get_options_for_calendartype(): array {
return \core_calendar\type_factory::get_list_of_calendar_types();
return ['' => get_string('forceno')] + \core_calendar\type_factory::get_list_of_calendar_types();
}
/**
@@ -452,7 +452,7 @@ class course extends base {
// If the column has corresponding filter, determine the value from its options.
$options = $this->get_options_for($fieldname);
if ($options !== null && array_key_exists($value, $options)) {
if ($options !== null && $value !== null && array_key_exists($value, $options)) {
return $options[$value];
}
@@ -364,7 +364,7 @@ class user extends base {
// If the column has corresponding filter, determine the value from its options.
$options = $this->get_options_for($fieldname);
if ($options !== null && array_key_exists($value, $options)) {
if ($options !== null && $value !== null && array_key_exists($value, $options)) {
return $options[$value];
}
+19 -4
View File
@@ -44,6 +44,9 @@ class select extends base {
/** @var int Not equal to */
public const NOT_EQUAL_TO = 2;
/** @var int Value to indicate "Any value" for the simplified filter options */
private const OPTION_ANY_VALUE = -124567;
/**
* Returns an array of comparison operators
*
@@ -65,7 +68,13 @@ class select extends base {
* @return array
*/
protected function get_select_options(): array {
return (array) $this->filter->get_options();
static $options = [];
if (!array_key_exists($this->name, $options)) {
$options[$this->name] = (array) $this->filter->get_options();
}
return $options[$this->name];
}
/**
@@ -91,7 +100,7 @@ class select extends base {
$element,
"{$this->name}_value",
get_string('filterfieldvalue', 'core_reportbuilder', $this->get_header()),
['' => $operators[self::ANY_VALUE]] + $options,
[self::OPTION_ANY_VALUE => $operators[self::ANY_VALUE]] + $options,
)->setHiddenLabel(true);
} else {
$elements = [];
@@ -129,13 +138,19 @@ class select extends base {
$name = database::generate_param_name();
$operator = (int) ($values["{$this->name}_operator"] ?? self::ANY_VALUE);
$value = $values["{$this->name}_value"] ?? '';
$value = (string) ($values["{$this->name}_value"] ?? self::OPTION_ANY_VALUE);
$fieldsql = $this->filter->get_field_sql();
$params = $this->filter->get_field_params();
// Get available options, if multidimensional then flatten the array.
$options = $this->get_select_options();
if (count($options) !== count($options, COUNT_RECURSIVE)) {
$options = array_merge(...array_values($options));
}
// Validate filter form values.
if ($value === '') {
if ($operator === self::ANY_VALUE || !array_key_exists($value, $options)) {
return ['', []];
}