From 6abf977299a383e7e3afae550eca40f22e276598 Mon Sep 17 00:00:00 2001 From: Brendan Lawlor Date: Fri, 19 Jan 2024 21:25:34 +0000 Subject: [PATCH] Bug 35746: Add multiselect to report dropdowns This work in progress patch adds the ability to use multi select in report dropdowns. It uses syntax similar to using a list and when using the :all option WHERE i.homebranch in <> GROUP BY i.homebranch 2. Save the report 3. Note that you get the error The authorized value category (branches:in) you selected does not exist. 4. Apply the patch and repeat steps 1 and 2 5. Note the report saves successfully 6. Run the report 7. Note the select dropdown is now a multiselect 8. Run the report with multiple selections 10. Click show SQL and note that multi select parameters get inserted into the query like: WHERE i.homebranch in ('CPL', 'FFL', 'FPL') 11. Test other types of queries with multiple multi selects and lists etc Signed-off-by: Andrew Fuerste-Henry --- C4/Reports/Guided.pm | 14 ++--------- Koha/Report.pm | 2 +- .../modules/reports/guided_reports_start.tt | 24 +++++++++++++++++-- reports/guided_reports.pl | 11 +++++++-- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm index a55cd17743..6e450ea8af 100644 --- a/C4/Reports/Guided.pm +++ b/C4/Reports/Guided.pm @@ -574,17 +574,7 @@ sub execute_query { my ( $is_sql_valid, $errors ) = Koha::Report->new({ savedsql => $sql })->is_sql_valid; return (undef, @{$errors}[0]) unless $is_sql_valid; - foreach my $sql_param ( @$sql_params ){ - if ( $sql_param =~ m/\n/ ){ - my @list = split /\n/, $sql_param; - my @quoted_list; - foreach my $item ( @list ){ - $item =~ s/\r//; - push @quoted_list, C4::Context->dbh->quote($item); - } - $sql_param = "(".join(",",@quoted_list).")"; - } - } + my ($useroffset, $userlimit); @@ -974,7 +964,7 @@ sub GetParametersFromSQL { for ( my $i = 0; $i < ($#split/2) ; $i++ ) { my ($name,$authval) = split(/\|/,$split[$i*2+1]); - $authval =~ s/\:all$// if $authval; + $authval =~ s/\:all$|\:in$// if $authval; push @sql_parameters, { 'name' => $name, 'authval' => $authval }; } diff --git a/Koha/Report.pm b/Koha/Report.pm index 55daece836..c99e8f60fc 100644 --- a/Koha/Report.pm +++ b/Koha/Report.pm @@ -169,7 +169,7 @@ sub prep_report { # } # ) if $quoted; #} - unless ( $split[ $i * 2 + 1 ] =~ /\|\s*list\s*$/ && $quoted ) { + unless ( $split[ $i * 2 + 1 ] =~ /\|\s*list\s*$\|\s*\:in\s*$/ && $quoted ) { $quoted = C4::Context->dbh->quote($quoted); } else { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index 74d9315a4e..21e6bdc125 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -842,7 +842,7 @@ [% END # /IF ( warn_authval_problem )%] [% IF ( enter_params ) %] -
+ [% IF ( auth_val_error ) %] @@ -883,10 +883,13 @@ [% ELSE %]
  • - [% IF (sql_param.include_all) %] [% END %] + [% IF (sql_param.select_multiple) %] + + [% END %] [% FOREACH value IN sql_param.input.values %] [% END %] @@ -1535,6 +1538,23 @@