From faf1e7cd914d1a6c88f5c7bef54780d43b6c453d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 27 Oct 2016 14:21:02 +0000 Subject: [PATCH] Bug 17374: Make use of fields from syspref 'DefaultPatronSearchFields' in patron search fields dropdown This patch preserves the current dropdown choices for patron search and adds fields from the DefaultPatronSearchFields system preference To test: 1 - View the regular patron search and note fields in dropdown 2 - Apply patch, ensure dropdown has not changed 3 - Add fields to DefaultPatronSearchFields, note they are available in dropdown 4 - Ensure existing and new fields search properly Signed-off-by: Kelly Signed-off-by: Maxime Dufresne Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- C4/Utils/DataTables/Members.pm | 15 ++-- ...DefaultPatronSearchFields_description.perl | 7 ++ installer/data/mysql/sysprefs.sql | 2 +- .../prog/en/includes/patron-search.inc | 64 ++++------------ .../prog/en/includes/patronfields.inc | 75 +++++++++++++++++++ .../en/modules/admin/preferences/patrons.pref | 2 +- .../prog/en/modules/members/member.tt | 63 ++++------------ 7 files changed, 119 insertions(+), 109 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug17374_update_DefaultPatronSearchFields_description.perl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index 4504bd3047..c4726ec89f 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -85,15 +85,10 @@ sub search { my $searchfields = { standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid', - surname => 'surname', email => 'email,emailpro,B_email', borrowernumber => 'borrowernumber', - userid => 'userid', phone => 'phone,phonepro,B_phone,altcontactphone,mobile', address => 'streetnumber,streettype,address,address2,city,state,zipcode,country', - dateofbirth => 'dateofbirth', - sort1 => 'sort1', - sort2 => 'sort2', }; # * is replaced with % for sql @@ -124,11 +119,17 @@ sub search { } my @where_strs_or; - for my $searchfield ( split /,/, $searchfields->{$searchfieldstype} ) { - push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?"; + if ( defined $searchfields->{$searchfieldstype} ) { + for my $searchfield ( split /,/, $searchfields->{$searchfieldstype} ) { + push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?"; + push @where_args, $term; + } + } else { + push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfieldstype) . " LIKE ?"; push @where_args, $term; } + if ( $searchfieldstype eq 'standard' and C4::Context->preference('ExtendedPatronAttributes') and $searchmember ) { my $matching_borrowernumbers = C4::Members::Attributes::SearchIdMatchingAttribute($searchmember); diff --git a/installer/data/mysql/atomicupdate/bug17374_update_DefaultPatronSearchFields_description.perl b/installer/data/mysql/atomicupdate/bug17374_update_DefaultPatronSearchFields_description.perl new file mode 100644 index 0000000000..2a8122a824 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug17374_update_DefaultPatronSearchFields_description.perl @@ -0,0 +1,7 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do( "UPDATE systempreferences SET explanation = 'Comma separated list defining the default fields to be used during a patron search using the \"standard\" option. If empty Koha will default to \"surname,firstname,othernames,cardnumber,userid\". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page.' WHERE variable='DefaultPatronSearchFields' " ); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 17374 - update description of DefaultPatronSearchFields)\n"; +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 62283f1087..fc6cb8830b 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -148,7 +148,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('DefaultLongOverdueChargeValue', '', NULL, "Charge a lost item to the borrower's account when the LOST value of the item changes to n.", 'integer'), ('DefaultLongOverdueDays', '', NULL, "Set the LOST value of an item when the item has been overdue for more than n days.", 'integer'), ('DefaultLongOverdueLostValue', '', NULL, "Set the LOST value of an item to n when the item has been overdue for more than defaultlongoverduedays days.", 'integer'), -('DefaultPatronSearchFields', 'surname,firstname,othernames,cardnumber,userid',NULL,'Comma separated list defining the default fields to be used during a patron search','free'), +('DefaultPatronSearchFields', 'surname,firstname,othernames,cardnumber,userid',NULL,'Comma separated list defining the default fields to be used during a patron search using the "standard" option. If empty Koha will default to "surname,firstname,othernames,cardnumber,userid". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page.','free'), ('defaultSortField','relevance','relevance|popularity|call_number|pubdate|acqdate|title|author','Specify the default field used for sorting','Choice'), ('defaultSortOrder','dsc','asc|dsc|az|za','Specify the default sort order','Choice'), ('DefaultToLoggedInLibraryCircRules', '0', NULL , 'If enabled, circ rules editor will default to the logged in library''s rules, rather than the ''all libraries'' rules.', 'YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index 74908496c1..68a894f0b0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -1,7 +1,9 @@ [% USE Koha %] [% USE Branches %] [% USE Categories %] +[% USE raw %] [% PROCESS 'html_helpers.inc' %] +[% PROCESS 'patronfields.inc' %]

[% LibraryName | html %]

+

-

- [% IF searchfieldstype == "standard" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "surname" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "email" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "borrowernumber" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "userid" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "phone" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "address" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "dateofbirth" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "sort1" %] - - [% ELSE %] - - [% END %] - [% IF searchfieldstype == "sort2" %] - - [% ELSE %] - - [% END %] + [% pref_fields = Koha.Preference('DefaultPatronSearchFields').split(',') %] + [% default_fields = [ 'standard', 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %] + [% search_options = default_fields.merge(pref_fields).unique %] + [% FOREACH s_o IN search_options %] + [% display_name = PROCESS patron_fields name=s_o %] + [% NEXT IF display_name.length == 5 %] + [% IF searchfieldstype == s_o %] + + [% ELSE %] + + [% END %] + [% END %]

  • -- 2.39.5