From 9bd0d2ed56d78d3a4fbb95addaa7a81f6ba4cdcf Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 1 Feb 2017 17:01:37 +1300 Subject: [PATCH] Bug 17944 - Moved the DBIx code into the ItemType.pm file Created get_items_and_biblioitems in Koha::ItemType using DBIx coding style. Changed itemtypes.pl to use that method This addresses comment #15. Signed-off-by: Mark Tompsett --- Koha/ItemType.pm | 14 ++++++++++++++ admin/itemtypes.pl | 9 ++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 8f2279b..94a1200 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -89,6 +89,20 @@ sub translated_descriptions { } @translated_descriptions ]; } + +=head3 get_items_and_biblioitems + +=cut + +sub get_items_and_biblioitems { + my $itemtype_code = $_[1]; + my $schema = Koha::Database->new()->schema(); + my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code})->count; + my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code})->count; + my $overalltotal = $itemtotal + $bibliototal; + return $overalltotal; +} + =head3 type =cut diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index e926418..f72c314 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -31,8 +31,8 @@ use C4::Koha; use C4::Context; use C4::Auth; use C4::Output; - use Koha::ItemTypes; +use Koha::ItemType; use Koha::Localizations; my $input = new CGI; @@ -140,12 +140,7 @@ if ( $op eq 'add_form' ) { } elsif ( $op eq 'delete_confirm' ) { - my $schema = Koha::Database->new()->schema(); - my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code})->count; - my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code})->count; - - my $overalltotal = $itemtotal + $bibliototal; - + my $overalltotal = Koha::ItemType->get_items_and_biblioitems($itemtype_code); if ($overalltotal) { push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal }; $op = 'list'; -- 2.1.4