From f1b781fa2c4a3c5ae88145371f6dc0cb215d5261 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 14 Sep 2022 04:02:10 +0000 Subject: [PATCH] Bug 23817: Normalize phone number when storing and when searching in Patrons module This patch normalizes the phone number when stored via Koha::Patron, and normalizes the phone number when searching "Primary phone" in the Patrons module. Test plan: 0. Apply patch and koha-plack --restart kohadev 1. Go to http://localhost:8081/cgi-bin/koha/members/memberentry.pl?op=modify&destination=circ&borrowernumber=51 2. Input '1-(234)-567-8901' into the 'Primary phone' field 3. Note on the next screen the phone number is shown as 12345678901 4. Go to http://localhost:8081/cgi-bin/koha/members/members-home.pl 5. Choose "Search field" of "Primary phone" 6. Search for '1-(234)-567-8901' 7. Note you are taken to http://localhost:8081/cgi-bin/koha/members/moremember.pl?borrowernumber=51 8. Try out different permutations like '234 567 8901' or '5678901' 9. Note that every permutation works to find the borrower --- Koha/Patron.pm | 22 +++++++++++++++++++ .../prog/en/includes/patron-search.inc | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 8031257304..efc926b42b 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2196,6 +2196,28 @@ sub virtualshelves { return Koha::Virtualshelves->_new_from_dbic( scalar $self->_result->virtualshelves ); } +=head3 phone + + my $phone = $patron->phone; + +=cut + +sub phone { + my ($self,@data) = @_; + if (@data){ + foreach my $datum (@data){ + $datum =~ s/[^\+0-9]//g; + } + $self->_result()->set_column( 'phone', @data ); + return $self; + } + else { + my $value = $self->_result()->get_column( 'phone' ); + return $value; + } +} + + =head2 Internal methods =head3 _type 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 3d1de0eb15..576198ad04 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -318,7 +318,10 @@ if ( !search_fields ) { search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]"; } - + if (search_fields == 'phone'){ + //Normalize phone numbers + patterns = [pattern.replace(/[^\+0-9]/g,'')]; + } let subquery_and = []; patterns.forEach(function(pattern,i){ let sub_or = []; -- 2.30.2