From ecbef120fc4b916e6931ef20609438ab9ccfed19 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Mon, 20 Jun 2011 11:15:01 +1200 Subject: [PATCH] [Signed Off] Bug 6513 - make the routing list search work properly, and faster too. Content-Type: text/plain; charset="utf-8" Signed-off-by: Liz Rea --- C4/Members.pm | 71 ++++++++++++- .../prog/en/modules/serials/member-search.tt | 7 +- serials/member-search.pl | 111 ++++++++----------- 3 files changed, 119 insertions(+), 70 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index ce694e5..045136f 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -124,6 +124,10 @@ BEGIN { &fixup_cardnumber &checkcardnumber ); + + push @EXPORT_OK, qw( + FindByPartialName + ); } =head1 NAME @@ -285,10 +289,14 @@ C<&search_on_fields> is an array ref to the fieldnames you want to limit search C<&searchtype> is a string telling the type of search you want todo : start_with, exact or contains are allowed +C is a boolean that tells us to avoid searching the +extended attributes even if we otherwise would. + =cut sub Search { - my ( $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ) = @_; + my ( $filter, $orderby, $limit, $columns_out, $search_on_fields, + $searchtype, $skipExtendedAttributes ) = @_; my @filters; my %filtersmatching_record; my @finalfilter; @@ -297,7 +305,8 @@ sub Search { } else { push @filters, $filter; } - if ( C4::Context->preference('ExtendedPatronAttributes') ) { + if (!$skipExtendedAttributes && + C4::Context->preference('ExtendedPatronAttributes') ) { my $matching_records = C4::Members::Attributes::SearchIdMatchingAttribute($filter); if(scalar(@$matching_records)>0) { foreach my $matching_record (@$matching_records) { @@ -314,6 +323,64 @@ sub Search { return ($data); } +=head2 FindByPartialName + + @result = FindByPartialName('string', categorycode => 'C', branchcode => 'L' ); + +This is a simplified version of the "Search" function above. It compares what +has been entered against the surname, firstname, othernames, and email as +a prefix, a literal match against the barcode, and allows filtering by the +user's library and category. + +=head3 RETURNS + +An array of hashrefs that contain the values from the borrowers table of things +that match. + +=head3 NOTES + +Supplying all fields as blank or C will return all users. Searches that +have no result will end up in an empty list. If you get undef, there was +an error of some sort. + +=cut + +sub FindByPartialName { + my ($prefix, %options) = @_; + + my $qry_start = 'SELECT * FROM borrowers'; + my ($qry_end, @params); + if ($prefix) { + $qry_end .= <dbh; + my $sth = $dbh->prepare($query); + eval { $sth->execute(@params) }; + if ($@) { + warn $@; + return undef; + } + my $result = $sth->fetchall_arrayref( {} ); + return @$result; +} + =head2 GetMemberDetails ($borrower) = &GetMemberDetails($borrowernumber, $cardnumber); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/member-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/member-search.tt index 91172be..67e3614 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/member-search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/member-search.tt @@ -24,10 +24,9 @@ function add_member(subscriptionid,borrowernumber){
- Filter : + Filter:
    -
  1. -
  2. +