From 591ea2aa44ee1fcc56d369409d099ba49b430c28 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 21 Jul 2021 10:44:12 +0000 Subject: [PATCH] Bug 28633: Add preferred name field to patrons This patch adds a new field 'preferredname' to the patron record. Additionally it adds a method 'effective_name' to choose the preferred name if present and fall back to firstname To test: 1 - Apply patches 2 - Update database and restart all, clear browser cache 3 - Load a patron in staff module 4 - Confirm you see and can add a preferred name 5 - Confirm the preferred name now displays on patron details 6 - Edit sysprefs BorrowerMandatoryFields and BorrowerUnwantedFields to confirm you can make new field required or hidden 7 - Sign in as patron to opac 8 - Confirm preferred name shows 9 - Edit account on opac and confirm field is present --- Koha/Patron.pm | 13 ++++++++++ installer/data/mysql/kohastructure.sql | 3 +++ koha-tmpl/intranet-tmpl/prog/en/columns.def | 1 + .../prog/en/includes/patron-title.inc | 13 ++++++++-- .../prog/en/includes/patronfields.inc | 1 + .../modules/admin/preferences/borrowers.json | 1 + .../prog/en/modules/members/memberentrygen.tt | 17 ++++++++++++- .../prog/en/modules/members/members-update.tt | 1 + .../prog/en/modules/members/moremember.tt | 2 +- .../bootstrap/en/includes/patron-title.inc | 2 +- .../bootstrap/en/modules/opac-memberentry.tt | 15 ++++++++--- t/db_dependent/Koha/Patron.t | 25 ++++++++++++++++++- 12 files changed, 85 insertions(+), 9 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 941dace0df..ea09167403 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -102,6 +102,19 @@ sub new { return $class->SUPER::new($params); } +=head3 effective_name + +Return the preferred name for a patron, or their firstname if no +preferred name is set + +=cut + +sub effective_name { + my ( $self ) = @_; + + return $self->preferredname || $self->firstname; +} + =head3 fixup_cardnumber Autogenerate next cardnumber from highest value found in database diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 0ff6005d93..79a7c7270f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1229,6 +1229,7 @@ CREATE TABLE `borrower_modifications` ( `cardnumber` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `surname` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, `firstname` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `preferredname` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s preferred name', `title` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, `othernames` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, `initials` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, @@ -1347,6 +1348,7 @@ CREATE TABLE `borrowers` ( `cardnumber` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'unique key, library assigned ID number for patrons/borrowers', `surname` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s last name (surname)', `firstname` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s first name', + `preferredname` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s preferred name', `title` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s title, for example: Mr. or Mrs.', `othernames` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any other names associated with the patron/borrower', `initials` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'initials for your patron/borrower', @@ -2354,6 +2356,7 @@ CREATE TABLE `deletedborrowers` ( `cardnumber` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'unique key, library assigned ID number for patrons/borrowers', `surname` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s last name (surname)', `firstname` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s first name', + `preferredname` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s preferred name', `title` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s title, for example: Mr. or Mrs.', `othernames` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any other names associated with the patron/borrower', `initials` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'initials for your patron/borrower', diff --git a/koha-tmpl/intranet-tmpl/prog/en/columns.def b/koha-tmpl/intranet-tmpl/prog/en/columns.def index a8d15914c1..1accc028cf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/columns.def +++ b/koha-tmpl/intranet-tmpl/prog/en/columns.def @@ -2,6 +2,7 @@ Salutation Surname First name +Preferred name Date of birth Initials Other name 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 71a293588a..576b6794c6 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,8 @@ [%- SET data.surname = patron.surname -%] [%- SET data.othernames = patron.othernames -%] [%- SET data.firstname = patron.firstname -%] + [%- SET data.preferredname = patron.preferredname -%] + [%- SET data.effective_name = patron.effective_name -%] [%- SET data.cardnumber = patron.cardnumber -%] [%- SET data.borrowernumber = patron.borrowernumber -%] [%- SET data.title = patron.title -%] @@ -15,6 +17,8 @@ [%- SET data.surname = borrower.surname -%] [%- SET data.othernames = borrower.othernames -%] [%- SET data.firstname = borrower.firstname -%] + [%- SET data.preferredname = borrower.preferredname -%] + [%- SET data.effective_name = borrower.effective_name -%] [%- SET data.cardnumber = borrower.cardnumber -%] [%- SET data.borrowernumber = borrower.borrowernumber -%] [%- SET data.title = borrower.title -%] @@ -23,10 +27,15 @@ [%- SET data.surname = surname -%] [%- SET data.othernames = othernames -%] [%- SET data.firstname = firstname -%] + [%- SET data.preferredname = preferredname -%] + [%- SET data.effective_name = effective_name -%] [%- SET data.cardnumber = cardnumber -%] [%- SET data.borrowernumber = borrowernumber -%] [%- SET data.title = title -%] [%- END -%] +[%- UNLESS data.effective_name -%] + [%- SET data.effective_name = data.preferredname || data.firstname -%] +[%- END -%] [%# Parameter no_html - if 1, the html tags are NOT generated %] [%- IF no_title %][% SET data.title = "" %][% END -%] [%- IF data.title %] @@ -60,9 +69,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.effective_name ) %], [% data.effective_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.effective_name | html %] [% 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 3cea1d6851..40e23054dd 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 'firstname' -%]Preferred name [%- CASE 'title' -%]Salutation [%- CASE 'othernames' -%]Other name [%- CASE 'initials' -%]Initials diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/borrowers.json b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/borrowers.json index 1a3f77e051..f02b20783f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/borrowers.json +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/borrowers.json @@ -2,6 +2,7 @@ "cardnumber": "cardnumber", "surname": "surname", "firstname": "firstname", + "preferredname": "preferredname", "title": "title", "othernames": "othernames", "initials": "initials", 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 49ab35f70f..9fabc2e4e4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -264,7 +264,7 @@ legend:hover { [% END %] [% IF ( step_1 ) %] - [% UNLESS notitle && nosurname && nofirstname && nodateofbirth && noinitials && noothernames &&nosex %] + [% UNLESS notitle && nosurname && nofirstname && nopreferredname && nodateofbirth && noinitials && noothernames &&nosex %]
[% IF ( I ) %]Organization [% ELSE %]Patron [% END %]identity
    @@ -338,6 +338,21 @@ legend:hover { [% END %] [% END #/UNLESS nofirstname %] + [% UNLESS nopreferredname %] +
  1. + [% IF ( mandatorypreferredname ) %] +
  2. + [% END #/UNLESS nopreferredname %] [% 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 6e90e23687..b99abaca0f 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 'preferredname' %]Preferred 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 39024d6ffa..e8f821754c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -86,7 +86,7 @@

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

    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..4b87c83aaa 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.effective_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 7f1ad4a58a..a85b8a8635 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -173,7 +173,7 @@ Guaranteed by [% FOREACH gr IN patron.guarantor_relationships %] [% SET g = gr.guarantor %] - [% g.firstname | html %] [% g.surname | html %] + [% g.effective_name | html %] [% g.surname | html %] [%- IF ! loop.last %], [% END %] [% END %] @@ -190,7 +190,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' 'preferredname' '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 %] @@ -294,7 +294,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('preferredname') && hidden.defined('dateofbirth') && hidden.defined('initials') && hidden.defined('othernames') && hidden.defined('sex') %]
    @@ -337,6 +337,15 @@
  4. [% END %] + [% UNLESS hidden.defined('preferredname') %] +
  5. + + + +
    Required
    +
  6. + [% END %] + [% UNLESS hidden.defined('dateofbirth') %]
  7. diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index f5a329960d..74a63dcfbe 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 8; +use Test::More tests => 9; use Test::Exception; use Test::Warn; @@ -716,3 +716,26 @@ subtest 'can_log_into() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'effective_name() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $patron_1 = $builder->build_object({ class => 'Koha::Patrons', value => { + firstname => 'John', + preferredname => 'Jacob', + } + }); + my $patron_2 = $builder->build_object({ class => 'Koha::Patrons', value=> { + firstname => "Bob", + preferredname => undef, + } + }); + + is( $patron_1->effective_name, "Jacob", 'Preferred name correctly chosen' ); + is( $patron_2->effective_name, "Bob", 'First name correctly chosen if no preferred name' ); + + $schema->storage->txn_rollback; +}; -- 2.20.1