From 33903ee6d525910852021bc146bf26617a5082d3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 Feb 2021 17:19:59 +0100 Subject: [PATCH] Bug 27652: Display patron's categories for sysprefs expecting them --- admin/preferences.pl | 27 +++++++++++++++++-- circ/circulation.pl | 2 +- .../data/mysql/atomicupdate/bug_27652.perl | 11 ++++++++ .../prog/en/includes/circ-menu.inc | 2 +- .../en/modules/admin/preferences/admin.pref | 1 + .../admin/preferences/circulation.pref | 6 +++-- .../en/modules/admin/preferences/opac.pref | 2 +- opac/opac-reserve.pl | 2 +- 8 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_27652.perl diff --git a/admin/preferences.pl b/admin/preferences.pl index 1353397b9b..64a0cd81e2 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -92,6 +92,7 @@ sub _get_chunk { $chunk->{'languages'} = getTranslatedLanguages( $interface, $theme, undef, $current_languages ); $chunk->{'type'} = 'languages'; } elsif ( $options{ 'choices' } ) { + my $add_blank; if ( $options{'choices'} && ref( $options{ 'choices' } ) eq '' ) { if ( $options{'choices'} eq 'class-sources' ) { my $sources = GetClassSources(); @@ -100,6 +101,9 @@ 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 => $_->description } Koha::Patron::Categories->search }; + $add_blank = 1; } else { die 'Unrecognized source of preference values: ' . $options{'choices'}; } @@ -107,12 +111,31 @@ sub _get_chunk { $value ||= 0; - $chunk->{'type'} = 'select'; + $chunk->{'type'} = ( $options{class} && $options{class} eq 'multiple' ) ? 'multiple' : 'select'; + + my @values; + @values = split /,/, $value if defined($value); $chunk->{'CHOICES'} = [ sort { $a->{'text'} cmp $b->{'text'} } - map { { text => $options{'choices'}->{$_}, value => $_, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } } + map { + my $c = $_; + { + text => $options{'choices'}->{$c}, + value => $c, + selected => ( + grep { $_ eq $c || ( $c eq '' && ($value eq '0' || !$value ) ) } @values + ) ? 1 : 0, + } + } keys %{ $options{'choices'} } ]; + + # Add a first blank value if needed + unshift @{ $chunk->{CHOICES} }, { + text => '', + value => '', + } if $add_blank && $chunk->{type} eq 'select'; + } elsif ( $options{'multiple'} ) { my @values; @values = split /,/, $value if defined($value); diff --git a/circ/circulation.pl b/circ/circulation.pl index ee3878ca13..3865cab927 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -116,7 +116,7 @@ my $batch = $query->param('batch'); my $batch_allowed = 0; if ( $batch && C4::Context->preference('BatchCheckouts') ) { $template_name = q|circ/circulation_batch_checkouts.tt|; - my @batch_category_codes = split '\|', C4::Context->preference('BatchCheckoutsValidCategories'); + my @batch_category_codes = split ',', C4::Context->preference('BatchCheckoutsValidCategories'); my $categorycode = $patron->categorycode; if ( $categorycode && grep { $_ eq $categorycode } @batch_category_codes ) { $batch_allowed = 1; diff --git a/installer/data/mysql/atomicupdate/bug_27652.perl b/installer/data/mysql/atomicupdate/bug_27652.perl new file mode 100644 index 0000000000..13a1f75b91 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_27652.perl @@ -0,0 +1,11 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + $dbh->do(q{ + UPDATE systempreferences + value=REPLACE(value, '|', ',') + WHERE variable="OPACHoldsIfAvailableAtPickupExceptions" + OR variable="BatchCheckoutsValidCategories" + }); + NewVersion( $DBversion, 27652, "Separate values for OPACHoldsIfAvailableAtPickupExceptions and BatchCheckoutsValidCategories with comma"); +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc index e89544a71d..27b4783e8e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -125,7 +125,7 @@