From 4a4b165ea1a903342a38bbb67878c0a72314d43b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 19 Apr 2022 16:20:51 +0100 Subject: [PATCH] Bug 21978: Add support for middle name This patch adds the new 'Middle name' field to the patron record. To test: 1) Apply patches 2) Update database, restart all and clear the browser cache 3) Load a patron in the staff module 4) Confirm you can see and edit the new 'Middle name' field 5) Confirm the new middle name data displays on patron details 6) Confirm the new middle name data displays on patron search results 7) Confirm the new middle name data displays everywhere patron names are displayed. 8) Confirm the new middle name data displays on the OPAC 9) Confirm the 'Middle name' field appears in the OPAC borrower modification screens 10) Edit sysprefs `BorrowerMandatoryFields`, `BorrowerUnwantedFields`, `SelfModificationBorrowerUnwantedField`, `PatronSelfModificationMandatoryField`, `PatronSelfRegistrationBorrowerMandatoryField` and `PatronSelfRegistrationBorrowerUnwantedField` to confirm you can make the new field required or hidden. 11) Verify that DefaultPatronSearchFields contains the new field if you already had 'firstname' in the field list 12) Enable PatronAutoComplete system preference 13) Type patrons surname into checkout or patron search but don't hit return 14) Confirm the patrons middle name is displayed in the preview 15) Go to tools > patron lists and attempt to add a patron to a list 16) Patrons middle name should appear in the autocomplete here too Signed-off-by: Sally Signed-off-by: Jonathan Druart --- Koha/Database/Columns.pm | 1 + circ/ysearch.pl | 35 ++++++++++--------- .../intranet-tmpl/js/autocomplete/patrons.js | 4 +-- .../prog/en/includes/js-patron-format.inc | 8 +++-- .../prog/en/includes/js_includes.inc | 7 +++- .../prog/en/includes/patron-search-header.inc | 2 +- .../prog/en/includes/patron-search.inc | 8 ++--- .../prog/en/includes/patron-title.inc | 7 ++-- .../prog/en/includes/patronfields.inc | 1 + .../en/modules/admin/preferences/patrons.pref | 2 +- .../prog/en/modules/members/memberentrygen.tt | 17 ++++++++- .../prog/en/modules/members/members-update.tt | 1 + .../prog/en/modules/members/moremember.tt | 7 +--- .../bootstrap/en/includes/patron-title.inc | 2 +- .../bootstrap/en/modules/opac-memberentry.tt | 15 ++++++-- 15 files changed, 77 insertions(+), 40 deletions(-) diff --git a/Koha/Database/Columns.pm b/Koha/Database/Columns.pm index 5fa7075de2..c1935ba1e5 100644 --- a/Koha/Database/Columns.pm +++ b/Koha/Database/Columns.pm @@ -63,6 +63,7 @@ sub columns { "title" => __("Salutation"), "surname" => __("Surname"), "firstname" => __("First name"), + "middle_name" => __("Middle name"), "dateofbirth" => __("Date of birth"), "initials" => __("Initials"), "othernames" => __("Other name"), diff --git a/circ/ysearch.pl b/circ/ysearch.pl index 3f2650cbeb..2e2729778e 100755 --- a/circ/ysearch.pl +++ b/circ/ysearch.pl @@ -59,9 +59,10 @@ foreach my $p (@parts) { push( @params, -or => [ - surname => { -like => "%$p%" }, - firstname => { -like => "%$p%" }, - cardnumber => { -like => "$p%" }, + surname => { -like => "%$p%" }, + firstname => { -like => "%$p%" }, + middle_name => { -like => "%$p%" }, + cardnumber => { -like => "$p%" }, ] ); } @@ -74,7 +75,7 @@ my $borrowers_rs = Koha::Patrons->search_limited( # Get the first 10 results page => 1, rows => 10, - order_by => [ 'surname', 'firstname' ], + order_by => [ 'surname', 'firstname', 'middle_name' ], prefetch => 'branchcode', }, ); @@ -82,18 +83,20 @@ my $borrowers_rs = Koha::Patrons->search_limited( my @borrowers; while ( my $b = $borrowers_rs->next ) { push @borrowers, - { borrowernumber => $b->borrowernumber, - surname => $b->surname // '', - firstname => $b->firstname // '', - cardnumber => $b->cardnumber // '', - dateofbirth => format_sqldatetime($b->dateofbirth, undef, undef, 1) // '', - age => $b->get_age // '', - address => $b->address // '', - city => $b->city // '', - zipcode => $b->zipcode // '', - country => $b->country // '', - branchcode => $b->branchcode // '', - branchname => $b->library->branchname // '', + { + borrowernumber => $b->borrowernumber, + surname => $b->surname // '', + firstname => $b->firstname // '', + middle_name => $b->middle_name // '', + cardnumber => $b->cardnumber // '', + dateofbirth => format_sqldatetime( $b->dateofbirth, undef, undef, 1 ) // '', + age => $b->get_age // '', + address => $b->address // '', + city => $b->city // '', + zipcode => $b->zipcode // '', + country => $b->country // '', + branchcode => $b->branchcode // '', + branchname => $b->library->branchname // '', }; } diff --git a/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js b/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js index ef61f0e085..ba59783e82 100644 --- a/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js +++ b/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js @@ -12,7 +12,7 @@ function patron_autocomplete(params) { if ( field_to_retrieve == 'borrowernumber' ) { field = ui.item.borrowernumber; } - AddPatron( ui.item.firstname + " " + ui.item.surname, field, patron_container, patron_input_name ); + AddPatron( ui.item.firstname + " " + ui.item.middle_name + " " + ui.item.surname, field, patron_container, patron_input_name ); input_autocomplete.val('').focus(); return false; } @@ -20,7 +20,7 @@ function patron_autocomplete(params) { .data( "ui-autocomplete" )._renderItem = function( ul, item ) { return $( "
  • " ) .data( "ui-autocomplete-item", item ) - .append( "" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "" ) + .append( "" + item.surname + ", " + item.firstname + " " + item.middle_name + " (" + item.cardnumber + ") " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "" ) .appendTo( ul ); }; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format.inc index 0c1daae17f..5e125dbc29 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format.inc @@ -19,8 +19,12 @@ } var name; - var firstname = escape_str(patron.firstname); - var surname = escape_str(patron.surname); + var firstname = escape_str(patron.firstname); + var surname = escape_str(patron.surname); + + if ( patron.middle_name != null && patron.middle_name != '' ) { + firstname += ' ' + escape_str(patron.middle_name); + } if ( patron.other_name != null && patron.other_name != '' ) { firstname += ' (' + escape_str(patron.other_name) + ')'; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc index d9f19b7229..cc3cbb713a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -87,7 +87,11 @@ // Display card number in parentheses if it exists cardnumber = " (" + item.cardnumber + ") "; } - var itemString = "" + ( item.surname ? item.surname.escapeHtml() : "" ) + ", " + ( item.firstname ? item.firstname.escapeHtml() : "" ) + cardnumber.escapeHtml() + " "; + var itemString = "" + ( item.surname ? item.surname.escapeHtml() : "" ) + ", " + + ( item.firstname ? item.firstname.escapeHtml() : "" ) + + ( item.middle_name ? " " + item.middle_name.escapeHtml() : "" ) + + cardnumber.escapeHtml() + + " "; if( item.branchcode == loggedInLibrary ){ loggedInClass = "ac-currentlibrary"; @@ -150,6 +154,7 @@ .append( "" + ( item.surname ? item.surname.escapeHtml() : "" ) + ", " + ( item.firstname ? item.firstname.escapeHtml() : "" ) + + ( item.middle_name ? " " + item.middle_name.escapeHtml() : "" ) + cardnumber.escapeHtml() + " " + ( item.dateofbirth ? item.dateofbirth.escapeHtml() : "" ) + " " diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc index ff17ca9280..d800b9c239 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc @@ -23,7 +23,7 @@

    - [% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' %] + [% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' %] [% default_fields = [ standard, 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %] [% search_options = default_fields.merge(standard.split(',')).unique %] [% FOREACH s_o IN search_options %] @@ -317,7 +317,7 @@ let search_type = $("#searchtype_filter").val() || "contain"; let search_fields = $("#searchfieldstype_filter").val(); if ( !search_fields ) { - search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' | html %]"; + search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]"; } let subquery_and = []; @@ -458,7 +458,7 @@ } [% CASE 'name-address' %] { - "data": "me.surname:me.firstname:me.othernames:me.street_number:me.address:me.address2:me.city:me.state:me.postal_code:me.country", + "data": "me.surname:me.firstname:me.middle_name:me.othernames:me.street_number:me.address:me.address2:me.city:me.state:me.postal_code:me.country", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { @@ -508,7 +508,7 @@ } [% CASE 'name' %] { - "data": "me.surname:me.firstname:me.othernames", + "data": "me.surname:me.firstname:me.middle_name:me.othernames", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-title.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-title.inc index e047700963..d2b61aade6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-title.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-title.inc @@ -7,6 +7,7 @@ [%- SET data.surname = patron.surname -%] [%- SET data.othernames = patron.othernames -%] [%- SET data.firstname = patron.firstname -%] + [%- SET data.middle_name = patron.middle_name -%] [%- SET data.cardnumber = patron.cardnumber -%] [%- SET data.borrowernumber = patron.borrowernumber -%] [%- SET data.title = patron.title -%] @@ -15,6 +16,7 @@ [%- SET data.surname = borrower.surname -%] [%- SET data.othernames = borrower.othernames -%] [%- SET data.firstname = borrower.firstname -%] + [%- SET data.middle_name = borrower.middle_name -%] [%- SET data.cardnumber = borrower.cardnumber -%] [%- SET data.borrowernumber = borrower.borrowernumber -%] [%- SET data.title = borrower.title -%] @@ -23,6 +25,7 @@ [%- SET data.surname = surname -%] [%- SET data.othernames = othernames -%] [%- SET data.firstname = firstname -%] + [%- SET data.middle_name = middle_name -%] [%- SET data.cardnumber = cardnumber -%] [%- SET data.borrowernumber = borrowernumber -%] [%- SET data.title = title -%] @@ -61,9 +64,9 @@ [%- IF data.category_type == 'I' -%] [%- data.surname | html %] [% IF data.othernames %] ([% data.othernames | html %])[% END -%] [%- ELSIF invert_name -%] - [% data.title | $raw %][%- data.surname | html %][% IF ( data.firstname ) %], [% data.firstname | html %][% END %][% IF data.othernames %] ([% data.othernames | html %]) [% END -%] + [% data.title | $raw %][%- data.surname | html %][% IF ( data.firstname ) %], [% data.firstname | html %][% END %][% IF data.middle_name %] [% data.middle_name | html %][% END %][% IF data.othernames %] ([% data.othernames | html %]) [% END -%] [%- ELSE -%] - [% data.title | $raw %][%- data.firstname | html %] [% IF data.othernames %] ([% data.othernames | html %]) [% END %] [% data.surname | html -%] + [% data.title | $raw %][%- data.firstname | html %][% IF data.middle_name %] [% data.middle_name | html %][% END %][% IF data.othernames %] ([% data.othernames | html %]) [% END %] [% data.surname | html -%] [%- END -%] [%- IF display_cardnumber AND data.cardnumber %] ([% data.cardnumber | html %])[% END -%] [%- ELSIF display_cardnumber -%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc index 416a5ae26c..3d3a3cd2e7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc @@ -5,6 +5,7 @@ [%- CASE 'cardnumber' -%]Card number [%- CASE 'surname' -%]Surname [%- CASE 'firstname' -%]First name + [%- CASE 'middle_name' -%]Middle name [%- CASE 'title' -%]Salutation [%- CASE 'othernames' -%]Other name [%- CASE 'initials' -%]Initials diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 5cdc142682..239dd62ed7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -48,7 +48,7 @@ Patrons: - "Comma separated list defining the default fields to be used during a patron search using the \"standard\" option:" - pref: DefaultPatronSearchFields class: multi - - "If empty Koha will default to \"firstname,surname,othernames,cardnumber,userid\". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page." + - "If empty Koha will default to \"firstname,middle_name,surname,othernames,cardnumber,userid\". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page." - - "Show the following fields from the items database table as columns on the statistics tab on the patron record: " - pref: StatisticsFields diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index c065dd3454..c5f17cb6f0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -267,7 +267,7 @@ legend:hover { [% END %] [% IF ( step_1 ) %] - [% UNLESS notitle && nosurname && nofirstname && nodateofbirth && noinitials && noothernames &&nosex %] + [% UNLESS notitle && nosurname && nofirstname && nomiddle_name && nodateofbirth && noinitials && noothernames &&nosex %]

    [% IF ( I ) %]Organization [% ELSE %]Patron [% END %]identity
      @@ -341,6 +341,21 @@ legend:hover { [% END %] [% END #/UNLESS nofirstname %] + [% UNLESS nomiddle_name %] +
    1. + [% IF ( mandatorymiddle_name ) %] +
    2. + [% END #/UNLESS nomiddle_name %] [% UNLESS nodateofbirth %]
    3. [% IF ( mandatorydateofbirth ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt index 9384c653c9..7d3ba0b643 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt @@ -19,6 +19,7 @@ [% CASE 'branchcode' %]Home library (branchcode) [% CASE 'surname' %]Surname [% CASE 'firstname' %]First name +[% CASE 'middle_name' %]Middle name [% CASE 'title' %]Title [% CASE 'othernames' %]Other names [% CASE 'initials' %]Initials diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 8d509b56a2..bf90be1d45 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -95,12 +95,7 @@ [% INCLUDE 'patron_messages.inc' %]
    -

    - [% UNLESS ( I ) %] - [% patron.title | html %] [% patron.firstname | html %] - [% END %] - [% patron.surname | html %] ([% patron.cardnumber | html %]) -

    +

    [% INCLUDE 'patron-title.inc' no_html = 1 %]

    diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/patron-title.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/patron-title.inc index d77961d713..d34475359d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/patron-title.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/patron-title.inc @@ -4,5 +4,5 @@ [%- IF patron.title -%] [% patron.title | html %] [%- END -%] - [% patron.firstname | html %] [% patron.surname | html %] + [% patron.firstname | html %] [% patron.middle_name | html %] [% patron.surname | html %] [%- END -%] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index cd146409d4..45c4373199 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -176,7 +176,7 @@ Guaranteed by [% FOREACH gr IN patron.guarantor_relationships %] [% SET g = gr.guarantor %] - [% g.firstname | html %] [% g.surname | html %] + [% g.firstname | html %] [% g.middle_name | html %] [% g.surname | html %] [%- IF ! loop.last %], [% END %] [% END %] @@ -193,7 +193,7 @@
    - [% FOREACH field = ['streetnumber' 'streettype' 'cardnumber' 'branchcode' 'categorycode' 'title' 'surname' 'firstname' 'dateofbirth' 'initials' 'othernames' 'address' 'address2' 'city' 'state' 'zipcode' 'country' 'phone' 'phonepro' 'mobile' 'email' 'emailpro' 'fax' 'B_streettype' 'B_address' 'B_address2' 'B_city' 'B_state' 'B_zipcode' 'B_country' 'B_phone' 'B_email' 'contactnote' 'altcontactsurname' 'altcontactfirstname' 'altcontactaddress1' 'altcontactaddress2' 'altcontactaddress3' 'altcontactstate' 'altcontactzipcode' 'altcontactcountry' 'altcontactphone' 'password' ] %] + [% FOREACH field = ['streetnumber' 'streettype' 'cardnumber' 'branchcode' 'categorycode' 'title' 'surname' 'firstname' 'middle_name' 'dateofbirth' 'initials' 'othernames' 'address' 'address2' 'city' 'state' 'zipcode' 'country' 'phone' 'phonepro' 'mobile' 'email' 'emailpro' 'fax' 'B_streettype' 'B_address' 'B_address2' 'B_city' 'B_state' 'B_zipcode' 'B_country' 'B_phone' 'B_email' 'contactnote' 'altcontactsurname' 'altcontactfirstname' 'altcontactaddress1' 'altcontactaddress2' 'altcontactaddress3' 'altcontactstate' 'altcontactzipcode' 'altcontactcountry' 'altcontactphone' 'password' ] %] [% IF mandatory.defined( field ) %] [% SET required.$field = 'required' %] [% END %] @@ -300,7 +300,7 @@ [% END # / defined 'branchcode' %] [%# Following on one line for translatability %] - [% UNLESS hidden.defined('title') && hidden.defined('surname') && hidden.defined('firstname') && hidden.defined('dateofbirth') && hidden.defined('initials') && hidden.defined('othernames') && hidden.defined('sex') %] + [% UNLESS hidden.defined('title') && hidden.defined('surname') && hidden.defined('firstname') && hidden.defined('middle_name') && hidden.defined('dateofbirth') && hidden.defined('initials') && hidden.defined('othernames') && hidden.defined('sex') %]
    @@ -343,6 +343,15 @@ [% END %] + [% UNLESS hidden.defined('middle_name') %] +
  • + + + +
    Required
    +
  • + [% END %] + [% UNLESS hidden.defined('dateofbirth') %]
  • -- 2.20.1