Bugzilla – Attachment 52998 Details for
Bug 14874
Add ability to search for patrons by date of birth from checkout and patron quick searches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14874 - Add ability to search for patrons by date of birth from checkout and patron quick searches
Bug-14874---Add-ability-to-search-for-patrons-by-d.patch (text/plain), 7.46 KB, created by
Nick Clemens (kidclamp)
on 2016-06-30 15:19:26 UTC
(
hide
)
Description:
Bug 14874 - Add ability to search for patrons by date of birth from checkout and patron quick searches
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2016-06-30 15:19:26 UTC
Size:
7.46 KB
patch
obsolete
>From 93e75b8b5a82b4c3b948bebd32db521904d9e052 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Sun, 15 May 2016 10:44:48 -0400 >Subject: [PATCH] Bug 14874 - Add ability to search for patrons by date of > birth from checkout and patron quick searches > >This patch alters C4::Utils::DataTables::Members::search to autodetect >if the searchmember parameter is a date and search by DOB if so > >To test: >1 - Apply patch >2 - Search for members by DOB formatted as per dateformat syspref or >mysql format >3 - Results should be returned as expected >4 - Search combined with other terms, results should be returned as >expected >5 - Search for patrons without using dates, results should be as >expected >6 - Search using search fields 'Date of birth' from expanded menu on >patron search - results should be returned as before (Note dying on > incorrect format is an existing bug) >7 - prove t/db_dependent/Utils/Datatables_Members.t > >Sponsored by Carnegie Stout Library (https://www.dubuque.lib.ia.us/) > >Signed-off-by: Eleftheria <koseoglo@lib.auth.gr> >--- > C4/Utils/DataTables/Members.pm | 14 +++++- > t/db_dependent/Utils/Datatables_Members.t | 77 ++++++++++++++++++++++++++++--- > 2 files changed, 84 insertions(+), 7 deletions(-) > >diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm >index 0b282ac..720cbf0 100644 >--- a/C4/Utils/DataTables/Members.pm >+++ b/C4/Utils/DataTables/Members.pm >@@ -88,13 +88,22 @@ sub search { > foreach my $term (@terms) { > next unless $term; > >+ my $termsearchfieldstype; >+ my $term_is_dt = eval { local $SIG{__WARN__}={}; Koha::DateUtils::output_pref( { str=>$term, dateonly=>1, dateformat=>'sql' } ); }; >+ >+ if ( $term_is_dt ){ >+ $termsearchfieldstype = 'dateofbirth' ; >+ $term = $term_is_dt; >+ } else { >+ $termsearchfieldstype = $searchfieldstype; > $term .= '%' # end with anything > if $term !~ /%$/; > $term = "%$term" # begin with anythin unless start_with > if $searchtype eq 'contain' && $term !~ /^%/; >+ } > > my @where_strs_or; >- for my $searchfield ( split /,/, $searchfields->{$searchfieldstype} ) { >+ for my $searchfield ( split /,/, $searchfields->{$termsearchfieldstype} ) { > push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?"; > push @where_args, $term; > } >@@ -136,6 +145,9 @@ sub search { > ($limit ? $limit : "") > ); > my $sth = $dbh->prepare($query); >+ warn Data::Dumper::Dumper( $query ); >+ warn Data::Dumper::Dumper( @where_args ); >+ > $sth->execute(@where_args); > my $patrons = $sth->fetchall_arrayref({}); > >diff --git a/t/db_dependent/Utils/Datatables_Members.t b/t/db_dependent/Utils/Datatables_Members.t >index be302e3..494a73f 100644 >--- a/t/db_dependent/Utils/Datatables_Members.t >+++ b/t/db_dependent/Utils/Datatables_Members.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 27; >+use Test::More tests => 47; > > use C4::Context; > use C4::Members; >@@ -60,7 +60,7 @@ my %john_doe = ( > surname => 'Doe', > categorycode => $categorycode, > branchcode => $branchcode, >- dateofbirth => '', >+ dateofbirth => '1983-03-01', > dateexpiry => '9999-12-31', > userid => 'john.doe' > ); >@@ -71,7 +71,7 @@ my %john_smith = ( > surname => 'Smith', > categorycode => $categorycode, > branchcode => $branchcode, >- dateofbirth => '', >+ dateofbirth => '1982-02-01', > dateexpiry => '9999-12-31', > userid => 'john.smith' > ); >@@ -82,7 +82,7 @@ my %jane_doe = ( > surname => 'Doe', > categorycode => $categorycode, > branchcode => $branchcode, >- dateofbirth => '', >+ dateofbirth => '1983-03-01', > dateexpiry => '9999-12-31', > userid => 'jane.doe' > ); >@@ -93,7 +93,7 @@ my %jeanpaul_dupont = ( > surname => 'Dupont', > categorycode => $categorycode, > branchcode => $branchcode, >- dateofbirth => '', >+ dateofbirth => '1982-02-01', > dateexpiry => '9999-12-31', > userid => 'jeanpaul.dupont' > ); >@@ -104,7 +104,7 @@ my %dupont_brown = ( > surname => 'Brown', > categorycode => $categorycode, > branchcode => $branchcode, >- dateofbirth => '', >+ dateofbirth => '1979-01-01', > dateexpiry => '9999-12-31', > userid => 'dupont.brown' > ); >@@ -362,6 +362,71 @@ $search_results = C4::Utils::DataTables::Members::search({ > is( $search_results->{ iTotalDisplayRecords }, 1, > "Jean Paul Dupont is found using contains and two terms search 'Jea Pau' (Bug 15252)"); > >+my @datetimeprefs = ("dmydot","iso","metric","us"); >+my %dates_in_pref = ( >+ dmydot => ["01.02.1982","01.03.1983","01.01.1979","01.01.1988"], >+ iso => ["1982-02-01","1983-03-01","1979-01-01","1988-01-01"], >+ metric => ["01/02/1982","01/03/1983","01/01/1979","01/01/1988"], >+ us => ["02/01/1982","03/01/1983","01/01/1979","01/01/1988"], >+ ); >+foreach my $dateformloo (@datetimeprefs){ >+ t::lib::Mocks::mock_preference('dateformat', $dateformloo); >+ $search_results = C4::Utils::DataTables::Members::search({ >+ searchmember => $dates_in_pref{$dateformloo}[0], >+ searchfieldstype => 'standard', >+ searchtype => 'contain', >+ branchcode => $branchcode, >+ dt_params => \%dt_params >+ }); >+ >+ is( $search_results->{ iTotalDisplayRecords }, 2, >+ "dateformat: $dateformloo Two borrowers have dob $dates_in_pref{$dateformloo}[0], standard search fields overriden"); >+ >+ $search_results = C4::Utils::DataTables::Members::search({ >+ searchmember => $dates_in_pref{$dateformloo}[2], >+ searchfieldstype => 'standard', >+ searchtype => 'contain', >+ branchcode => $branchcode, >+ dt_params => \%dt_params >+ }); >+ >+ is( $search_results->{ iTotalDisplayRecords }, 1, >+ "dateformat: $dateformloo One borrower has dob $dates_in_pref{$dateformloo}[2], standard search fields overriden"); >+ >+ $search_results = C4::Utils::DataTables::Members::search({ >+ searchmember => $dates_in_pref{$dateformloo}[1], >+ searchfieldstype => 'dateofbirth', >+ searchtype => 'contain', >+ branchcode => $branchcode, >+ dt_params => \%dt_params >+ }); >+ >+ is( $search_results->{ iTotalDisplayRecords }, 2, >+ "dateformat: $dateformloo Two borrowers have dob $dates_in_pref{$dateformloo}[1], dateofbirth search field works"); >+ >+ $search_results = C4::Utils::DataTables::Members::search({ >+ searchmember => $dates_in_pref{$dateformloo}[3], >+ searchfieldstype => 'dateofbirth', >+ searchtype => 'contain', >+ branchcode => $branchcode, >+ dt_params => \%dt_params >+ }); >+ >+ is( $search_results->{ iTotalDisplayRecords }, 0, >+ "dateformat: $dateformloo No borrowers have dob $dates_in_pref{$dateformloo}[3], dateofbirth search field works"); >+ >+ $search_results = C4::Utils::DataTables::Members::search({ >+ searchmember => $dates_in_pref{$dateformloo}[3], >+ searchfieldstype => 'standard', >+ searchtype => 'contain', >+ branchcode => $branchcode, >+ dt_params => \%dt_params >+ }); >+ >+ is( $search_results->{ iTotalDisplayRecords }, 0, >+ "dateformat: $dateformloo No borrowers have dob $dates_in_pref{$dateformloo}[3], standard search field overridden"); >+} >+ > # End > $dbh->rollback; > >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14874
:
51503
|
51504
|
51505
|
51652
|
51653
|
51654
|
51971
|
51972
|
52079
|
52998
|
52999
|
53000
|
53001
|
55589
|
55899
|
55912
|
55913
|
55919
|
55920
|
56027
|
56028
|
57009