From ff7d8ef653e92b5df83332f142aefea191e682b7 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 28 Sep 2020 17:53:43 +0100 Subject: [PATCH] Bug 24975: Re-introduce translated_description accessor method --- C4/Biblio.pm | 2 +- C4/Items.pm | 2 +- Koha/ItemType.pm | 14 ++++++++++++++ authorities/authorities.pl | 2 +- catalogue/getitem-ajax.pl | 2 +- catalogue/itemsearch.pl | 2 +- cataloguing/addbiblio.pl | 2 +- circ/transferstoreceive.pl | 2 +- opac/opac-search.pl | 2 +- reports/reserves_stats.pl | 2 +- svc/holds | 2 +- 11 files changed, 24 insertions(+), 10 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 2ff808bcad..4fdd7550a2 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1448,7 +1448,7 @@ sub GetAuthorisedValueDesc { #---- itemtypes if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) { my $itemtype = Koha::ItemTypes->find( $value ); - return $itemtype ? db_t('itemtype', $itemtype->itemtype) : q||; + return $itemtype ? $itemtype->translated_description : q||; } if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) { diff --git a/C4/Items.pm b/C4/Items.pm index 389aa9e0d9..e4e4442879 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1723,7 +1723,7 @@ sub PrepareItemrecordDisplay { push @authorised_values, ""; while ( my $itemtype = $itemtypes->next ) { push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = db_t('itemtype', $itemtype->itemtype); + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } if ($defaultvalues && $defaultvalues->{'itemtype'}) { $defaultvalue = $defaultvalues->{'itemtype'}; diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 9d88c9e004..e0a5fd1535 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -22,6 +22,7 @@ use C4::Koha qw( getitemtypeimagelocation ); use C4::Languages; use Koha::Database; use Koha::CirculationRules; +use Koha::I18N; use base qw(Koha::Object Koha::Object::Limit::Library); @@ -35,6 +36,19 @@ Koha::ItemType - Koha Item type Object class =cut +=head3 translation_description + + my $translated_description = Koha::ItemType->translated_description; + +Returns a localized string for the Koha::ItemType description field. + +=cut + +sub translated_description { + my ( $self ) = @_; + return dt_t('itemtype', $self->itemtype); +} + =head3 image_location =cut diff --git a/authorities/authorities.pl b/authorities/authorities.pl index e2e428ba29..5184af62a9 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -88,7 +88,7 @@ sub build_authorized_values_list { unless ( $tagslib->{$tag}->{$subfield}->{mandatory} && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) ); push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = db_t('itemtype', $itemtype->itemtype); + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } } else { # "true" authorised value diff --git a/catalogue/getitem-ajax.pl b/catalogue/getitem-ajax.pl index 14667cad57..bd0e8e0d84 100755 --- a/catalogue/getitem-ajax.pl +++ b/catalogue/getitem-ajax.pl @@ -76,7 +76,7 @@ if($itemnumber) { my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); # We should not do that here, but call ->itemtype->description when needed instea - $item_unblessed->{itemtype} = db_t('itemtype', $itemtype->itemtype); + $item_unblessed->{itemtype} = $itemtype->translated_description; } my $json_text = to_json( $item_unblessed, { utf8 => 1 } ); diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index ec6a6b0b48..271a9f813b 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -282,7 +282,7 @@ my @itemtypes; foreach my $itemtype ( Koha::ItemTypes->search->as_list ) { push @itemtypes, { value => $itemtype->itemtype, - label => db_t('itemtype', $itemtype->itemtype), + label => $itemtype->translated_description, }; } diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index da9e7f271c..bb603e5328 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -196,7 +196,7 @@ sub build_authorized_values_list { my $itemtypes = Koha::ItemTypes->search; while ( $itemtype = $itemtypes->next ) { push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = db_t('itemtype', $itemtype->itemtype); + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } $value = $itemtype unless ($value); } diff --git a/circ/transferstoreceive.pl b/circ/transferstoreceive.pl index 7e902c8f94..7be6d54db6 100755 --- a/circ/transferstoreceive.pl +++ b/circ/transferstoreceive.pl @@ -88,7 +88,7 @@ while ( my $library = $libraries->next ) { my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); $getransf{'datetransfer'} = $num->{'datesent'}; - $getransf{'itemtype'} = db_t('itemtype', $itemtype->itemtype); + $getransf{'itemtype'} = $itemtype->translated_description; %getransf = ( %getransf, title => $biblio->title, diff --git a/opac/opac-search.pl b/opac/opac-search.pl index cdb2666580..5e16ba87b1 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -231,7 +231,7 @@ foreach my $itemtype ( keys %{$itemtypes} ) { # If 'iscat' (see ITEMTYPECAT) then there is no itemtype and the description is not translated my $description = $itemtypes->{$itemtype}->{iscat} ? $itemtypes->{$itemtype}->{description} - : db_t('itemtype', Koha::ItemTypes->find($itemtype)->itemtype); + : Koha::ItemTypes->find($itemtype)->translated_description; $itemtypes->{$itemtype}->{description} = $description || $itemtypes->{$itemtype}->{description} || q{}; } diff --git a/reports/reserves_stats.pl b/reports/reserves_stats.pl index 805113ad2c..fb22460239 100755 --- a/reports/reserves_stats.pl +++ b/reports/reserves_stats.pl @@ -309,7 +309,7 @@ sub display_value { my $display_value = ( $crit =~ /ccode/ ) ? $ccodes->{$value} : ( $crit =~ /location/ ) ? $locations->{$value} - : ( $crit =~ /itemtype/ ) ? db_t('itemtype', Koha::ItemTypes->find( $value )->itemtype) + : ( $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/svc/holds b/svc/holds index f537154495..e7df6ec957 100755 --- a/svc/holds +++ b/svc/holds @@ -82,7 +82,7 @@ while ( my $h = $holds_rs->next() ) { my $itemtype_limit; if ( $h->itemtype ) { my $itemtype = Koha::ItemTypes->find( $h->itemtype ); - $itemtype_limit = db_t('itemtype', $itemtype->itemtype); + $itemtype_limit = $itemtype->translated_description; } my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed; -- 2.20.1