From a4ae2a530c6868b205254fd857c0f31f91447177 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Sun, 19 Feb 2017 03:07:03 +0000 Subject: [PATCH] Bug 18212 - Created a subroutine GetAuthValuesForCategory() in C4/Acqusition.pm perl module. I've removed one sql select query from aqplan.pl and rewritten it in DBIx query format in the new GetAuthValuesForCategory subroutine. aqplan.pl is successfully calling and running this DBIx query --- C4/Acquisition.pm | 18 ++++++++++++++++++ admin/aqplan.pl | 15 +++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index c113c16..10233d2 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -2980,6 +2980,24 @@ sub GetOrderUsers { return @borrowernumbers; } +=head3 GetAuthorisedValues + + + +=cut + +sub GetAuthValuesForCategory{ + my ($self, $category) = @_; + my $schema = Koha::Database->new()->schema(); + my $authvalues = Koha::AuthorisedValues->search({ + 'category' => $category, + order_by => { -asc => 'lib'} + }); + return $authvalues; +} + + + =head3 ModOrderUsers my @order_users_ids = (1, 2, 3); diff --git a/admin/aqplan.pl b/admin/aqplan.pl index a27fb0a..9dac549 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -192,18 +192,17 @@ HideCols($authcat, @hide_cols); } # ------------------------------------------------------------ if ( $authcat =~ m/^Asort/ ) { - my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib }; - my $sth = $dbh->prepare($query); - $sth->execute($authcat ); - if ( $sth->rows > 0 ) { - for ( my $i = 0 ; $i < $sth->rows ; $i++ ) { - my $results = $sth->fetchrow_hashref; + my $categoryauthvalues = C4::Acquisition->GetAuthValuesForCategory($authcat); + + if ( $categoryauthvalues->rows > 0 ) { + for ( my $i = 0 ; $i < $categoryauthvalues->rows ; $i++ ) { + my $results = $categoryauthvalues->fetchrow_hashref; push @authvals, $results->{authorised_value}; $labels{ $results->{authorised_value} } = $results->{lib}; } } - $sth->finish; - @authvals = sort { $a <=> $b } @authvals; + $categoryauthvalues->finish; + @authvals = sort { $a <=> $b } @authvals; } elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_enddate ) { -- 2.1.4