Bugzilla – Attachment 182198 Details for
Bug 33430
Use REST API for suggestions tables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33430: Pass search parameters to the template
Bug-33430-Pass-search-parameters-to-the-template.patch (text/plain), 7.43 KB, created by
Emily Lamancusa (emlam)
on 2025-05-09 16:44:04 UTC
(
hide
)
Description:
Bug 33430: Pass search parameters to the template
Filename:
MIME Type:
Creator:
Emily Lamancusa (emlam)
Created:
2025-05-09 16:44:04 UTC
Size:
7.43 KB
patch
obsolete
>From 495758fe3c123793c35188466a042ce908515779 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> >Date: Thu, 8 May 2025 11:05:05 +0100 >Subject: [PATCH] Bug 33430: Pass search parameters to the template > >This patch removes the existing process intensive searches and moves the search logic to a single group query that returns the values that will be the counts in the tabs. It then formats the parameters for each type and passes them to the template for the datatables ajax requests > >Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov> >--- > Koha/Schema/Result/Suggestion.pm | 24 ++++++++ > suggestion/suggestion.pl | 102 ++++++++++++++++++------------- > 2 files changed, 84 insertions(+), 42 deletions(-) > >diff --git a/Koha/Schema/Result/Suggestion.pm b/Koha/Schema/Result/Suggestion.pm >index fdbd355b53..969c040798 100644 >--- a/Koha/Schema/Result/Suggestion.pm >+++ b/Koha/Schema/Result/Suggestion.pm >@@ -572,6 +572,30 @@ __PACKAGE__->belongs_to( > }, > ); > >+__PACKAGE__->belongs_to( >+ "manager", >+ "Koha::Schema::Result::Borrower", >+ { "foreign.borrowernumber" => "self.managedby" }, >+ { >+ is_deferrable => 1, >+ join_type => "LEFT", >+ on_delete => "SET NULL", >+ on_update => "CASCADE", >+ }, >+); >+ >+__PACKAGE__->belongs_to( >+ "last_modifier", >+ "Koha::Schema::Result::Borrower", >+ { "foreign.borrowernumber" => "self.managedby" }, >+ { >+ is_deferrable => 1, >+ join_type => "LEFT", >+ on_delete => "SET NULL", >+ on_update => "CASCADE", >+ }, >+); >+ > __PACKAGE__->add_columns( > '+archived' => { is_boolean => 1 }, > ); >diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl >index a72e7a2a48..de37a7196f 100755 >--- a/suggestion/suggestion.pl >+++ b/suggestion/suggestion.pl >@@ -425,67 +425,85 @@ if ( $op eq 'else' ) { > $suggestion_ref->{branchcode} = C4::Context->userenv->{'branch'}; > } > >+ my $search_params = {%$suggestion_ref}; >+ >+ # filter on date fields >+ foreach my $field (qw( suggesteddate manageddate accepteddate )) { >+ my $from = delete $search_params->{"${field}_from"}; >+ my $to = delete $search_params->{"${field}_to"}; >+ >+ my $from_dt = $from && eval { dt_from_string($from) }; >+ my $to_dt = $to && eval { dt_from_string($to) }; >+ >+ if ( $from_dt || $to_dt ) { >+ my $dtf = Koha::Database->new->schema->storage->datetime_parser; >+ if ( $from_dt && $to_dt ) { >+ $search_params->{$field} = >+ { -between => [ $dtf->format_date($from_dt), $dtf->format_date($to_dt) ] }; >+ } elsif ($from_dt) { >+ $search_params->{$field} = { '>=' => $dtf->format_date($from_dt) }; >+ } elsif ($to_dt) { >+ $search_params->{$field} = { '<=' => $dtf->format_date($to_dt) }; >+ } >+ } >+ } >+ if ( $search_params->{budgetid} && $search_params->{budgetid} eq '__NONE__' ) { >+ $search_params->{budgetid} = [ undef, '' ]; >+ } >+ for my $f (qw (branchcode budgetid)) { >+ delete $search_params->{$f} >+ if $search_params->{$f} eq '__ANY__' >+ || $search_params->{$f} eq ''; >+ } >+ for my $bi (qw (title author isbn publishercode copyrightdate collectiontitle)) { >+ $search_params->{$bi} = { 'LIKE' => "%" . $search_params->{$bi} . "%" } if $search_params->{$bi}; >+ } >+ >+ $search_params->{archived} = 0 if !$filter_archived; >+ foreach my $key ( keys %$search_params ) { >+ if ( $key eq 'branchcode' ) { >+ my $branch_param = delete $search_params->{$key}; >+ $search_params->{"me.branchcode"} = $branch_param; >+ } >+ } >+ >+ # Retrieve the count to display on each tab >+ my $suggestion_tabs = Koha::Suggestions->search_limited( >+ $search_params, >+ { >+ select => [ $displayby, { count => $displayby, -as => 'count' } ], >+ as => [ $displayby, 'count' ], >+ group_by => [$displayby], >+ } >+ ); >+ my $tab_counts = { map { $_->get_column($displayby) => $_->get_column('count') } $suggestion_tabs->as_list }; >+ > my @allsuggestions; > foreach my $criteriumvalue (@criteria_dv) { >- my $search_params = {%$suggestion_ref}; > >+ # By default, display suggestions from current working branch >+ my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne ""; > next > if $search_params->{STATUS} > && $displayby eq 'STATUS' > && $criteriumvalue ne $search_params->{STATUS}; > >- # By default, display suggestions from current working branch >- my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne ""; >- > next > if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) > and ( $displayby ne 'branchcode' && $branchfilter ne '__ANY__' ); > >- $search_params->{$displayby} = $criteriumvalue; >- >- # filter on date fields >- foreach my $field (qw( suggesteddate manageddate accepteddate )) { >- my $from = delete $search_params->{"${field}_from"}; >- my $to = delete $search_params->{"${field}_to"}; >- >- my $from_dt = $from && eval { dt_from_string($from) }; >- my $to_dt = $to && eval { dt_from_string($to) }; >- >- if ( $from_dt || $to_dt ) { >- my $dtf = Koha::Database->new->schema->storage->datetime_parser; >- if ( $from_dt && $to_dt ) { >- $search_params->{$field} = >- { -between => [ $dtf->format_date($from_dt), $dtf->format_date($to_dt) ] }; >- } elsif ($from_dt) { >- $search_params->{$field} = { '>=' => $dtf->format_date($from_dt) }; >- } elsif ($to_dt) { >- $search_params->{$field} = { '<=' => $dtf->format_date($to_dt) }; >- } >- } >- } >- if ( $search_params->{budgetid} && $search_params->{budgetid} eq '__NONE__' ) { >- $search_params->{budgetid} = [ undef, '' ]; >- } >- for my $f (qw (branchcode budgetid)) { >- delete $search_params->{$f} >- if $search_params->{$f} eq '__ANY__' >- || $search_params->{$f} eq ''; >- } >- for my $bi (qw (title author isbn publishercode copyrightdate collectiontitle)) { >- $search_params->{$bi} = { 'LIKE' => "%" . $search_params->{$bi} . "%" } if $search_params->{$bi}; >- } >- >- $search_params->{archived} = 0 if !$filter_archived; >- my @suggestions = Koha::Suggestions->search_limited($search_params)->as_list; >+ my $criterium_search_params = {%$search_params}; >+ $criterium_search_params->{"me.$displayby"} = $criteriumvalue; > > push @allsuggestions, > { > "suggestiontype" => $criteriumvalue || "suggest", > "suggestiontypelabel" => GetCriteriumDesc( $criteriumvalue, $displayby ) || "", >- 'suggestions' => \@suggestions, > 'reasonsloop' => $reasonsloop, >+ 'search_params' => $criterium_search_params, >+ 'tab_count' => $tab_counts->{$criteriumvalue}, > } >- if scalar @suggestions > 0; >+ if $tab_counts->{$criteriumvalue} > 0; > > delete $$suggestion_ref{$displayby} unless $definedvalue; > } >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33430
:
182146
|
182147
|
182148
|
182149
|
182150
|
182161
|
182196
|
182197
|
182198
|
182199
|
182200
|
182202
|
182203
|
182204
|
182205
|
182206
|
182207
|
182208
|
182209
|
182210
|
182211
|
182339
|
182340
|
182341
|
182342
|
182343
|
182428
|
182429
|
182430
|
182431
|
182432
|
182433
|
182434
|
182478
|
182480
|
182481
|
182482
|
182483
|
182484
|
182485
|
182486
|
182487
|
182493
|
182494
|
182495
|
182496
|
182497
|
182498
|
182499
|
182500
|
182577
|
182578