From cf5247aa6617e456c95be497d1db6153637c982d Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Tue, 15 Mar 2022 12:18:13 +0000 Subject: [PATCH] Fix filtering of name/description (case in-sensitive) --- src/Sprunje/OrganisationSprunje.php | 64 ++++++++++++++++-------- templates/tables/organisations.html.twig | 4 +- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/Sprunje/OrganisationSprunje.php b/src/Sprunje/OrganisationSprunje.php index 7f44f9a..694a159 100644 --- a/src/Sprunje/OrganisationSprunje.php +++ b/src/Sprunje/OrganisationSprunje.php @@ -83,6 +83,48 @@ class OrganisationSprunje extends Sprunje return $this; } + /** + * Filter by name (case insensitive). + * + * @param Builder $query + * @param mixed $value + * + * @return self + */ + protected function filterName($query, $value) + { + // Split value on separator for OR queries + $values = explode($this->orSeparator, $value); + $query->where(function ($query) use ($values) { + foreach ($values as $value) { + $query->orWhereRaw('LOWER(name) LIKE ?', [ '%' . strtolower($value) . '%' ]); + } + }); + + return $this; + } + + /** + * Filter by description (case insensitive). + * + * @param Builder $query + * @param mixed $value + * + * @return self + */ + protected function filterDescription($query, $value) + { + // Split value on separator for OR queries + $values = explode($this->orSeparator, $value); + $query->where(function ($query) use ($values) { + foreach ($values as $value) { + $query->orWhereRaw('LOWER(description) LIKE ?', [ '%' . strtolower($value) . '%' ]); + } + }); + + return $this; + } + /** * Return a list of possible user statuses. * @@ -117,28 +159,6 @@ class OrganisationSprunje extends Sprunje return $this; } - /** - * Filter LIKE name OR description. (for user organisations modal) - * - * @param Builder $query - * @param mixed $value - * - * @return self - */ - protected function filterInfo($query, $value) - { - // Split value on separator for OR queries - $values = explode($this->orSeparator, $value); - $query->where(function ($query) use ($values) { - foreach ($values as $value) { - $query->orLike('name', $value) - ->orLike('description', $value); - } - }); - - return $this; - } - /** * Sort based on created date. * diff --git a/templates/tables/organisations.html.twig b/templates/tables/organisations.html.twig index b36a591..8886c2e 100644 --- a/templates/tables/organisations.html.twig +++ b/templates/tables/organisations.html.twig @@ -19,9 +19,9 @@ - + {% if 'description' not in table.hidden_columns %} - + {% endif %} {% if hasRole('site-admin') or hasRole('organisations-admin') or (current_user.adminForOrganisations.count > 0) -%}
{{translate('ORGANISATION')}} {{translate('ORGANISATION')}} {{translate("DESCRIPTION")}} {{translate("DESCRIPTION")}} {{translate("STATUS")}}