From 735b0b91d2526a2c069f146b8d1a484d98113e93 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 20 Apr 2023 15:06:25 +0200 Subject: [PATCH] Bug 24975: WIP remove db_t from controllers This is not done yet, for discussion. I don't think we should call db_t in controllers, or we do it better, but now it's confusing. This patch may impact performances, as we are not caching the itemtype object. Ideas? --- C4/Search.pm | 1 + catalogue/moredetail.pl | 10 ++++----- .../prog/en/modules/catalogue/moredetail.tt | 5 +++-- .../bootstrap/en/modules/opac-detail.tt | 22 ++++++++++--------- opac/opac-detail.pl | 14 ++---------- 5 files changed, 23 insertions(+), 29 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 77e3e6e48cd..b75657f72d4 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -539,6 +539,7 @@ sub getRecords { && ref( $itemtypes->{$one_facet} ) eq "HASH" ) { + # FIXME This must call $itemtype->translation_key actually $facet_label_value = db_t('itemtype', $itemtypes->{$one_facet}->{itemtype}); } } diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 20f58eb318f..51b8e98d638 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -139,10 +139,10 @@ my $ccodes = my $copynumbers = { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) }; -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; +my $itemtypes = { map { $_->itemtype => $_ } @{ Koha::ItemTypes->search->as_list } }; + +$data->{itemtype} = $itemtypes->{ $data->{itemtype} }; -$data->{'itemtypename'} = db_t('itemtype', $itemtypes->{ $data->{'itemtype'} }->{itemtype}) - if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} }; foreach ( keys %{$data} ) { $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' ); } @@ -155,8 +155,8 @@ foreach my $item (@items){ my $item_info = $item->unblessed; $item_info->{object} = $item; - $item_info->{itype} = db_t('itemtype', $itemtypes->{ $item_info->{itype} }->{itemtype}) if exists $itemtypes->{ $item_info->{itype} }; - $item_info->{effective_itemtype} = $itemtypes->{$item->effective_itemtype}; + $item_info->{itemtype} = $itemtypes->{$item_info->{itype}}; + $item_info->{effective_itemtype} = $itemtypes->{$item->effective_itemtype}; $item_info->{'ccode'} = $ccodes->{ $item->ccode } if $ccodes && $item->ccode && exists $ccodes->{ $item->ccode }; if ( defined $item->copynumber ) { $item_info->{'displaycopy'} = 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt index b220f58002d..131875851bc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -4,6 +4,7 @@ [% USE Koha %] [% USE Branches %] [% USE Price %] +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Item details for [% INCLUDE 'biblio-title-head.inc' %] › Catalog › Koha @@ -53,7 +54,7 @@
  1. Biblionumber: [% biblionumber | html %] 
  2. [% UNLESS ( item_level_itypes ) %] -
  3. Item type: [% itemtypename | html %] 
  4. +
  5. Item type: [% ItemTypes.t(itemtype.translation_key) | html %] 
  6. [% END %] [% IF ( rentalcharge ) %]
  7. Rental charge:[% rentalcharge | $Price %] 
  8. @@ -125,7 +126,7 @@
    1. Home library: [% Branches.GetName( ITEM_DAT.homebranch ) | html %] 
    2. [% IF ( item_level_itypes ) %] -
    3. Item type: [% ITEM_DAT.itype | html %] 
    4. +
    5. Item type: [% ItemTypes.t(ITEM_DAT.itemtype.translation_key) | html %] 
    6. [% END %] [% IF ( ITEM_DAT.ccode) %]
    7. Collection: [% ITEM_DAT.ccode | html %]
    8. diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index ab2f28e6158..836dd4e2dbc 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -6,6 +6,7 @@ [% USE Branches %] [% USE TablesSettings %] [% USE AuthorisedValues %] +[% USE ItemTypes %] [% SET TagsShowEnabled = ( ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsShowOnDetail ) %] [% SET TagsInputEnabled = ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsInputOnDetail ) %] [% IF Koha.Preference('AmazonAssocTag') %] @@ -167,14 +168,13 @@ [% IF ( !item_level_itypes || Koha.Preference('BiblioItemtypeInfo') ) %] Item type: - [% IF ( imageurl && !Koha.Preference('OpacNoItemTypeImages') ) %] - - [% END %] - [% IF ( description ) %] - [% description | html %] - [% ELSE %] - [% itemtype | html %] + [% IF ( !Koha.Preference('OpacNoItemTypeImages') ) %] + [% SET image_url = itemtype.image_url %] + [% IF image_url %] + + [% END %] [% END %] + [% ItemTypes.t(itemtype.translation_key) | html %] [% END %] @@ -1237,12 +1237,14 @@ [% IF ( item_level_itypes ) %] + [% SET itemtype_description = ItemTypes.t(ITEM_RESULT.itemtype.translation_key) %] [% UNLESS ( Koha.Preference('OpacNoItemTypeImages') ) %] - [% IF ( ITEM_RESULT.imageurl ) %] - [% ITEM_RESULT.description | html %] + [% SET image_url = ITEM_RESULT.itemtype.image_url %] + [% IF image_url %] + [% itemtype_description | html %] [% END %] [% END %] - [% ITEM_RESULT.description | html %] + [% itemtype_description | html %] [% END %] [% IF ( OpacLocationBranchToDisplay == 'holding' || OpacLocationBranchToDisplay == 'both' ) %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 7d7b93685c5..2b20850bbcc 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -508,13 +508,7 @@ my $HideMARC = $record_processor->filters->[0]->should_hide_marc( interface => 'opac', } ); -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; -# imageurl: -my $itemtype = $dat->{'itemtype'}; -if ( $itemtype ) { - $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); - $dat->{'description'} = db_t('itemtype', $itemtypes->{$itemtype}->{itemtype}); -} +$dat->{itemtype} = Koha::ItemTypes->find($dat->{itemtype}); my $shelflocations = { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) }; @@ -705,11 +699,7 @@ else { $shelflocations->{ $item->location }; } - my $itemtype = $item->itemtype; - $item_info->{'imageurl'} = getitemtypeimagelocation( 'opac', - $itemtypes->{ $itemtype->itemtype }->{'imageurl'} ); - $item_info->{'description'} = - db_t('itemtype', $itemtypes->{ $itemtype->itemtype }->{itemtype}); + $item_info->{itemtype} = $item->itemtype; foreach my $field ( qw(ccode materials enumchron copynumber itemnotes location_description uri) -- 2.25.1