From ce78811455526094dda78a9c634c91fc1c2b6ea4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Delaune?= Date: Mon, 7 Mar 2011 22:34:19 -0500 Subject: [PATCH] Bug 5595: (MT #5757)adding additional attributes support on patrons's search Restores ability to search on extended borrower attributes that are configured to be searchable Signed-off-by: Ian Walls Signed-off-by: Nicole C. Engard Signed-off-by: Chris Cormack (cherry picked from commit 0ee0cc18b314d0123d8436a798bb02c5c1448494) Signed-off-by: Chris Nighswonger --- C4/Members.pm | 40 ++++++++++++++++++++++++---------------- C4/Members/Attributes.pm | 10 +++++----- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 00716cd0f7..dcbb0b07d0 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -277,22 +277,30 @@ C<&searchtype> is a string telling the type of search you want todo : start_with =cut sub Search { - my ($filter,$orderby, $limit, $columns_out, $search_on_fields,$searchtype) = @_; - my @filters; - if (ref($filter) eq "ARRAY"){ - push @filters,@$filter; - } - else { - push @filters,$filter; - } - if (C4::Context->preference('ExtendedPatronAttributes')) { - my $matching_records = C4::Members::Attributes::SearchIdMatchingAttribute($filter); - push @filters,@$matching_records; - } - $searchtype||="start_with"; - my $data=SearchInTable("borrowers",\@filters,$orderby,$limit,$columns_out,$search_on_fields,$searchtype); - - return ( $data ); + my ( $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ) = @_; + my @filters; + my %filtersmatching_record; + my @finalfilter; + if ( ref($filter) eq "ARRAY" ) { + push @filters, @$filter; + } else { + push @filters, $filter; + } + if ( C4::Context->preference('ExtendedPatronAttributes') ) { + my $matching_records = C4::Members::Attributes::SearchIdMatchingAttribute($filter); + if(scalar(@$matching_records)>0) { + foreach my $matching_record (@$matching_records) { + $filtersmatching_record{$$matching_record[0]}=1; + } + foreach my $k (keys(%filtersmatching_record)) { + push @filters, {"borrowernumber"=>$k}; + } + } + } + $searchtype ||= "start_with"; + push @finalfilter, \@filters; + my $data = SearchInTable( "borrowers", \@finalfilter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ); + return ($data); } =head2 GetMemberDetails diff --git a/C4/Members/Attributes.pm b/C4/Members/Attributes.pm index 70c34b4185..b89b03a646 100644 --- a/C4/Members/Attributes.pm +++ b/C4/Members/Attributes.pm @@ -102,17 +102,17 @@ sub GetBorrowerAttributes { sub SearchIdMatchingAttribute{ my $filter = shift; - - my $dbh = C4::Context->dbh(); + my $finalfilter=$$filter[0]; + my $dbh = C4::Context->dbh(); my $query = qq{ SELECT borrowernumber FROM borrower_attributes JOIN borrower_attribute_types USING (code) WHERE staff_searchable = 1 -AND attribute like ?}; +AND attribute like "%$finalfilter%"}; my $sth = $dbh->prepare_cached($query); - $sth->execute($filter); - return $sth->fetchall_arrayref; + $sth->execute(); + return $sth->fetchall_arrayref; } =head2 CheckUniqueness -- 2.39.5