Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding option for selecting search type of choice field: AND/OR #1537

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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 ▢,▣
Expand Down
4 changes: 4 additions & 0 deletions lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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 ▢,▣
Expand Down
4 changes: 4 additions & 0 deletions lang/es_es.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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 ▢, ▣
Expand Down
4 changes: 4 additions & 0 deletions lang/sv_se.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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 ▢, ▣
Expand Down
14 changes: 7 additions & 7 deletions lib/manager/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> $value Single value (string or int) or array of values (ints only)
* @return $this
*/
public function whereListContains(string $column, $value): self
Expand Down Expand Up @@ -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<int> $value Single value (string or int) or array of values (ints only)
* @return $this
*/
public function havingListContains(string $column, $value): self
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<int> $value Single value (string or int) or array of values (ints only)
*/
private function buildListContains(string $type, string $column, $value): string
{
Expand Down
21 changes: 20 additions & 1 deletion lib/yform/value/choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
Expand Down Expand Up @@ -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) {
Expand All @@ -270,15 +282,22 @@ 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);
}
break;
}
}

if ('OR' === $searchType && count($searchOr)) {
// build string
$query->whereRaw('(' . implode(' ' . $searchType . ' ', $searchOr) . ')');
}

return $query;
}

Expand Down
Loading