Bug 5103: Refactor the code to avoid repetition

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
(cherry picked from commit 572c3afef1)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2020-03-12 15:09:02 +01:00 committed by Lucas Gass
parent b66e890f84
commit 5d52c0076f
3 changed files with 16 additions and 24 deletions

View File

@ -289,14 +289,10 @@ foreach my $field (@fields) {
$norequests = 0 if $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.notforloan' and $subf[$i][1] == 0;
if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.dateaccessioned' ||
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.onloan' ||
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.datelastseen' ||
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.datelastborrowed' ||
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.replacementpricedate'
){
$item->{$subf[$i][0]} = output_pref({ dt => dt_from_string( $item->{$subf[$i][0]} ), dateonly => 1 });
}
my $kohafield = $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield};
$item->{ $subf[$i][0] } = output_pref( { str => $item->{ $subf[$i][0] }, dateonly => 1 } )
if grep { $kohafield eq $_ }
qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate );
}
push @item_loop, $item if $item;
}

View File

@ -858,14 +858,13 @@ for my $row ( @big_array ) {
$item_field->{field} = '';
}
my ($tmpa, $dateaccessioned) = &GetMarcFromKohaField( "items.dateaccessioned" );
my ($tmpb, $onloan) = &GetMarcFromKohaField( "items.onloan" );
my ($tmpc, $datelastseen) = &GetMarcFromKohaField( "items.datelastseen" );
my ($tmpd, $datelastborrowed) = &GetMarcFromKohaField( "items.datelastborrowed" );
my ($tmpe, $replacementpricedate) = &GetMarcFromKohaField( "items.replacementpricedate" );
if ( $key eq $dateaccessioned || $key eq $onloan || $key eq $datelastseen || $key eq $datelastborrowed || $key eq $replacementpricedate ){
# date accessioned || on loan || date last seen || date last borrowed || replacement price date
$item_field->{field} = output_pref({ dt => dt_from_string( $row->{$key} ), dateonly => 1 });
for my $kohafield (
qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate )
)
{
my ( undef, $subfield ) = GetMarcFromKohaField($kohafield);
next unless $key eq $subfield;
$item_field->{field} = output_pref( { str => $row->{$key}, dateonly => 1 } );
}
push @item_fields, $item_field;

View File

@ -313,14 +313,11 @@ foreach my $field (@fields) {
$subf[$i][1], '', $tagslib, '', 'opac' );
}
if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.dateaccessioned' ||
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.onloan' ||
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.datelastseen' ||
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.datelastborrowed' ||
$tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.replacementpricedate'
){
$item->{$subf[$i][0]} = output_pref({ dt => dt_from_string( $item->{$subf[$i][0]} ), dateonly => 1 });;
}
my $kohafield = $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield};
$item->{ $subf[$i][0] } = output_pref( { str => $item->{ $subf[$i][0] }, dateonly => 1 } )
if grep { $kohafield eq $_ }
qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate );
}
push @item_loop, $item if $item;
}