Bugzilla – Attachment 128969 Details for
Bug 28633
Add a preferred name field to patrons
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28633: Add preferred name field to patrons
Bug-28633-Add-preferred-name-field-to-patrons.patch (text/plain), 20.44 KB, created by
Nick Clemens (kidclamp)
on 2022-01-03 15:33:38 UTC
(
hide
)
Description:
Bug 28633: Add preferred name field to patrons
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2022-01-03 15:33:38 UTC
Size:
20.44 KB
patch
obsolete
>From d691a5c6d319bbfb484a089431d8dd7016a7fa1e Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 3 Jan 2022 15:24:01 +0000 >Subject: [PATCH] Bug 28633: Add preferred name field to patrons > >This patch adds a new field 'preferred_name' to the patron record. > >Additionally it adds a method 'effective_name' to choose the preferred name if present >and fall back to firstname > >The 'firstname' is displayed as 'First name' on the details page, with id/class >patron_first_name to allow ajusting via JS/CSS if library wants to highlight/hide >the non-preferred name > >PatronAutoComplete/ysearch is updated to use 'effective_name' method > >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 and first name now displays on patron details > 6 - Remove first name from patron record and confirm it no longer shows > 7 - Edit sysprefs BorrowerMandatoryFields and BorrowerUnwantedFields to confirm you can make > new field required or hidden > 8 - Sign in as patron to opac > 9 - Confirm preferred name shows >10 - Edit account on opac and confirm field is present >11 - Verify DefaultPatronSearchFields contains 'preferredname' if your pref had firstname >12 - Perform checkout and patron search using preferred_name, confirm patron is found >13 - Enable PatronAutoComplete system preference >14 - Type patron's surname into Checkout or patron search but don't hit enter >15 - Confirm patron is displayed with 'preferred_name' in the preview >--- > C4/Utils/DataTables/Members.pm | 2 +- > Koha/Patron.pm | 13 ++++++++++ > circ/ysearch.pl | 2 +- > .../prog/en/includes/patron-title.inc | 13 ++++++++-- > .../prog/en/includes/patronfields.inc | 1 + > .../modules/admin/preferences/borrowers.json | 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 | 8 +++++- > .../bootstrap/en/includes/patron-title.inc | 2 +- > .../bootstrap/en/modules/opac-memberentry.tt | 15 ++++++++--- > t/db_dependent/Koha/Patron.t | 25 ++++++++++++++++++- > 13 files changed, 90 insertions(+), 12 deletions(-) > >diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm >index 15f04eb972..78e2f8f7bf 100644 >--- a/C4/Utils/DataTables/Members.pm >+++ b/C4/Utils/DataTables/Members.pm >@@ -113,7 +113,7 @@ sub search { > } > > my $searchfields = { >- standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid', >+ standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,preferred_name,othernames,cardnumber,userid', > email => 'email,emailpro,B_email', > borrowernumber => 'borrowernumber', > phone => 'phone,phonepro,B_phone,altcontactphone,mobile', >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 85d9c01bf1..1e093ec88b 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -103,6 +103,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->preferred_name || $self->firstname; >+} >+ > =head3 fixup_cardnumber > > Autogenerate next cardnumber from highest value found in database >diff --git a/circ/ysearch.pl b/circ/ysearch.pl >index efe1a62d24..292145c309 100755 >--- a/circ/ysearch.pl >+++ b/circ/ysearch.pl >@@ -84,7 +84,7 @@ while ( my $b = $borrowers_rs->next ) { > push @borrowers, > { borrowernumber => $b->borrowernumber, > surname => $b->surname // '', >- firstname => $b->firstname // '', >+ firstname => $b->effective_name // '', > cardnumber => $b->cardnumber // '', > dateofbirth => format_sqldatetime($b->dateofbirth, undef, undef, 1) // '', > age => $b->get_age // '', >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..9a18048142 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.preferred_name = patron.preferred_name -%] >+ [%- 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.preferred_name = borrower.preferred_name -%] >+ [%- 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.preferred_name = preferred_name -%] >+ [%- 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.preferred_name || 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 7edc5c9082..fc31fad81e 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' -%]<span>Card number</span> > [%- CASE 'surname' -%]<span>Surname</span> > [%- CASE 'firstname' -%]<span>First name</span> >+ [%- CASE 'preferred_name' -%]<span>Preferred name</span> > [%- CASE 'title' -%]<span>Salutation</span> > [%- CASE 'othernames' -%]<span>Other name</span> > [%- CASE 'initials' -%]<span>Initials</span> >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 23140978f0..4d5a6934c2 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", >+ "preferred_name": "preferred_name", > "title": "title", > "othernames": "othernames", > "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 5a6f1bd5a4..3c44ba3e7d 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 \"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." >+ - "If empty Koha will default to \"surname,firstname,preferred_name,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 39f1e5f2a8..7d3175e87b 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 && nopreferred_name && nodateofbirth && noinitials && noothernames &&nosex %] > <fieldset class="rows" id="memberentry_identity"> > <legend id="identity_lgd">[% IF ( I ) %]Organization [% ELSE %]Patron [% END %]identity</legend> > <ol> >@@ -338,6 +338,21 @@ legend:hover { > [% END %] > </li> > [% END #/UNLESS nofirstname %] >+ [% UNLESS nopreferred_name %] >+ <li> >+ [% IF ( mandatorypreferred_name ) %] >+ <label for="preferred_name" class="required"> >+ [% ELSE %] >+ <label for="preferred_name"> >+ [% END %] >+ Preferred name: >+ </label> >+ <input type="text" id="preferred_name" name="preferred_name" size="20" value="[% preferred_name | html UNLESS opduplicate %]" /> >+ [% IF ( mandatorypreferred_name ) %] >+ <span class="required">Required</span> >+ [% END %] >+ </li> >+ [% END #/UNLESS nopreferred_name %] > [% UNLESS nodateofbirth %] > <li> > [% 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..85f40a61aa 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' %]<span>Home library (branchcode)</span> > [% CASE 'surname' %]<span>Surname</span> > [% CASE 'firstname' %]<span>First name</span> >+[% CASE 'preferred_name' %]<span>Preferred name</span> > [% CASE 'title' %]<span>Title</span> > [% CASE 'othernames' %]<span>Other names</span> > [% CASE 'initials' %]<span>Initials</span> >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 853cac23c3..e66ac47651 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >@@ -87,7 +87,7 @@ > > <h3> > [% UNLESS ( I ) %] >- [% patron.title | html %] [% patron.firstname | html %] >+ [% patron.title | html %] [% patron.effective_name | html %] > [% END %] > [% patron.surname | html %] ([% patron.cardnumber | html %]) > </h3> >@@ -125,6 +125,12 @@ > > <div class="rows"> > <ol> >+ [% IF ( patron.preferred_name && patron.firstname ) %] >+ <li id="patron_first_name"> >+ <span class="label patron_first_name">First name: </span> >+ [% patron.firstname | html %] >+ </li> >+ [% END %] > [% IF ( patron.phone ) %] > <li> > <span class="label">Primary phone: </span> >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 -%] > <span class="patron-title">[% patron.title | html %]</span> > [%- 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 8d2b8a0f78..c4aee0eb3f 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.effective_name | html %] [% g.surname | html %] > [%- IF ! loop.last %], [% END %] > [% END %] > </span> >@@ -193,7 +193,7 @@ > > <form method="post" action="/cgi-bin/koha/opac-memberentry.pl" id="memberentry-form" autocomplete="off"> > >- [% 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' 'preferred_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 %] >@@ -297,7 +297,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('preferred_name') && hidden.defined('dateofbirth') && hidden.defined('initials') && hidden.defined('othernames') && hidden.defined('sex') %] > <div class="row"> > <div class="col"> > <fieldset class="rows" id="memberentry_identity"> >@@ -340,6 +340,15 @@ > </li> > [% END %] > >+ [% UNLESS hidden.defined('preferred_name') %] >+ <li> >+ <label for="borrower_preferred_name" class="[% required.preferred_name | html %]">Preferrred name:</label> >+ >+ <input type="text" id="borrower_preferred_name" name="borrower_preferred_name" value="[% borrower.preferred_name | html %]" class="[% required.preferred_name | html %]" /> >+ <div class="required_label [% required.preferred_name | html %]">Required</div> >+ </li> >+ [% END %] >+ > [% UNLESS hidden.defined('dateofbirth') %] > <li> > <label for="borrower_dateofbirth" class="[% required.dateofbirth | html %]">Date of birth:</label> >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index 2929349661..f621a80674 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 => 10; >+use Test::More tests => 11; > use Test::Exception; > use Test::Warn; > >@@ -846,3 +846,26 @@ subtest 'article_requests() 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', >+ preferred_name => 'Jacob', >+ } >+ }); >+ my $patron_2 = $builder->build_object({ class => 'Koha::Patrons', value=> { >+ firstname => "Bob", >+ preferred_name => 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.30.2
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 28633
:
123008
|
123009
|
123010
|
123658
|
125497
|
125498
|
125499
|
125500
|
126591
|
128968
|
128969
|
128970
|
130000
|
130001
|
130002
|
133445
|
133446
|
133447
|
133448
|
133449
|
133450
|
133451
|
133958
|
133959
|
133960
|
133961
|
133962
|
133963
|
133964
|
133965
|
166792
|
166793
|
166794
|
166813
|
166814
|
166815
|
166816
|
166817
|
167163
|
167164
|
173628
|
173629
|
173630
|
173631
|
173632
|
173633
|
173634
|
173664
|
173665
|
173666
|
173667
|
173668
|
173669
|
173670
|
173717
|
173718
|
173719
|
173813
|
173814
|
173815
|
173816
|
173826
|
173827
|
173828
|
173829
|
173930
|
173931
|
173932
|
173933
|
173934
|
173935
|
173936
|
174419
|
174420
|
174472
|
175177