From 2e57b6ef392ecf5ca39abcf7ef3acd2ba5781451 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Fri, 10 Mar 2017 13:51:40 +0000 Subject: [PATCH] Bug 18247 - Moved the SQL queries out of the branch_transfer_limits.pl script into the Koha::AuthorisedValue, Koha::Libraries, Koha::ItemType perl modules All the queries run successfully in the perl modules. --- Koha/AuthorisedValue.pm | 13 +++++++++++++ Koha/ItemType.pm | 15 +++++++++++++++ Koha/Libraries.pm | 17 +++++++++++++++++ admin/branch_transfer_limits.pl | 19 +++++++++++-------- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm index 898b630..48aa813 100644 --- a/Koha/AuthorisedValue.pm +++ b/Koha/AuthorisedValue.pm @@ -158,6 +158,19 @@ sub _avb_resultset { $self->{_avb_resultset}; } +=head3 GetCatAuthValues +$sth = Koha::AuthorisedValue->GetCatAuthValues($dbh); + +This subroutine retrieves and returns all authorised_values (in the authorised_values table where the category=CCODE) in a column named ccode +=cut + +sub GetCatAuthValues { + my ($self, $dbh) = @_; + my $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"'); + $sth->execute(); + return $sth; +} + =head3 type =cut diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 48df808..4f3522e 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -81,6 +81,21 @@ sub translated_descriptions { } @translated_descriptions ]; } +=head3 GetItemTypes +my $sth = Koha::ItemType->GetItemTypes($dbh); + +This subroutine retreives and returns all itemtype values in the itemtypes table. + +=cut + +sub GetItemTypes { + my ($self, $dbh) = @_; + my $sth = $dbh->prepare('SELECT itemtype FROM itemtypes'); + $sth->execute(); + return $sth; +} + + =head3 type =cut diff --git a/Koha/Libraries.pm b/Koha/Libraries.pm index fa2bf17..1cdbc25 100644 --- a/Koha/Libraries.pm +++ b/Koha/Libraries.pm @@ -52,6 +52,23 @@ sub search_filtered { return $self->SUPER::search( $params, $attributes ); } + +=head3 GetBranchcodes +my $sth = Koha::Libraries->GetBranchCodes($dbh); + +This subroutine retrieves and returns all branchcode values in the branches table to the branch_transfer_limits.pl administrative script. + +=cut + +sub GetBranchCodes { + my ($self, $dbh) = @_; + my $query = qq{ SELECT branchcode FROM branches }; + my $sth = $dbh->prepare($query); + $sth->execute(); + return $sth; +} + + =head3 type =cut diff --git a/admin/branch_transfer_limits.pl b/admin/branch_transfer_limits.pl index 84d7210..64fc6ad 100755 --- a/admin/branch_transfer_limits.pl +++ b/admin/branch_transfer_limits.pl @@ -27,6 +27,7 @@ use C4::Context; use C4::Output; use C4::Koha; use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit }; +use Koha::Libraries; my $input = new CGI; @@ -57,17 +58,19 @@ my @branchcodes; my $sth; if ( $limitType eq 'ccode' ) { - $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"'); + $sth = Koha::AuthorisedValue->GetCatAuthValues($dbh); + while ( my $row = $sth->fetchrow_hashref ) { + push( @codes, $row->{ $limitType } ); + } } elsif ( $limitType eq 'itemtype' ) { - $sth = $dbh->prepare('SELECT itemtype FROM itemtypes'); -} -$sth->execute(); -while ( my $row = $sth->fetchrow_hashref ) { - push( @codes, $row->{ $limitType } ); + $sth = Koha::ItemType->GetItemTypes($dbh); + while ( my $row = $sth->fetchrow_hashref ) { + push( @codes, $row->{ $limitType } ); + } } -$sth = $dbh->prepare("SELECT branchcode FROM branches"); -$sth->execute(); + +my $sth = Koha::Libraries->GetBranchCodes($dbh); while ( my $row = $sth->fetchrow_hashref ) { push( @branchcodes, $row->{'branchcode'} ); } -- 2.1.4