From 16d756791ece7325f4541b7f2b7caaee7c9c12c5 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 26 Feb 2020 02:52:24 +0000 Subject: [PATCH] Bug 5103: Format dates in MARC detail using dateformat syspref This patch fixes the formatting of dates on the following pages: - catalogue/MARCdetail.pl (staff) - cataloguing/additem.pl (staff) - opac-MARCdetail.pl (opac) To test: 1) Ensure that the following fields are visible in the opac, intranet and editor. You may need to edit the subfields in your default bibliographic framework 952$d date accessioned 952$q date due/on loan 952$r date last seen 952$s date last borrowed 952$w replacement price date Also ensure you have dateformat system preference set 2) Go to cataloguing/additem.pl for a biblio. Fill in the fields above if required. Save 3) Remain on cataloguing/additem.pl. Notice the items table at the top of the page, the dates are in the generic yyyy-mm-dd format 4) Go to catalogue/MARCdetail.pl for that biblio. Notice dates in wrong format 5) View this biblio in the opac opac-MARCdetail.pl. Scroll to bottom to items table. Notice dates in wrong format. 6) Apply patch, restart memcached and plack and refresh pages 7) Dates should now be formatted according to dateformat preference 8) Confirm that changing the preference changes the format of the dates Sponsored-by: Catalyst IT Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson --- catalogue/MARCdetail.pl | 7 +++++++ cataloguing/additem.pl | 17 +++++++++++++++-- opac/opac-MARCdetail.pl | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl index 8577d1ee48..3f58641f3b 100755 --- a/catalogue/MARCdetail.pl +++ b/catalogue/MARCdetail.pl @@ -61,6 +61,7 @@ use C4::Search; # enabled_staff_search_views use Koha::Biblios; use Koha::BiblioFrameworks; use Koha::Patrons; +use Koha::DateUtils; use List::MoreUtils qw( uniq ); @@ -259,6 +260,7 @@ my %witness my @item_subfield_codes; my @item_loop; my $norequests = 1; + foreach my $field (@fields) { next if ( $field->tag() < 10 ); my @subf = $field->subfields; @@ -286,6 +288,11 @@ foreach my $field (@fields) { } $norequests = 0 if $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.notforloan' and $subf[$i][1] == 0; + + if ( $subf[$i][0] eq 'd' || $subf[$i][0] eq 'q' || $subf[$i][0] eq 'r' || $subf[$i][0] eq 's' || $subf[$i][0] eq 'w' ){ + # date accessioned || on loan || date last seen || date last borrowed || replacement price date + $item->{$subf[$i][0]} = output_pref({ dt => dt_from_string( $item->{$subf[$i][0]} ), dateonly => 1 }); + } } push @item_loop, $item if $item; } diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index babf6d3d4c..70c78b12fd 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -797,7 +797,6 @@ if ( C4::Context->preference('EasyAnalyticalRecords') ) { } } - foreach my $field (@fields) { next if ( $field->tag() < 10 ); @@ -854,7 +853,21 @@ my @item_value_loop; my @header_value_loop; for my $row ( @big_array ) { my %row_data; - my @item_fields = map +{ field => $_ || '' }, @$row{ sort keys(%witness) }; + my @item_fields; + foreach my $key (sort keys %witness){ + my $item_field; + if ( $row->{$key} ){ + $item_field->{field} = $row->{$key}; + } else { + $item_field->{field} = ''; + } + if ( $key eq 'd' || $key eq 'q' || $key eq 'r' || $key eq 's' || $key eq 'w' ){ + # 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 }); + } + + push @item_fields, $item_field; + } $row_data{item_value} = [ @item_fields ]; $row_data{itemnumber} = $row->{itemnumber}; #reporting this_row values diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index cfa9d4e991..51c3651f3d 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -63,6 +63,7 @@ use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; use Koha::RecordProcessor; +use Koha::DateUtils; my $query = CGI->new(); @@ -290,6 +291,7 @@ foreach my $field (@fields) { my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] }; next if ( ($sf_def->{tab}||0) != 10 ); next if ( ($sf_def->{hidden}||0) > 0 ); + push @item_subfield_codes, $subf[$i][0]; $witness{ $subf[$i][0] } = $sf_def->{lib}; @@ -310,6 +312,11 @@ foreach my $field (@fields) { $item->{ $subf[$i][0] } .= GetAuthorisedValueDesc( $field->tag(), $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' ); } + + if ( $subf[$i][0] eq 'd' || $subf[$i][0] eq 'q' || $subf[$i][0] eq 'r' || $subf[$i][0] eq 's' || $subf[$i][0] eq 'w' ){ + # date accessioned || on loan || date last seen || date last borrowed || replacement price date + $item->{$subf[$i][0]} = output_pref({ dt => dt_from_string( $item->{$subf[$i][0]} ), dateonly => 1 });; + } } push @item_loop, $item if $item; } -- 2.39.5