From 4f14fe0fdd5ea2b3e0c13706da579b66f560240f Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 27 Jan 2017 03:13:06 +0000 Subject: [PATCH] Bug 17987: Changing PatronSelfRegistrationDefaultCategory to a dropdown menu syspref This removes the chance of a librarian putting in a patron category that does not exist and having PatronSelfRegistrationDefaultCategory default to the first category in the list. To test: 1) Put a false category code into the PatronSelfRegistrationDefaultCategory syspref 2) Go to the OPAC to self register 3) Notice the selected category type is just the first category in the list (alphabetically) 4) Apply patch and update database 5) Go back to the PatronSelfRegistrationDefaultCategory syspref 6) Select a category code from the dropdown and save 7) Go back to the OPAC and attempt to self register 8) Confirm that the correct category is now showing Sponsored-by: Catalyst IT https://bugs.koha-community.org/show_bug.cgi?id=17897 --- admin/preferences.pl | 22 ++++++++++++++++------ ...tronSelfRegistrationDefaultCategory-syspref.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-17987-changing-PatronSelfRegistrationDefaultCategory-syspref.sql diff --git a/admin/preferences.pl b/admin/preferences.pl index ef2b643..691a2c5 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -29,6 +29,7 @@ use C4::Log; use C4::Output; use C4::Templates; use Koha::Acquisition::Currencies; +use Koha::Patron::Categories; use File::Spec; use IO::File; use YAML::Syck qw(); @@ -92,6 +93,8 @@ sub _get_chunk { $options{'choices'} = { map { $_ => $_ } getallthemes( 'opac' ) } } elsif ( $options{'choices'} eq 'staff-templates' ) { $options{'choices'} = { map { $_ => $_ } getallthemes( 'intranet' ) } + } elsif ( $options{'choices'} eq 'patron-categories' ) { + $options{'choices'} = { map { $_ => $_->categorycode } Koha::Patron::Categories->search({}, { columns => 'categorycode' }) } } else { die 'Unrecognized source of preference values: ' . $options{'choices'}; } @@ -100,11 +103,19 @@ sub _get_chunk { $value ||= 0; $chunk->{'type'} = 'select'; - $chunk->{'CHOICES'} = [ - sort { $a->{'text'} cmp $b->{'text'} } - map { { text => $options{'choices'}->{$_}, value => $_, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } } - keys %{ $options{'choices'} } - ]; + if ( $name eq 'PatronSelfRegistrationDefaultCategory' ) { + $chunk->{'CHOICES'} = [ + sort { $a->{'text'} cmp $b->{'text'} } + map { { text => $options{'choices'}->{$_}, value => $options{'choices'}->{$_}, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } } + keys %{ $options{'choices'} } + ]; + } else { + $chunk->{'CHOICES'} = [ + sort { $a->{'text'} cmp $b->{'text'} } + map { { text => $options{'choices'}->{$_}, value => $_, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } } + keys %{ $options{'choices'} } + ]; + } } elsif ( $options{'multiple'} ) { my @values; @values = split /,/, $value if defined($value); @@ -295,7 +306,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( debug => 1, } ); - $lang = $template->param( 'lang' ); my $op = $input->param( 'op' ) || ''; my $tab = $input->param( 'tab' ); diff --git a/installer/data/mysql/atomicupdate/bug-17987-changing-PatronSelfRegistrationDefaultCategory-syspref.sql b/installer/data/mysql/atomicupdate/bug-17987-changing-PatronSelfRegistrationDefaultCategory-syspref.sql new file mode 100644 index 0000000..0c6ad5e --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-17987-changing-PatronSelfRegistrationDefaultCategory-syspref.sql @@ -0,0 +1 @@ +UPDATE systempreferences SET `type` = 'PatronCategories',`options` = NULL WHERE `variable` = 'PatronSelfRegistrationDefaultCategory'; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 62aaeff..e9b7d20 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -720,7 +720,7 @@ OPAC: - - "Use the patron category code" - pref: PatronSelfRegistrationDefaultCategory - class: short + choices: patron-categories - "as the default patron category for patrons registered via the OPAC." - - "Delete patrons registered via the OPAC, but not yet verified after" -- 2.1.4