Koha/svc/members/search
Jonathan Druart 0965dfcc15 Bug 12833: Patron search should search on extended attributes
Before Bug 9811, the patron search searched on extended attributes.

This patch restore this behavior.

Test plan:
0/ Create a patron attribute PA
1/ Create a patron A (cardnumber CNA) with PA="foo"
2/ Create a patron B (cardnumber CNB) with PA="foo bar"
3/ Search for CNA should redirect on the patron detail page.
4/ Search for "foo" should display the search result with 2 results.

Signed-off-by: Nick Clemens <nick@quecheelibrary.org>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
'Searchable' patron attributes can now be searched for again.
Works as described, passes stests and QA script.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2014-09-09 10:08:59 -03:00

134 lines
4.3 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2013 BibLibre
#
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use CGI;
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_with_http_headers );
use C4::Utils::DataTables qw( dt_get_params );
use C4::Utils::DataTables::Members qw( search );
use Koha::DateUtils qw( output_pref dt_from_string );
my $input = new CGI;
exit unless $input->param('template_path');
my ($template, $user, $cookie) = get_template_and_user({
template_name => $input->param('template_path'),
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { borrowers => 1 }
});
my $searchmember = $input->param('searchmember');
my $firstletter = $input->param('firstletter');
my $categorycode = $input->param('categorycode');
my $branchcode = $input->param('branchcode');
my $searchtype = $input->param('searchtype');
my $searchfieldstype = $input->param('searchfieldstype');
if ( $searchfieldstype eq "dateofbirth" ) {
$searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1});
}
# variable information for DataTables (id)
my $sEcho = $input->param('sEcho');
my %dt_params = dt_get_params($input);
foreach (grep {$_ =~ /^mDataProp/} keys %dt_params) {
$dt_params{$_} =~ s/^dt_//;
}
my $results;
if ( $searchfieldstype and $searchfieldstype eq 'standard' ) {
my $member = C4::Members::GetMember( cardnumber => $searchmember );
$results = {
iTotalRecords => 1,
iTotalDisplayRecords => 1,
patrons => [ $member ],
} if $member;
}
# Perform the patrons search
$results = C4::Utils::DataTables::Members::search(
{
searchmember => $searchmember,
firstletter => $firstletter,
categorycode => $categorycode,
branchcode => $branchcode,
searchtype => $searchtype,
searchfieldstype => $searchfieldstype,
dt_params => \%dt_params,
}
) unless $results;
$template->param(
sEcho => $sEcho,
iTotalRecords => $results->{iTotalRecords},
iTotalDisplayRecords => $results->{iTotalDisplayRecords},
aaData => $results->{patrons}
);
output_with_http_headers $input, $cookie, $template->output, 'json';
__END__
=head1 NAME
search - a search script for finding patrons
=head1 SYNOPSIS
This script provides a service for template for patron search using DataTables
=head2 Performing a search
Call this script from a DataTables table my $searchmember = $input->param('searchmember');
All following params are optional:
searchmember => the search terms
firstletter => search patrons with surname begins with this pattern (currently only used for 1 letter)
categorycode and branchcode => search patrons belong to a given categorycode or a branchcode
searchtype: can be 'contain' or 'start_with'
searchfieldstype: Can be 'standard', 'email', 'borrowernumber', 'phone' or 'address'
=cut
=back
=head1 LICENSE
Copyright 2013 BibLibre
This file is part of Koha.
Koha is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
Koha is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with Koha; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.