[Koha-patches] [PATCH] [SIGNED-OFF] Bug 5595: (MT #5757)adding additional attributes support on patrons's search
Nicole C. Engard
nengard at bywatersolutions.com
Tue Mar 8 04:34:19 CET 2011
From: Stéphane Delaune <stephane.delaune at biblibre.com>
Restores ability to search on extended borrower attributes that are configured to be searchable
Signed-off-by: Ian Walls <ian.walls at bywatersolutions.com>
Signed-off-by: Nicole C. Engard <nengard at bywatersolutions.com>
---
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 a292054..2b733ed 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.7.2.3
More information about the Koha-patches
mailing list