From 8d5b4306e07a594cd102fcce85f912ab3a5661e9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 3 Jan 2017 11:05:15 +0100 Subject: [PATCH] Bug 17835: Replace GetItemTypes with Koha::ItemTypes Signed-off-by: Josef Moravec Signed-off-by: Lari Taskula Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- C4/Items.pm | 9 +++++---- C4/Search.pm | 4 +++- C4/XSLT.pm | 3 ++- Koha/Template/Plugin/ItemTypes.pm | 5 ++--- acqui/basketgroup.pl | 4 ++-- acqui/orderreceive.pl | 1 - admin/smart-rules.pl | 5 ++--- authorities/authorities.pl | 9 +++++---- catalogue/detail.pl | 5 +++-- catalogue/moredetail.pl | 3 ++- catalogue/search.pl | 7 ++++--- cataloguing/addbiblio.pl | 9 +++++---- cataloguing/additem.pl | 9 +++++---- circ/view_holdsqueue.pl | 13 +++++++------ course_reserves/add_items.pl | 5 ++++- .../prog/en/modules/reports/bor_issues_top.tt | 4 ++-- .../prog/en/modules/reports/cat_issues_top.tt | 4 ++-- .../prog/en/modules/reports/catalogue_out.tt | 4 ++-- .../prog/en/modules/reports/issues_stats.tt | 4 ++-- .../prog/en/modules/reports/itemslost.tt | 7 ++----- .../prog/en/modules/tools/export.tt | 8 ++------ labels/label-item-search.pl | 13 ++++++++----- opac/opac-ISBDdetail.pl | 3 ++- opac/opac-detail.pl | 5 +++-- opac/opac-readingrecord.pl | 4 +++- opac/opac-reserve.pl | 13 +++++++------ opac/opac-search.pl | 2 -- opac/opac-topissues.pl | 2 -- opac/opac-user.pl | 3 ++- reports/acquisitions_stats.pl | 6 +++--- reports/bor_issues_top.pl | 14 +++----------- reports/cat_issues_top.pl | 12 +++--------- reports/catalogue_out.pl | 19 ++----------------- reports/catalogue_stats.pl | 3 ++- reports/issues_avg_stats.pl | 3 ++- reports/issues_stats.pl | 9 +++------ reports/itemslost.pl | 13 ++----------- reports/reserves_stats.pl | 13 ++++--------- reserve/request.pl | 3 ++- serials/subscription-add.pl | 4 +++- serials/subscription-bib-search.pl | 5 ++++- suggestion/suggestion.pl | 1 - svc/bib_profile | 3 ++- tools/batchMod.pl | 9 +++++---- tools/export.pl | 14 +++----------- 45 files changed, 131 insertions(+), 167 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index de27769447..637824927d 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -41,6 +41,7 @@ use Koha::Database; use Koha::Biblioitems; use Koha::Items; +use Koha::ItemTypes; use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::Libraries; @@ -2892,12 +2893,12 @@ sub PrepareItemrecordDisplay { #----- itemtypes } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { - my $itemtypes = GetItemTypes( style => 'array' ); + my $itemtypes = Koha::ItemTypes->search_with_localization; push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); - for my $itemtype ( @$itemtypes ) { - push @authorised_values, $itemtype->{itemtype}; - $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description}; + while ( my $itemtype = $itemtypes->next ) { + push @authorised_values, $itemtype->itemtype; + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } if ($defaultvalues && $defaultvalues->{'itemtype'}) { $defaultvalue = $defaultvalues->{'itemtype'}; diff --git a/C4/Search.pm b/C4/Search.pm index 780e2140f4..37dfb2cd6c 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -31,6 +31,7 @@ use C4::Reserves; # GetReserveStatus use C4::Debug; use C4::Charset; use Koha::AuthorisedValues; +use Koha::ItemTypes; use Koha::Libraries; use Koha::Patrons; use YAML; @@ -1867,7 +1868,8 @@ sub searchResults { my $notforloan_authorised_value = $av->count ? $av->next->authorised_value : undef; #Get itemtype hash - my %itemtypes = %{ GetItemTypes() }; + my $itemtypes = Koha::ItemTypes->search_with_localization; + my %itemtypes = map { $_->{itemtype} => $_ } @{ $itemtypes->unblessed }; #search item field code my ($itemtag, undef) = &GetMarcFromKohaField( "items.itemnumber", "" ); diff --git a/C4/XSLT.pm b/C4/XSLT.pm index b757f8ff8b..8813da0ac7 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -30,6 +30,7 @@ use C4::Biblio; use C4::Circulation; use C4::Reserves; use Koha::AuthorisedValues; +use Koha::ItemTypes; use Koha::XSLT_Handler; use Koha::Libraries; @@ -280,7 +281,7 @@ sub buildKohaItemsNamespace { my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' }); - my $itemtypes = GetItemTypes(); + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; my $location = ""; my $ccode = ""; my $xml = ''; diff --git a/Koha/Template/Plugin/ItemTypes.pm b/Koha/Template/Plugin/ItemTypes.pm index 85d2542f0f..449a491669 100644 --- a/Koha/Template/Plugin/ItemTypes.pm +++ b/Koha/Template/Plugin/ItemTypes.pm @@ -23,6 +23,7 @@ use Template::Plugin; use base qw( Template::Plugin ); use C4::Koha; +use Koha::ItemTypes; sub GetDescription { my ( $self, $itemtype ) = @_; @@ -33,9 +34,7 @@ sub GetDescription { } sub Get { - my @itemtypes = @{ GetItemTypes(style => 'array') }; - @itemtypes = sort { $a->{description} cmp $b->{description} } @itemtypes; - return \@itemtypes; + return Koha::ItemTypes->search_with_localization->unblessed; } 1; diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 9ca84e9a35..9e50484de7 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -56,6 +56,7 @@ use C4::Members qw/GetMember/; use Koha::EDI qw/create_edi_order get_edifact_ean/; use Koha::Acquisition::Booksellers; +use Koha::ItemTypes; our $input=new CGI; @@ -174,7 +175,6 @@ sub printbasketgrouppdf{ $ord->{total_tax_excluded} = $ord->{ecost_tax_excluded} * $ord->{quantity}; my $bib = GetBiblioData($ord->{biblionumber}); - my $itemtypes = GetItemTypes(); #FIXME DELETE ME # 0 1 2 3 4 5 6 7 8 9 @@ -195,7 +195,7 @@ sub printbasketgrouppdf{ } } - $ord->{itemtype} = ( $ord->{itemtype} and $bib->{itemtype} ) ? $itemtypes->{$bib->{itemtype}}->{description} : undef; + $ord->{itemtype} = ( $ord->{itemtype} and $bib->{itemtype} ) ? Koha::ItemTypes->find( $bib->{itemtype} )->description : undef; $ord->{en} = $en ? $en : undef; $ord->{edition} = $edition ? $edition : undef; diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index b8be5372e5..f0dd664917 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -63,7 +63,6 @@ use warnings; use CGI qw ( -utf8 ); use C4::Context; -use C4::Koha; # GetItemTypes use C4::Acquisition; use C4::Auth; use C4::Output; diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index ba8b5bf08b..5ca2e1c63e 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -468,8 +468,7 @@ $template->param( my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] }); my @row_loop; -my @itemtypes = @{ GetItemTypes( style => 'array' ) }; -@itemtypes = sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @itemtypes; +my $itemtypes = Koha::ItemTypes->search_with_localization; my $sth2 = $dbh->prepare(" SELECT issuingrules.*, @@ -616,7 +615,7 @@ $template->param(default_rules => ($defaults ? 1 : 0)); $template->param( patron_categories => $patron_categories, - itemtypeloop => \@itemtypes, + itemtypeloop => $itemtypes, rules => \@sorted_row_loop, humanbranch => ($branch ne '*' ? $branch : ''), current_branch => $branch, diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 21103e0728..e45f5dd902 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -32,6 +32,7 @@ use MARC::File::USMARC; use MARC::File::XML; use C4::Biblio; use Koha::Authority::Types; +use Koha::ItemTypes; use vars qw( $tagslib); use vars qw( $authorised_values_sth); use vars qw( $is_a_modif ); @@ -91,10 +92,10 @@ sub build_authorized_values_list { && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) ); my $itemtype; - my $itemtypes = GetItemTypes( style => 'array' ); - for my $itemtype ( @$itemtypes ) { - push @authorised_values, $itemtype->{itemtype}; - $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description}; + my $itemtypes = Koha::ItemTypes->search_with_localization; + while ( $itemtype = $itemtypes->next ) { + push @authorised_values, $itemtype->itemtype; + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } $value = $itemtype unless ($value); diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 63ba1ad3ad..3a632b6049 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -44,6 +44,7 @@ use C4::Acquisition qw(GetOrdersByBiblionumber); use Koha::AuthorisedValues; use Koha::Biblios; use Koha::Items; +use Koha::ItemTypes; use Koha::Patrons; use Koha::Virtualshelves; @@ -129,8 +130,8 @@ my $marcurlsarray = GetMarcUrls ($record,$marcflavour); my $marchostsarray = GetMarcHosts($record,$marcflavour); my $subtitle = GetRecordValue('subtitle', $record, $fw); -# Get Branches, Itemtypes and Locations -my $itemtypes = GetItemTypes(); +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; + my $dbh = C4::Context->dbh; my @all_items = GetItemsInfo( $biblionumber ); diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index b63c53249c..04a0e9d43f 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -124,7 +124,8 @@ my $ccodes = { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) }; my $copynumbers = { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) }; -my $itemtypes = GetItemTypes; + +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'}; $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} ); diff --git a/catalogue/search.pl b/catalogue/search.pl index e4e5e66b25..8488f832a0 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -151,6 +151,7 @@ use URI::Escape; use POSIX qw(ceil floor); use C4::Search::History; +use Koha::ItemTypes; use Koha::LibraryCategories; use Koha::Virtualshelves; use Koha::SearchEngine::Search; @@ -221,7 +222,7 @@ $template->param( ); # load the Type stuff -my $itemtypes = GetItemTypes; +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; # the index parameter is different for item-level itemtypes my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; my @advancedsearchesloop; @@ -515,7 +516,7 @@ my $facets; # this object stores the faceted results that display on the left-ha my $results_hashref; eval { - my $itemtypes = GetItemTypes; + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; ( $error, $results_hashref, $facets ) = $searcher->search_compat( $query, $simple_query, \@sort_by, \@servers, $results_per_page, $offset, $expanded_facet, undef, @@ -780,7 +781,7 @@ sub prepare_adv_search_types { # the index parameter is different for item-level itemtypes my $itype_or_itemtype = ( C4::Context->preference("item-level_itypes") ) ? 'itype' : 'itemtype'; - my $itemtypes = GetItemTypes; + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; my ( $cnt, @result ); foreach my $advanced_srch_type (@advanced_search_types) { diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 54950a57de..013c312bb2 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -37,6 +37,7 @@ use C4::Charset; use Koha::BiblioFrameworks; use Koha::DateUtils; +use Koha::ItemTypes; use Koha::Libraries; use Koha::BiblioFrameworks; @@ -188,10 +189,10 @@ sub build_authorized_values_list { && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) ); my $itemtype; - my $itemtypes = GetItemTypes( style => 'array' ); - for my $itemtype ( @$itemtypes ) { - push @authorised_values, $itemtype->{itemtype}; - $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description}; + my $itemtypes = Koha::ItemTypes->search_with_localization; + while ( $itemtype = $itemtypes->next ) { + push @authorised_values, $itemtype->itemtype; + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } $value = $itemtype unless ($value); } diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 5d8c0d085c..669fa4a23d 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -31,6 +31,7 @@ use C4::Circulation; use C4::Koha; use C4::ClassSource; use Koha::DateUtils; +use Koha::ItemTypes; use Koha::Libraries; use List::MoreUtils qw/any/; use C4::Search; @@ -182,10 +183,10 @@ sub generate_subfield_form { } elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) { push @authorised_values, "" unless ( $subfieldlib->{mandatory} ); - my $itemtypes = GetItemTypes( style => 'array' ); - for my $itemtype ( @$itemtypes ) { - push @authorised_values, $itemtype->{itemtype}; - $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description}; + my $itemtypes = Koha::ItemTypes->search_with_localization; + while ( my $itemtype = $itemtypes->next ) { + push @authorised_values, $itemtype->itemtype; + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } unless ( $value ) { diff --git a/circ/view_holdsqueue.pl b/circ/view_holdsqueue.pl index 72457e03a3..75b02d5944 100755 --- a/circ/view_holdsqueue.pl +++ b/circ/view_holdsqueue.pl @@ -29,10 +29,11 @@ use C4::Auth; use C4::Output; use C4::Biblio; use C4::Items; -use C4::Koha; # GetItemTypes use C4::HoldsQueue qw(GetHoldsQueueItems); use Koha::BiblioFrameworks; +use Koha::ItemTypes; + my $query = new CGI; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( { @@ -62,16 +63,16 @@ if ( $run_report ) { } # getting all itemtypes -my $itemtypes = &GetItemTypes(); +my $itemtypes = Koha::ItemTypes->search({}, {order_by => 'itemtype'});; my @itemtypesloop; -foreach my $thisitemtype ( sort keys %$itemtypes ) { +while ( my $itemtype = $itemtypes->next ) { push @itemtypesloop, { - value => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{'description'}, + value => $itemtype->itemtype, + description => $itemtypes->description, # FIXME Don't we want the translated_description here? }; } -$template->param( +$template->param( # FIXME Could be improved passing the $itemtypes iterator directly to the template itemtypeloop => \@itemtypesloop, ); diff --git a/course_reserves/add_items.pl b/course_reserves/add_items.pl index fc705e1928..89cbb47eb7 100755 --- a/course_reserves/add_items.pl +++ b/course_reserves/add_items.pl @@ -30,6 +30,8 @@ use Koha::Items; use C4::CourseReserves qw(GetCourse GetCourseItem GetCourseReserve ModCourseItem ModCourseReserve); +use Koha::ItemTypes; + my $cgi = new CGI; my $action = $cgi->param('action') || ''; @@ -68,6 +70,7 @@ if ( $action eq 'lookup' ) { ) : undef; + my $itemtypes = Koha::ItemTypes->search; $template->param( item => $item, title => $title, @@ -76,7 +79,7 @@ if ( $action eq 'lookup' ) { ccodes => GetAuthorisedValues('CCODE'), locations => GetAuthorisedValues('LOC'), - itypes => GetItemTypes( style => 'array' ), + itypes => $itemtypes, # FIXME We certainly want to display the translated_description in the template return => $return, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt index 30f7287c4b..4b64802c45 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt @@ -147,8 +147,8 @@ function Dopop(link) {
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt index d6d77b52da..7365de18e6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt @@ -120,8 +120,8 @@
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_out.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_out.tt index 7a83df516a..aa098c34b3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_out.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_out.tt @@ -97,8 +97,8 @@
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt index 1ae51ea3ff..ea7c18418e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt @@ -167,8 +167,8 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt index c6f9661349..e02dccd579 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt @@ -106,11 +106,8 @@
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt index cfa252cd4a..681bddbbdd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt @@ -89,12 +89,8 @@ $(document).ready(function() { diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index 07924c87d3..3ef8dbff2a 100755 --- a/labels/label-item-search.pl +++ b/labels/label-item-search.pl @@ -31,11 +31,11 @@ use C4::Context; use C4::Search qw(SimpleSearch); use C4::Biblio qw(TransformMarcToKoha); use C4::Items qw(GetItemInfosOf get_itemnumbers_of); -use C4::Koha qw(GetItemTypes); use C4::Creators::Lib qw(html_table); use C4::Debug; use Koha::DateUtils; +use Koha::ItemTypes; use Koha::SearchEngine::Search; BEGIN { @@ -251,12 +251,15 @@ else { debug => 1, } ); - my $itemtypes = GetItemTypes; + my $itemtypes = Koha::ItemTypes->search; my @itemtypeloop; - foreach my $thisitemtype ( keys %$itemtypes ) { + while ( my $itemtype = $itemtypes->next ) { + # FIXME This must be improved: + # - pass the iterator to the template + # - display the translated_description my %row = ( - value => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{'description'}, + value => $itemtype->itemtype, + description => $itemtype->description, ); push @itemtypeloop, \%row; } diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 357f2f851d..6cb502c614 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -53,6 +53,7 @@ use C4::Acquisition; use C4::Serials; # uses getsubscriptionfrom biblionumber use C4::Koha; use C4::Members; # GetMember +use Koha::ItemTypes; use Koha::RecordProcessor; @@ -162,7 +163,7 @@ my $res = GetISBDView({ 'framework' => $framework }); -my $itemtypes = GetItemTypes(); +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); for my $itm (@items) { $norequests = 0 diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 1336ae1905..bb521e2f6f 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -50,6 +50,7 @@ use C4::CourseReserves qw(GetItemCourseReservesInfo); use Koha::RecordProcessor; use Koha::AuthorisedValues; use Koha::Biblios; +use Koha::ItemTypes; use Koha::Virtualshelves; use Koha::Ratings; use Koha::Reviews; @@ -206,7 +207,7 @@ if ($session->param('busc')) { my ($arrParamsBusc, $offset, $results_per_page) = @_; my $expanded_facet = $arrParamsBusc->{'expand'}; - my $itemtypes = GetItemTypes; + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; my @servers; @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'}; @servers = ("biblioserver") unless (@servers); @@ -538,7 +539,7 @@ my $HideMARC = $record_processor->filters->[0]->should_hide_marc( interface => 'opac', } ); -my $itemtypes = GetItemTypes(); +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; # imageurl: my $itemtype = $dat->{'itemtype'}; if ( $itemtype ) { diff --git a/opac/opac-readingrecord.pl b/opac/opac-readingrecord.pl index a7b67cefb4..940bd91c3a 100755 --- a/opac/opac-readingrecord.pl +++ b/opac/opac-readingrecord.pl @@ -32,6 +32,8 @@ use MARC::Record; use C4::Output; use C4::Charset qw(StripNonXmlChars); +use Koha::ItemTypes; + my $query = new CGI; # if opacreadinghistory is disabled, leave immediately @@ -55,7 +57,7 @@ my ( $borr ) = GetMember( borrowernumber => $borrowernumber ); $template->param(%{$borr}); -my $itemtypes = GetItemTypes(); +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; # get the record my $order = $query->param('order') || ''; diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 8b7d388ee3..7de7b978b9 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -35,6 +35,7 @@ use C4::Debug; use Koha::AuthorisedValues; use Koha::DateUtils; use Koha::Items; +use Koha::ItemTypes; use Koha::Libraries; use Koha::Patrons; use Date::Calc qw/Today Date_to_Days/; @@ -100,7 +101,7 @@ if ( $reservefee > 0){ $template->param( RESERVE_CHARGE => sprintf("%.2f",$reservefee)); } -my $itemTypes = GetItemTypes(); +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; # There are two ways of calling this script, with a single biblio num # or multiple biblio nums. @@ -419,14 +420,14 @@ foreach my $biblioNum (@biblionumbers) { $biblioLoopIter{reqholdnotes}=0; #TODO: For future use if (!$itemLevelTypes && $biblioData->{itemtype}) { - $biblioLoopIter{translated_description} = $itemTypes->{$biblioData->{itemtype}}{translated_description}; - $biblioLoopIter{imageurl} = getitemtypeimagesrc() . "/". $itemTypes->{$biblioData->{itemtype}}{imageurl}; + $biblioLoopIter{translated_description} = $itemtypes->{$biblioData->{itemtype}}{translated_description}; + $biblioLoopIter{imageurl} = getitemtypeimagesrc() . "/". $itemtypes->{$biblioData->{itemtype}}{imageurl}; } foreach my $itemInfo (@{$biblioData->{itemInfos}}) { if ($itemLevelTypes && $itemInfo->{itype}) { - $itemInfo->{translated_description} = $itemTypes->{$itemInfo->{itype}}{translated_description}; - $itemInfo->{imageurl} = getitemtypeimagesrc() . "/". $itemTypes->{$itemInfo->{itype}}{imageurl}; + $itemInfo->{translated_description} = $itemtypes->{$itemInfo->{itype}}{translated_description}; + $itemInfo->{imageurl} = getitemtypeimagesrc() . "/". $itemtypes->{$itemInfo->{itype}}{imageurl}; } if (!$itemInfo->{'notforloan'} && !($itemInfo->{'itemnotforloan'} > 0)) { @@ -550,7 +551,7 @@ foreach my $biblioNum (@biblionumbers) { } } - $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} ); + $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itemInfo->{itype} }{imageurl} ); # Show serial enumeration when needed if ($itemLoopIter->{enumchron}) { diff --git a/opac/opac-search.pl b/opac/opac-search.pl index a84e9d3916..e190fcd1a3 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -229,8 +229,6 @@ foreach my $itemtype ( keys %{$itemtypes} ) { $itemtypes->{$itemtype}->{translated_description} = ( $translated_description ) ? $translated_description : $itemtypes->{$itemtype}->{description}; } -# Load the Type stuff without search categories for facets -my $itemtypes_nocategory = GetItemTypes; # the index parameter is different for item-level itemtypes my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; my @advancedsearchesloop; diff --git a/opac/opac-topissues.pl b/opac/opac-topissues.pl index 912c37296a..c3a7530df8 100755 --- a/opac/opac-topissues.pl +++ b/opac/opac-topissues.pl @@ -48,8 +48,6 @@ if ( ! C4::Context->preference('OpacTopissue') ) { exit; } -my $itemtypes = GetItemTypes(); - my ($template, $borrowernumber, $cookie) = get_template_and_user( { template_name => 'opac-topissues.tt', diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 9a041743a5..c7333e2776 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -36,6 +36,7 @@ use C4::Letters; use Koha::DateUtils; use Koha::Holds; use Koha::Database; +use Koha::ItemTypes; use Koha::Patron::Attribute::Types; use Koha::Patron::Messages; use Koha::Patron::Discharge; @@ -175,7 +176,7 @@ my $count = 0; my $overdues_count = 0; my @overdues; my @issuedat; -my $itemtypes = GetItemTypes(); +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; my $issues = GetPendingIssues($borrowernumber); if ($issues){ foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) { diff --git a/reports/acquisitions_stats.pl b/reports/acquisitions_stats.pl index a4f2e242a0..ac86289a1a 100755 --- a/reports/acquisitions_stats.pl +++ b/reports/acquisitions_stats.pl @@ -27,6 +27,7 @@ use C4::Output; use C4::Koha; use C4::Circulation; use C4::Biblio; +use Koha::ItemTypes; use Koha::DateUtils; use Koha::Libraries; @@ -124,8 +125,6 @@ else { $req->execute; my $booksellers = $req->fetchall_arrayref({}); - my $itemtypes = GetItemTypes( style => 'array' ); - $req = $dbh->prepare("SELECT DISTINCTROW budget_code, budget_name FROM aqbudgets ORDER BY budget_name"); $req->execute; my @bselect; @@ -195,9 +194,10 @@ else { $ccode_avlist = GetAuthorisedValues($ccode_subfield_structure->{authorised_value}); } + my $itemtypes = Koha::ItemTypes->search_with_localization; $template->param( booksellers => $booksellers, - itemtypes => $itemtypes, + itemtypes => $itemtypes, # FIXME Should use the TT plugin instead Budgets => $Budgets, hassort1 => $hassort1, hassort2 => $hassort2, diff --git a/reports/bor_issues_top.pl b/reports/bor_issues_top.pl index cd2964b9fd..d4d4dbe8cd 100755 --- a/reports/bor_issues_top.pl +++ b/reports/bor_issues_top.pl @@ -30,6 +30,7 @@ use C4::Reports; use C4::Debug; use Koha::DateUtils; +use Koha::ItemTypes; use Koha::Patron::Categories; =head1 NAME @@ -110,21 +111,12 @@ my @values; my @mime = ( map { {type =>$_} } (split /[;:]/, 'CSV') ); # FIXME translation my $delims = GetDelimiterChoices; -my $itemtypes = GetItemTypes; -my @itemtypeloop; -foreach (sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description}} keys %$itemtypes) { - my %row = (value => $_, - translated_description => $itemtypes->{$_}->{translated_description}, - ); - push @itemtypeloop, \%row; -} - my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); - +my $itemtypes = Koha::ItemTypes->search_with_localization; $template->param( mimeloop => \@mime, CGIseplist => $delims, - itemtypeloop => \@itemtypeloop, + itemtypes => $itemtypes, patron_categories => $patron_categories, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/reports/cat_issues_top.pl b/reports/cat_issues_top.pl index 08b185234d..958a72e059 100755 --- a/reports/cat_issues_top.pl +++ b/reports/cat_issues_top.pl @@ -29,6 +29,7 @@ use C4::Circulation; use C4::Reports; use C4::Members; use Koha::DateUtils; +use Koha::ItemTypes; =head1 NAME @@ -118,14 +119,7 @@ if ($do_it) { my $CGIsepChoice=GetDelimiterChoices; #doctype - my $itemtypes = GetItemTypes; - my @itemtypeloop; - foreach my $thisitemtype ( sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description}} keys %$itemtypes) { - my %row =(value => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{translated_description}, - ); - push @itemtypeloop, \%row; - } + my $itemtypes = Koha::ItemTypes->search_with_localization; #ccode my $ccodes = GetAuthorisedValues('CCODE'); @@ -156,7 +150,7 @@ if ($do_it) { $template->param( CGIextChoice => $CGIextChoice, CGIsepChoice => $CGIsepChoice, - itemtypeloop =>\@itemtypeloop, + itemtypes => $itemtypes, ccodeloop =>\@ccodeloop, shelvinglocloop =>\@shelvinglocloop, patron_categories => $patron_categories, diff --git a/reports/catalogue_out.pl b/reports/catalogue_out.pl index 73595f4b08..0c53a79178 100755 --- a/reports/catalogue_out.pl +++ b/reports/catalogue_out.pl @@ -25,7 +25,6 @@ use C4::Auth; use C4::Context; use C4::Debug; use C4::Output; -use C4::Koha; # GetItemTypes # use Date::Manip; # TODO: add not borrowed since date X criteria use Data::Dumper; @@ -60,23 +59,9 @@ if ($do_it) { exit; # in either case, exit after do_it } -# Displaying choices (i.e., not do_it) -my $itemtypes = GetItemTypes(); -my @itemtypeloop; -foreach ( - sort { $itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description} } - keys %$itemtypes - ) -{ - push @itemtypeloop, - { - value => $_, - description => $itemtypes->{$_}->{translated_description}, - }; -} - +my $itemtypes = Koha::ItemTypes->search_with_localization; $template->param( - itemtypeloop => \@itemtypeloop, + itemtypes => $itemtypes, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/reports/catalogue_stats.pl b/reports/catalogue_stats.pl index be516c189f..dcd28894c0 100755 --- a/reports/catalogue_stats.pl +++ b/reports/catalogue_stats.pl @@ -31,6 +31,7 @@ use C4::Biblio qw/GetMarcSubfieldStructureFromKohaField/; use Koha::AuthorisedValues; use Koha::DateUtils; +use Koha::ItemTypes; =head1 NAME @@ -120,7 +121,7 @@ if ($do_it) { my $req; my @select; - my $itemtypes = GetItemTypes( style => 'array' ); + my $itemtypes = Koha::ItemTypes->search_with_localization; my @authvals = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ); my @locations = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ); diff --git a/reports/issues_avg_stats.pl b/reports/issues_avg_stats.pl index 4274f163a3..c353680736 100755 --- a/reports/issues_avg_stats.pl +++ b/reports/issues_avg_stats.pl @@ -28,6 +28,7 @@ use C4::Koha; use C4::Circulation; use C4::Reports; use Koha::DateUtils; +use Koha::ItemTypes; use Koha::Patron::Categories; use Date::Calc qw(Delta_Days); @@ -119,7 +120,7 @@ if ($do_it) { } else { my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); - my $itemtypes = GetItemTypes( style => 'array' ); + my $itemtypes = Koha::ItemTypes->search_with_localization; my $dbh = C4::Context->dbh; my $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1"); diff --git a/reports/issues_stats.pl b/reports/issues_stats.pl index 42413937a3..f7f5662f4b 100755 --- a/reports/issues_stats.pl +++ b/reports/issues_stats.pl @@ -34,6 +34,7 @@ use C4::Members; use Koha::AuthorisedValues; use Koha::DateUtils; +use Koha::ItemTypes; use C4::Members::AttributeTypes; =head1 NAME @@ -87,7 +88,6 @@ $sep = "\t" if ($sep eq 'tabulation'); $template->param(do_it => $do_it, ); -our $itemtypes = GetItemTypes(); our @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); our $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; @@ -146,10 +146,7 @@ my %labels; my %select; # create itemtype arrayref for . -my @itemtypeloop; -for my $itype ( sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description}} keys(%$itemtypes)) { - push @itemtypeloop, { code => $itype , description => $itemtypes->{$itype}->{translated_description} } ; -} +my $itemtypes = Koha::ItemTypes->search_with_localization; # location list my @locations; @@ -153,7 +149,7 @@ my $CGIsepChoice=GetDelimiterChoices; $template->param( categoryloop => \@patron_categories, - itemtypeloop => \@itemtypeloop, + itemtypes => $itemtypes, locationloop => \@locations, ccodeloop => \@ccodes, hassort1=> $hassort1, @@ -319,13 +315,12 @@ sub display_value { my ( $crit, $value ) = @_; my $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; my $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) }; - my $itemtypes = GetItemTypes(); my $Bsort1 = GetAuthorisedValues("Bsort1"); my $Bsort2 = GetAuthorisedValues("Bsort2"); my $display_value = ( $crit =~ /ccode/ ) ? $ccodes->{$value} : ( $crit =~ /location/ ) ? $locations->{$value} - : ( $crit =~ /itemtype/ ) ? $itemtypes->{$value}->{description} + : ( $crit =~ /itemtype/ ) ? Koha::ItemTypes->find( $value )->translated_description : ( $crit =~ /branch/ ) ? Koha::Libraries->find($value)->branchname : ( $crit =~ /reservestatus/ ) ? reservestatushuman($value) : $value; # default fallback diff --git a/reserve/request.pl b/reserve/request.pl index 89dace65aa..810c904c3b 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -45,6 +45,7 @@ use C4::Search; # enabled_staff_search_views use Koha::DateUtils; use Koha::Holds; use Koha::Items; +use Koha::ItemTypes; use Koha::Libraries; use Koha::Patrons; @@ -64,7 +65,7 @@ my $multihold = $input->param('multi_hold'); $template->param(multi_hold => $multihold); my $showallitems = $input->param('showallitems'); -my $itemtypes = GetItemTypes(); +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; # Select borrowers infos my $findborrower = $input->param('findborrower'); diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index f66b650f89..ce7f168e8b 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -32,6 +32,7 @@ use C4::Serials::Numberpattern; use C4::Letters; use Koha::AdditionalField; use Koha::DateUtils; +use Koha::ItemTypes; use Carp; #use Smart::Comments; @@ -141,8 +142,9 @@ for my $field ( @$additional_fields ) { } $template->param( additional_fields_for_subscription => $additional_fields ); -my $typeloop = GetItemTypes(); +my $typeloop = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +# FIXME We should use the translated_description for item types my @typearg = map { { code => $_, value => $typeloop->{$_}{'description'}, selected => ( ( $subs->{itemtype} and $_ eq $subs->{itemtype} ) ? "selected=\"selected\"" : "" ), } } sort keys %{$typeloop}; my @previoustypearg = diff --git a/serials/subscription-bib-search.pl b/serials/subscription-bib-search.pl index 8e44603e73..35159e6754 100755 --- a/serials/subscription-bib-search.pl +++ b/serials/subscription-bib-search.pl @@ -58,6 +58,7 @@ use C4::Search; use C4::Biblio; use C4::Debug; +use Koha::ItemTypes; use Koha::SearchEngine; use Koha::SearchEngine::Search; @@ -196,8 +197,10 @@ else { ); # load the itemtypes - my $itemtypes = GetItemTypes(); + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; my @itemtypesloop; + # FIXME This is uselessly complex, the iterator should be send to the template + # FIXME The translated_description should be used foreach my $thisitemtype ( sort { $itemtypes->{$a}->{'description'} diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 91ab7419bd..d993ccacf3 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -24,7 +24,6 @@ use CGI qw ( -utf8 ); use C4::Auth; # get_template_and_user use C4::Output; use C4::Suggestions; -use C4::Koha; #GetItemTypes use C4::Budgets; use C4::Search; use C4::Members; diff --git a/svc/bib_profile b/svc/bib_profile index 75a55c6f12..0c1bc8e41b 100755 --- a/svc/bib_profile +++ b/svc/bib_profile @@ -25,6 +25,7 @@ use CGI qw ( -utf8 ); use C4::Auth qw/check_api_auth/; use C4::Context; use C4::Koha; +use Koha::ItemTypes; use XML::Simple; my $query = new CGI; @@ -113,7 +114,7 @@ sub _get_bib_number_tag { sub _get_biblioitem_itemtypes { my $result = shift; - my $itemtypes = GetItemTypes; + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield FROM marc_subfield_structure WHERE frameworkcode = '' diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 7cc3fe9bc2..1dc2174951 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -37,6 +37,7 @@ use List::MoreUtils qw/uniq/; use Koha::Biblios; use Koha::DateUtils; +use Koha::ItemTypes; my $input = new CGI; my $dbh = C4::Context->dbh; @@ -361,10 +362,10 @@ foreach my $tag (sort keys %{$tagslib}) { } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { push @authorised_values, ""; - my $itemtypes = GetItemTypes( style => 'array' ); - for my $itemtype ( @$itemtypes ) { - push @authorised_values, $itemtype->{itemtype}; - $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description}; + my $itemtypes = Koha::ItemTypes->search_with_localization; + while ( my $itemtype = $itemtypes->next ) { + push @authorised_values, $itemtype->itemtype; + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } $value = ""; diff --git a/tools/export.pl b/tools/export.pl index 1ed7b1af4e..0165cf1ea4 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -21,7 +21,6 @@ use CGI qw ( -utf8 ); use MARC::File::XML; use List::MoreUtils qw(uniq); use C4::Auth; -use C4::Koha; # GetItemTypes use C4::Output; use Koha::Authority::Types; @@ -30,6 +29,7 @@ use Koha::CsvProfiles; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Exporter::Record; +use Koha::ItemTypes; use Koha::Libraries; my $query = new CGI; @@ -266,15 +266,7 @@ if ( $op eq "export" ) { else { - my $itemtypes = GetItemTypes; - my @itemtypesloop; - foreach my $thisitemtype ( sort keys %$itemtypes ) { - my %row = ( - value => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{translated_description}, - ); - push @itemtypesloop, \%row; - } + my $itemtypes = Koha::ItemTypes->search_with_localization; my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); @@ -305,7 +297,7 @@ else { $template->param( libraries => $libraries, - itemtypeloop => \@itemtypesloop, + itemtypes => $itemtypes, authority_types => $authority_types, export_remove_fields => C4::Context->preference("ExportRemoveFields"), csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], -- 2.39.5