From fafab9dcbbe599a1cbf8d36d13188c56d105e960 Mon Sep 17 00:00:00 2001 From: Emily-Rose Francoeur Date: Tue, 21 Nov 2023 15:13:43 -0500 Subject: [PATCH] Bug 35145: Add ability to order patron attribute types Here is a summary of the changes: - Added the new column 'number' to 'borrower_attribute_types' table ---> Created an atomic update file (bug_35145_order_patron_attributes.pl) ---> Updated the kohastructure.sql file - Added the new column 'number' for '/cgi-bin/koha/admin/patron-attr-types.pl' table ---> The table now defaults to sorting based on the 'number' column - Added the field 'Appear in position' in the patron attribute types create/edit form - Changed the order of patron attribute types in the patron create/edit form (OPAC and staff interfcce) so it's now sorted by the assigned number TEST PLAN 1) Go to 'Koha administration > Patron attribute types > + New patron attribute type' 2) Fill out the form ---> Code: Enter any code, for example 'WEIGHT' ---> Description: Enter any description ---> Display in OPAC: Check ---> Editable in OPAC: Check ---> Class: Keep it empty 3) Click 'Save' 4) Repeat to add a second code with a code alphabetically "before" the previous one, for example SURNAME 5) Optionally, add more to really view the order 6) Go to 'Koha administration > System preferences' 7) Search for 'selfreg' 8) Set 'PatronSelfRegistration' to 'Allow' 9) Set a category in 'PatronSelfRegistrationDefaultCategory' 10) Click on the 'Save all OPAC preferences' button 11) Go to the OPAC and click on the 'Create an account' button 12) Go to the bottom of the form ---> Note that the patron attribute fields are presented in alphabetical order of code 13) Apply the patch 14) Perform an atomic update (./installer/data/mysql/updatedatabase.pl) 15) Return to 'Koha administration > Patron attribute types' ---> Notice the new 'number' column in the tables 16) Choose one of the attribute types you created earlier and click on the 'edit' button ---> You should now see the 'Appear in position' field 17) Enter a number in the 'Appear in position' field and click on 'Save' 18) Repeat the last two steps for each attribute type you created ---> Notice that the patron attribute types tables are sorted by number by default 19) In the staff interface, go to 'Patrons > + New patron' ---> In the 'Additional attributes and identifiers' section, notice that the fields are in the given number order 20) In the OPAC, return to the patron creation form (step 11) ---> At the end of the form, notice that the fields are in the given number order Signed-off-by: Owen Leonard --- Koha/Schema/Result/BorrowerAttributeType.pm | 10 ++++++++++ admin/patron-attr-types.pl | 2 ++ .../bug_35145_order_patron_attributes.pl | 20 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + .../en/modules/admin/patron-attr-types.tt | 13 +++++++++++- members/memberentry.pl | 2 +- opac/opac-memberentry.pl | 2 +- 7 files changed, 47 insertions(+), 3 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_35145_order_patron_attributes.pl diff --git a/Koha/Schema/Result/BorrowerAttributeType.pm b/Koha/Schema/Result/BorrowerAttributeType.pm index ad609f0a78..dbf5383459 100644 --- a/Koha/Schema/Result/BorrowerAttributeType.pm +++ b/Koha/Schema/Result/BorrowerAttributeType.pm @@ -137,6 +137,14 @@ defines if this field is copied to anonymized_borrower_attributes (1 for yes, 0 defines if the attribute is mandatory or not +=head2 number + + data_type: 'int' + default_value: NULL + is_nullable: 1 + + the order in which this attribute type appears in patron form + =cut __PACKAGE__->add_columns( @@ -168,6 +176,8 @@ __PACKAGE__->add_columns( { data_type => "tinyint", default_value => 0, is_nullable => 0 }, "mandatory", { data_type => "tinyint", default_value => 0, is_nullable => 0 }, + "number", + { data_type => "int", is_nullable => 1 }, ); =head1 PRIMARY KEY diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl index ca5d2fca47..720a929715 100755 --- a/admin/patron-attr-types.pl +++ b/admin/patron-attr-types.pl @@ -124,6 +124,7 @@ sub add_update_attribute_type { my $display_checkout = $input->param('display_checkout') ? 1 : 0; my $category_code = $input->param('category_code') || undef; my $class = $input->param('class'); + my $number = $input->param('number') || undef; my $attr_type = Koha::Patron::Attribute::Types->find($code); if ( $op eq 'edit' ) { @@ -160,6 +161,7 @@ sub add_update_attribute_type { display_checkout => $display_checkout, category_code => $category_code, class => $class, + number => $number, } )->store; diff --git a/installer/data/mysql/atomicupdate/bug_35145_order_patron_attributes.pl b/installer/data/mysql/atomicupdate/bug_35145_order_patron_attributes.pl new file mode 100755 index 0000000000..ac5a0520e2 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_35145_order_patron_attributes.pl @@ -0,0 +1,20 @@ +use Modern::Perl; + +return { + bug_number => "35145", + description => "Add number column to borrower_attribute_types table", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + # Do you stuffs here + $dbh->do(q{ + ALTER TABLE borrower_attribute_types + ADD number int(11); + }); + + # Print useful stuff here + # tables + say $out "Added column 'borrower_attribute_types.number'"; + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 16310f0f44..d47818605f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1242,6 +1242,7 @@ CREATE TABLE `borrower_attribute_types` ( `class` varchar(255) NOT NULL DEFAULT '' COMMENT 'defines a class for an attribute_type', `keep_for_pseudonymization` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is copied to anonymized_borrower_attributes (1 for yes, 0 for no)', `mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not', + `number` int(11) DEFAULT NULL COMMENT 'the order in which this attribute type appears in patron form', PRIMARY KEY (`code`), KEY `auth_val_cat_idx` (`authorised_value_category`), KEY `category_code` (`category_code`), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt index bad4257539..ec89b1d548 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt @@ -104,6 +104,14 @@ Required +
  • + + [% IF ( attribute_type.number ) %] + + [% ELSE %] + + [% END %] +
  • [% IF attribute_type AND attribute_type.repeatable AND NOT can_be_set_to_nonrepeatable %]
  • @@ -317,6 +325,7 @@ Authorized value category Mandatory Searching + Number Actions @@ -367,6 +376,7 @@ Not searchable [% END %] + [% item.number | html %] Edit Delete @@ -432,7 +442,8 @@ $(".patron_attributes_types").each(function(){ var tableid = $(this).attr("id"); KohaTable( tableid, { - "paginate": false, + "sorting": [[ 6, "asc" ]], + "bPaginate": false, 'autoWidth': false, }, null ); }); diff --git a/members/memberentry.pl b/members/memberentry.pl index 57e780cfec..790b47f046 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -866,7 +866,7 @@ sub patron_attributes_form { my $op = shift; my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; - my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id); + my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, { order_by => 'number' }, $library_id); if ( $attribute_types->count == 0 ) { $template->param(no_patron_attribute_types => 1); return; diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 51f03fca19..064e8389a9 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -672,7 +672,7 @@ sub GeneratePatronAttributesForm { # Get all attribute types and the values for this patron (if applicable) my @types = grep { $_->opac_editable() or $_->opac_display } # FIXME filter using DBIC - Koha::Patron::Attribute::Types->search()->as_list(); + Koha::Patron::Attribute::Types->search( {}, { order_by => 'number' } )->as_list(); if ( scalar(@types) == 0 ) { return []; } -- 2.34.1