From c1a8f9c454af3925869fab161f6682c73b121e78 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 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 Signed-off-by: Claire Gravely --- admin/preferences.pl | 22 ++++++++++++++++------ ...tronSelfRegistrationDefaultCategory-syspref.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 4 ++-- 3 files changed, 19 insertions(+), 8 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..ff8a087 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 { $_ => $_ } Koha::Patron::Categories->search({}) } } 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'}->{$_}->description, value => $options{'choices'}->{$_}->categorycode, selected => ( $options{'choices'}->{$_}->categorycode 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..f5751da 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 @@ -718,9 +718,9 @@ OPAC: no: "Don't require" - "that a self-registering patron verify his or herself via email." - - - "Use the patron category code" + - "Use patron category" - 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