Bug 5595: (MT #5757)adding additional attributes support on patrons's search
authorStéphane Delaune <stephane.delaune@biblibre.com>
Tue, 8 Mar 2011 03:34:19 +0000 (22:34 -0500)
committerChris Cormack <chrisc@catalyst.net.nz>
Fri, 11 Mar 2011 23:46:05 +0000 (12:46 +1300)
Restores ability to search on extended borrower attributes that are configured to be searchable

Signed-off-by: Ian Walls <ian.walls@bywatersolutions.com>
Signed-off-by: Nicole C. Engard <nengard@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Members.pm
C4/Members/Attributes.pm

index a292054..2b733ed 100644 (file)
@@ -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
index 70c34b4..b89b03a 100644 (file)
@@ -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