From 4e207a9efa0b0a4085ae2b506bc9e79c2a6aac74 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 --- 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 ++----- .../intranet-tmpl/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 | 10 ++++++---- tools/export.pl | 14 +++----------- 45 files changed, 132 insertions(+), 167 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 2188ca4..23dd4cf 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; @@ -2998,12 +2999,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 4270c82..442c301 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; @@ -1866,7 +1867,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 a829402..6454f67 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 85d2542..449a491 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 9ca84e9..9e50484d 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 b8be537..f0dd664 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 ba8b5bf..5ca2e1c 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 1e49d96..7e4974a 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 a31a0c5..c848f60 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -42,6 +42,7 @@ use C4::HTML5Media; use C4::CourseReserves qw(GetItemCourseReservesInfo); use C4::Acquisition qw(GetOrdersByBiblionumber); use Koha::AuthorisedValues; +use Koha::ItemTypes; use Koha::Patrons; use Koha::Virtualshelves; @@ -127,8 +128,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 125b103..26efa03 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 e4e5e66..8488f83 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 54950a5..013c312 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 5d8c0d0..669fa4a 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 ce632e6..8087827 100755 --- a/circ/view_holdsqueue.pl +++ b/circ/view_holdsqueue.pl @@ -29,9 +29,10 @@ use C4::Auth; use C4::Output; use C4::Biblio; use C4::Items; -use C4::Koha; # GetItemTypes use C4::HoldsQueue qw(GetHoldsQueueItems); +use Koha::ItemTypes; + my $query = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -61,16 +62,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 bcfadc7..5be3cb3 100755 --- a/course_reserves/add_items.pl +++ b/course_reserves/add_items.pl @@ -29,6 +29,8 @@ use C4::Biblio; use C4::CourseReserves qw(GetCourse GetCourseItem GetCourseReserve ModCourseItem ModCourseReserve); +use Koha::ItemTypes; + my $cgi = new CGI; my $action = $cgi->param('action') || ''; @@ -64,6 +66,7 @@ if ( $action eq 'lookup' ) { ) : undef; + my $itemtypes = Koha::ItemTypes->search; $template->param( item => $item, course_item => $course_item, @@ -71,7 +74,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 30f7287..4b64802 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 d6d77b5..7365de1 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 7a83df5..aa098c3 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 1ae51ea..ea7c184 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 c6f9661..e02dccd 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 8f19cba..a87a7ff 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt @@ -80,12 +80,8 @@ $(document).ready(function() { diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index 07924c8..3ef8dbf 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 357f2f8..6cb502c 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 a7e643c..d1a9d6a 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -49,6 +49,7 @@ use C4::HTML5Media; use C4::CourseReserves qw(GetItemCourseReservesInfo); use Koha::RecordProcessor; use Koha::AuthorisedValues; +use Koha::ItemTypes; use Koha::Virtualshelves; use Koha::Ratings; use Koha::Reviews; @@ -205,7 +206,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); @@ -537,7 +538,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 a7b67ce..940bd91 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 f1fe2ff..0e59d03 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -33,6 +33,7 @@ use C4::Members; use C4::Overdues; use C4::Debug; use Koha::DateUtils; +use Koha::ItemTypes; use Koha::Libraries; use Koha::Patrons; use Date::Calc qw/Today Date_to_Days/; @@ -90,7 +91,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. @@ -399,14 +400,14 @@ foreach my $biblioNum (@biblionumbers) { $biblioLoopIter{mandatorynotes}=0; #FIXME: 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)) { @@ -522,7 +523,7 @@ foreach my $biblioNum (@biblionumbers) { $numCopiesAvailable++; } - $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 4e302d3..9b60b77 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 912c372..c3a7530 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 04a94c0..d4bdcec 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::Messages; use Koha::Patron::Discharge; use Koha::Patrons; @@ -174,7 +175,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 a4f2e24..ac86289 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 cd2964b..d4d4dbe 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 08b1852..958a72e 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 73595f4..0c53a79 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 be516c1..dcd2889 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 4274f16..c353680 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 4241393..f7f5662 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 3f4dba3..b8c751d 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -44,6 +44,7 @@ use C4::Members; use C4::Search; # enabled_staff_search_views use Koha::DateUtils; use Koha::Holds; +use Koha::ItemTypes; use Koha::Libraries; use Koha::Patrons; @@ -63,7 +64,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 f66b650..ce7f168 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 8e44603..35159e6 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 91ab741..d993cca 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 75a55c6..0c1bc8e 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 2920da9..e1b0135 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -34,7 +34,9 @@ use C4::Debug; use C4::Members; use MARC::File::XML; use List::MoreUtils qw/uniq/; + use Koha::DateUtils; +use Koha::ItemTypes; my $input = new CGI; my $dbh = C4::Context->dbh; @@ -359,10 +361,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 b1ce09c..e383926 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; @@ -259,15 +259,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'] } ); @@ -298,7 +290,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.1.4