@@ -, +, @@ branch_transfer_limits.pl script into the Koha::AuthorisedValue, Koha::Libraries, Koha::ItemType 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(-) --- a/Koha/AuthorisedValue.pm +++ a/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 --- a/Koha/ItemType.pm +++ a/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 --- a/Koha/Libraries.pm +++ a/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 --- a/admin/branch_transfer_limits.pl +++ a/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'} ); } --