From: Stéphane Delaune <[email protected]>

Restores ability to search on extended borrower attributes that are configured 
to be searchable

Signed-off-by: Ian Walls <[email protected]>
---
 C4/Members.pm            |   38 +++++++++++++++++++++++---------------
 C4/Members/Attributes.pm |   10 +++++-----
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/C4/Members.pm b/C4/Members.pm
index fafc99b..3a4899c 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -278,22 +278,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 70c34b4..b89b03a 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
-- 
1.5.6.5

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to