From 939eb7748681014cc7bb28be97b653b456a0b6c5 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 7 Mar 2018 04:51:08 +0000 Subject: [PATCH] Bug 20346 - Server side patron filtering implemented Server side (in the svc/members/search file) perl logic for filtering results returned from patron searches checks all patron data fields for a match with the filter value. This filtering works in the following steps: when filtering is initiated the original search using the original search query is run again and then the filter value is used to filter the resulting data, thereby using both the search and filter values to easily find a patron. The submitted filter value is automatically checked against every patron value in every patron record returned from the search and so there is no need for a specific data value to be selected with the select dropdown box id=searchfieldstype_filter and so that select dropdown has been removed due to this redundancy. This filter works for both filtering based on finding a match containing the filter value and, filtering based on finding a match starting with the filter value. Test plan: 1. Go to /members/members-home.pl and create 4 users. Make them all have the same first and last name but vary the homebranch, email addresses and dates of birth 2. Perform a search by writing in the first and last name combination shared by the 4 users and you should get 4 results 3. Filter by writing in the email adrr Sponsored-By: Catalyst IT --- C4/Utils/DataTables/Members.pm | 80 ++++++++--------- .../prog/en/modules/members/member.tt | 66 +++------------ svc/members/search | 99 ++++++++++++++++------ 3 files changed, 121 insertions(+), 124 deletions(-) diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index 8912146..395d661 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -9,12 +9,14 @@ use C4::Members::Attributes qw(SearchIdMatchingAttribute ); sub search { my ( $params ) = @_; my $searchmember = $params->{searchmember}; + my $firstquery = $params->{firstquery}; my $firstletter = $params->{firstletter}; my $categorycode = $params->{categorycode}; my $branchcode = $params->{branchcode}; my $searchtype = $params->{searchtype} || 'contain'; my $searchfieldstype = $params->{searchfieldstype} || 'standard'; my $dt_params = $params->{dt_params}; + my $searchfiltering = $params->{search_filter}; unless ( $searchmember ) { $searchmember = $dt_params->{sSearch} // ''; @@ -55,46 +57,44 @@ sub search { }; } } - - my $select = "SELECT - borrowers.borrowernumber, borrowers.surname, borrowers.firstname, - borrowers.streetnumber, borrowers.streettype, borrowers.address, - borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode, - borrowers.country, cardnumber, borrowers.dateexpiry, - borrowers.borrowernotes, borrowers.branchcode, borrowers.email, - borrowers.userid, borrowers.dateofbirth, borrowers.categorycode, - categories.description AS category_description, categories.category_type, - branches.branchname"; - my $from = "FROM borrowers - LEFT JOIN branches ON borrowers.branchcode = branches.branchcode - LEFT JOIN categories ON borrowers.categorycode = categories.categorycode"; - my @where_args; - my @where_strs; - if(defined $firstletter and $firstletter ne '') { - push @where_strs, "borrowers.surname LIKE ?"; - push @where_args, "$firstletter%"; - } - if(defined $categorycode and $categorycode ne '') { - push @where_strs, "borrowers.categorycode = ?"; - push @where_args, $categorycode; - } - if(@restricted_branchcodes ) { - push @where_strs, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")"; - push @where_args, @restricted_branchcodes; - } - - my $searchfields = { - standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid', - surname => 'surname', - email => 'email,emailpro,B_email', - borrowernumber => 'borrowernumber', - userid => 'userid', - phone => 'phone,phonepro,B_phone,altcontactphone,mobile', - address => 'streettype,address,address2,city,state,zipcode,country', - dateofbirth => 'dateofbirth', - sort1 => 'sort1', - sort2 => 'sort2', - }; + my $select = "SELECT + borrowers.borrowernumber, borrowers.surname, borrowers.firstname, + borrowers.streetnumber, borrowers.streettype, borrowers.address, + borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode, + borrowers.country, cardnumber, borrowers.dateexpiry, + borrowers.borrowernotes, borrowers.branchcode, borrowers.email, + borrowers.userid, borrowers.dateofbirth, borrowers.categorycode, + categories.description AS category_description, categories.category_type, + branches.branchname"; + my $from = "FROM borrowers + LEFT JOIN branches ON borrowers.branchcode = branches.branchcode + LEFT JOIN categories ON borrowers.categorycode = categories.categorycode"; + my @where_args; + my @where_strs; + if(defined $firstletter and $firstletter ne '') { + push @where_strs, "borrowers.surname LIKE ?"; + push @where_args, "$firstletter%"; + } + if(defined $categorycode and $categorycode ne '') { + push @where_strs, "borrowers.categorycode = ?"; + push @where_args, $categorycode; + } + if(@restricted_branchcodes ) { + push @where_strs, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")"; + push @where_args, @restricted_branchcodes; + } + my $searchfields = { + standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid', + surname => 'surname', + email => 'email,emailpro,B_email', + borrowernumber => 'borrowernumber', + userid => 'userid', + phone => 'phone,phonepro,B_phone,altcontactphone,mobile', + address => 'streettype,address,address2,city,state,zipcode,country', + dateofbirth => 'dateofbirth', + sort1 => 'sort1', + sort2 => 'sort2', + }; # * is replaced with % for sql $searchmember =~ s/\*/%/g; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt index b40bb03..dbc5e8b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt @@ -111,67 +111,13 @@

Filters

+

Filter results by entering any value and all data values in the patron record(s) will be checked

  1. - - -
  2. -