From 81deaaa27aae4671ac00f768851262aab11c3b93 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 9 Jul 2025 23:52:53 +0000 Subject: [PATCH 07/16] Add branch libraries to reports edit view. --- Koha/Reports.pm | 27 +++++++++++++++++++++++++++ reports/guided_reports.pl | 34 +++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/Koha/Reports.pm b/Koha/Reports.pm index 605a1fc0aa..387c72abb1 100644 --- a/Koha/Reports.pm +++ b/Koha/Reports.pm @@ -33,6 +33,33 @@ Koha::Reports - Koha Report Object set class =cut +=head3 search_with_localization + +my $itemtypes = Koha::ItemTypes->search_with_localization + +=cut + +sub search_with_localization { + my ( $self, $params, $attributes ) = @_; + + my $language = C4::Languages::getlanguage(); + $Koha::Schema::Result::Itemtype::LANGUAGE = $language; + $attributes->{order_by} = 'translated_description' unless exists $attributes->{order_by}; + $attributes->{join} = 'localization'; + $attributes->{'+select'} = [ + { + coalesce => [qw( localization.translation me.description )], + -as => 'translated_description' + } + ]; + if ( defined $params->{branchcode} ) { + my $branchcode = delete $params->{branchcode}; + $self->search_with_library_limits( $params, $attributes, $branchcode ); + } else { + $self->SUPER::search( $params, $attributes ); + } +} + =head3 _type Returns name of corresponding DBIC resultset diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index c670d39274..71a5eaf6f5 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -56,7 +56,8 @@ Script to control the guided report creation my $input = CGI->new; my $usecache = Koha::Caches->get_instance->memcached_cache; -my $op = $input->param('op') // ''; +my $op = $input->param('op') // ''; +my @branches = grep { $_ ne q{} } $input->multi_param('branches'); my $flagsrequired; if ( ( $op eq 'add_form' ) || ( $op eq 'add_form_sql' ) @@ -135,11 +136,29 @@ if ( !$op ) { ); } elsif ( $op eq 'edit_form' ) { - my $id = $input->param('id'); - my $report = Koha::Reports->find($id); - my $group = $report->report_group; - my $subgroup = $report->report_subgroup; - my $tables = get_tables(); + my $id = $input->param('id'); + my $report = Koha::Reports->find($id); + my $group = $report->report_group; + my $subgroup = $report->report_subgroup; + my $tables = get_tables(); + my $selected_branches = $report ? $report->get_library_limits : undef; + my $branches = + Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; + my @branches_loop; + + foreach my $branch (@$branches) { + my $selected = + ( $selected_branches && grep { $_->branchcode eq $branch->{branchcode} } @{ $selected_branches->as_list } ) + ? 1 + : 0; + push @branches_loop, + { + branchcode => $branch->{branchcode}, + branchname => $branch->{branchname}, + selected => $selected, + }; + } + $template->param( 'sql' => $report->savedsql, 'reportname' => $report->report_name, @@ -152,7 +171,8 @@ if ( !$op ) { 'editsql' => 1, 'mana_id' => $report->{mana_id}, 'mana_comments' => $report->{comments}, - 'tables' => $tables + 'tables' => $tables, + 'branches_loop' => \@branches_loop ); } elsif ( $op eq 'cud-update_sql' || $op eq 'cud-update_and_run_sql' ) { -- 2.39.5