From 52e5d09ed0d5a7261ae5efb3283ff3e9d64d838b Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 2 Jun 2023 02:52:04 +0000 Subject: [PATCH] Bug 23817: Include all phone numbers --- Koha/REST/V1/Patrons.pm | 25 ++++++++++++------- .../prog/en/includes/patron-search.inc | 3 +-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm index 28e186ad7d..9fd60e02e6 100644 --- a/Koha/REST/V1/Patrons.pm +++ b/Koha/REST/V1/Patrons.pm @@ -472,23 +472,23 @@ sub guarantors_can_see_checkouts { sub _parse_dbic_query_for_dt { my ($q_params,$collector) = @_; + my %allowed_keys = ( + 'me.phone' => 1, + 'me.phonepro' => 1, + 'me.B_phone' => 1, + 'me.altcontactphone' => 1, + 'me.mobile' => 1, + ); if(ref($q_params) && ref($q_params) eq 'HASH') { foreach my $key (keys %{$q_params}) { - #FIXME: The table preference is always required so we might want to handle other scenarios... - if ($key eq 'me.phone'){ + if ($allowed_keys{$key}){ my $query = $q_params->{$key}; if ($query->{'like'}){ my $like = $query->{'like'}; #NOTE: Remove the hashref, and add a data structure to add to the WHERE clause via the attributes... delete $q_params->{$key}; - my $collection = \["regexp_replace(me.phone,?,?) LIKE ?","[^0-9]","",$like]; + my $collection = \["regexp_replace($key,?,?) LIKE ?","[^0-9]","",$like]; push(@$collector,$collection); - #NOTE: Rewrite the query to use a subquery where we can perform phone number normalization (but it's slow) - #$q_params->{$key} = { - # '-in' => \["SELECT phone FROM borrowers WHERE regexp_replace(phone,?,?) LIKE ?","[^0-9]","",$query->{'like'}], - #}; - #NOTE: Technically, you could replace the whole hashref, but that would nuke any OR query in the same hashref - #return \["regexp_replace(me.phone,?,?) LIKE ?","[^0-9]","",$query->{'like'}]; } } else { @@ -506,6 +506,13 @@ sub _parse_dbic_query_for_dt { } } +=head3 preprocess_dbic_for_datatables + +Method for preprocessing DBIC queries sent from DataTables, so a WHERE +clause can be injected into the query if one doesn't already exist. + +=cut + sub preprocess_dbic_for_datatables { my ($c,$q_params,$attributes) = @_; my @collector = (); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index 77558d1870..89dad14bda 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -308,10 +308,9 @@ if ( !search_fields ) { search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]"; } - if (search_fields == 'phone'){ + if (search_fields == 'phone,phonepro,B_phone,altcontactphone,mobile'){ patterns = [pattern.replace(/[^\+0-9]/g,'')]; } - let subquery_and = []; patterns.forEach(function(pattern,i){ let sub_or = []; -- 2.30.2