diff --git a/lang/de_de.lang b/lang/de_de.lang index 373a49f9..ec619f62 100644 --- a/lang/de_de.lang +++ b/lang/de_de.lang @@ -248,6 +248,11 @@ yform_values_choice_placeholder = Platzhalter yform_values_choice_placeholder_notice = Diese Option legt fest, ob eine spezielle "leere" Option (z.B. "Wählen Sie eine Option") oben in einem Select-Widget erscheint. Diese Option gilt nur, wenn die Mehrfachoption auf false gesetzt ist. yform_values_choice_preferred_choices = Bevorzugte Auswahlmöglichkeiten (preferred_choices) yform_values_choice_preferred_choices_notice = Mit dieser Option werden bestimmte Auswahlmöglichkeiten an den Anfang der Liste verschoben, wobei ein optisches Trennzeichen zwischen ihnen und dem Rest der Optionen gesetzt wird. +yform_values_choice_search_type_label = Art der Suche +yform_values_choice_search_type_notice = betrifft Suchfilter in Tabellen im Backend +yform_values_choice_search_type_AND = UND-Suche (alle ausgewählten Suchwerte müssen vorkommen) +yform_values_choice_search_type_OR = ODER-Suche (mindestens einer der ausgewählten Suchwerte muss vorkommen) + yform_values_status_output_values = Ausgabewerte eingeben yform_values_status_output_values_notice = 2 Werte kommasepariert. z.B. offline,online oder ▢,▣ diff --git a/lang/en_gb.lang b/lang/en_gb.lang index edde3f5b..6e92e67d 100644 --- a/lang/en_gb.lang +++ b/lang/en_gb.lang @@ -234,6 +234,10 @@ yform_values_choice_placeholder = Placeholder yform_values_choice_placeholder_notice = Use this setting to display an extra "empty" option (ex. "Choose an option") as a first select option. This setting works only, if multiple is set to false. yform_values_choice_preferred_choices = Preferred choices yform_values_choice_preferred_choices_notice = Use this setting to move certain options to the beginning of the option list. A visual delimiter will be added to separate these choices from the rest. +yform_values_choice_search_type_label = Type of search +yform_values_choice_search_type_notice = relates to search filters in backend tables +yform_values_choice_search_type_AND = AND search (all selected search values must be present) +yform_values_choice_search_type_OR = OR search (at least one of the selected search values must be present) yform_values_status_output_values = Enter output values yform_values_status_output_values_notice = 2 comma separated values. Ex. offline, online OR ▢,▣ diff --git a/lang/es_es.lang b/lang/es_es.lang index 3719db1c..d17db8c1 100644 --- a/lang/es_es.lang +++ b/lang/es_es.lang @@ -231,6 +231,10 @@ yform_values_choice_placeholder = Marcador de posición yform_values_choice_placeholder_notice = Esta opción determina si una opción especial "en blanco" (por ejemplo, "elegir una opción") aparece en la parte superior de un widget Seleccionar. Esta opción se aplica solo si la opción múltiple está configurada en falso. yform_values_choice_preferred_choices = Opciones preferidas yform_values_choice_preferred_choices_notice = Esta opción mueve ciertas opciones a la parte superior de la lista, colocando un separador óptico entre ellas y el resto de las opciones. +yform_values_choice_search_type_label = Tipo de búsqueda +yform_values_choice_search_type_notice = se refiere a los filtros de búsqueda en las tablas del backend +yform_values_choice_search_type_AND = Búsqueda AND (todos los valores seleccionados deben estar presentes) +yform_values_choice_search_type_OR = Búsqueda OR (al menos uno de los valores seleccionados debe estar presente) yform_values_status_output_values = Ingrese valores de salida yform_values_status_output_values_notice = 2 valores separados por comas. p.ej. fuera de línea, en línea o ▢, ▣ diff --git a/lang/sv_se.lang b/lang/sv_se.lang index 3a594110..34641d13 100644 --- a/lang/sv_se.lang +++ b/lang/sv_se.lang @@ -235,6 +235,10 @@ yform_values_choice_placeholder = Platshållare yform_values_choice_placeholder_notice = Det här alternativet avgör om ett speciellt "tomt" alternativ (till exempel "Välj ett alternativ") visas överst på en Select-widget. Det här alternativet gäller endast om multipelalternativet är inställt på felaktigt. yform_values_choice_preferred_choices = Föredragna val (preferred_choices) yform_values_choice_preferred_choices_notice = Det här alternativet flyttar vissa val överst i listan, placera en optisk separator mellan dem och resten av alternativen. +yform_values_choice_search_type_label = Söktyp +yform_values_choice_search_type_notice = avser sökfilter i tabeller i backend +yform_values_choice_search_type_AND = OCH-sökning (alla valda sökvärden måste förekomma) +yform_values_choice_search_type_OR = ELLER-sökning (minst ett av de valda sökvärdena måste förekomma) yform_values_status_output_values = Ange utgångsvärden yform_values_status_output_values_notice = 2 värden separerade med komma-tecken. t.ex. offline, online eller ▢, ▣ diff --git a/lib/manager/query.php b/lib/manager/query.php index 466c895e..20a3f51c 100644 --- a/lib/manager/query.php +++ b/lib/manager/query.php @@ -350,7 +350,7 @@ public function whereNotBetween(string $column, $from, $to): self * Where the comma separated list column contains the given value or any of the given values. * * @param string $column Column with comma separated list - * @param string|int|int[] $value Single value (string or int) or array of values (ints only) + * @param string|int|array $value Single value (string or int) or array of values (ints only) * @return $this */ public function whereListContains(string $column, $value): self @@ -497,7 +497,7 @@ public function havingNotBetween(string $column, $from, $to): self * Where the comma separated list column contains the given value or any of the given values. * * @param string $column Column with comma separated list - * @param string|int|int[] $value Single value (string or int) or array of values (ints only) + * @param string|int|array $value Single value (string or int) or array of values (ints only) * @return $this */ public function havingListContains(string $column, $value): self @@ -694,18 +694,18 @@ public function findIds(array $ids): rex_yform_manager_collection } /** - * @return null|T + * @return T|null */ public function findOne(): ?rex_yform_manager_dataset { $this->limit(1); - /** @var null|T */ + /** @var T|null */ return rex_yform_manager_dataset::queryOne($this->getQuery(), $this->getParams(), $this->table); } /** - * @return null|T + * @return T|null */ public function findId(int $id): ?rex_yform_manager_dataset { @@ -837,7 +837,7 @@ private function normalizeValue($value) * @param self::PARAM_* $type * @param mixed $value */ - private function addParam(string $type, $value): string + public function addParam(string $type, $value): string { $this->paramCounter[$type] = ($this->paramCounter[$type] ?? 0) + 1; @@ -872,7 +872,7 @@ private function buildCondition(string $type, string $column, mixed $value, ?str /** * @param self::PARAM_* $type * @param string $column Column with comma separated list - * @param string|int|int[] $value Single value (string or int) or array of values (ints only) + * @param string|int|array $value Single value (string or int) or array of values (ints only) */ private function buildListContains(string $type, string $column, $value): string { diff --git a/lib/yform/value/choice.php b/lib/yform/value/choice.php index cb23bcd5..79987794 100644 --- a/lib/yform/value/choice.php +++ b/lib/yform/value/choice.php @@ -141,6 +141,16 @@ public function getDefinitions(): array 'group_attributes' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_group_attributes'), 'notice' => rex_i18n::msg('yform_values_choice_group_attributes_notice')], 'attributes' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_attributes'), 'notice' => rex_i18n::msg('yform_values_choice_attributes_notice')], 'choice_attributes' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_choice_attributes'), 'notice' => rex_i18n::msg('yform_values_choice_choice_attributes_notice')], + 'search_type' => [ + 'type' => 'choice', + 'label' => rex_i18n::msg('yform_values_choice_search_type_label'), + 'notice' => rex_i18n::msg('yform_values_choice_search_type_notice'), + 'choices' => [ + 'AND' => rex_i18n::msg('yform_values_choice_search_type_AND'), + 'OR' => rex_i18n::msg('yform_values_choice_search_type_OR'), + ], + 'default' => 'AND', + ], 'notice' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_notice')], 'no_db' => ['type' => 'no_db', 'label' => rex_i18n::msg('yform_values_defaults_table'), 'default' => 0], 'choice_label' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_choice_choice_label'), 'notice' => rex_i18n::msg('yform_values_choice_choice_label_notice')], @@ -260,6 +270,8 @@ public static function getSearchFilter($params) $self = new self(); $values = $self->getArrayFromString($value); $multiple = 1 == $params['field']->getElement('multiple'); + $searchType = $params['field']->getElement('search_type'); + $searchOr = []; foreach ($values as $value) { switch ($value) { @@ -270,8 +282,10 @@ public static function getSearchFilter($params) $query->where($field, '', '<>'); break; default: - if ($multiple) { + if ($multiple && 'OR' !== $searchType) { $query->whereListContains($field, $value); + } elseif ('OR' === $searchType) { + $searchOr[] = sprintf('FIND_IN_SET(%s, %s)', $query->addParam('where', $value), $query->quoteIdentifier($field)); } else { $query->where($field, $value); } @@ -279,6 +293,11 @@ public static function getSearchFilter($params) } } + if ('OR' === $searchType && count($searchOr)) { + // build string + $query->whereRaw('(' . implode(' ' . $searchType . ' ', $searchOr) . ')'); + } + return $query; }