From dbfdd9889eefd6b47eee3ad1ffd38a4552aa3343 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Wed, 31 Jul 2024 14:47:28 +0200 Subject: [PATCH] Bug 37434: Sort by publicationyear when copyrightdate is set in UNIMARC TEST PLAN (on an UNIMARC machine): 1 - Create a list with items with different publicationyear if you do not have one. 2 - Edit the list and select "copyrightdate as date" 3 - See they are not sorted by date 4 - Apply patch 5 - See they are now sorted by date. Note: The transformation of copyrightdate before loading the template is only useful if the list is sorted by copyrightdate, which is quite inconsistent but is actual for every Kohas at the moment. Signed-off-by: Roman Dolny --- .../prog/en/modules/virtualshelves/shelves.tt | 2 ++ virtualshelves/shelves.pl | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index 4a0d749579..11ddab3357 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -439,6 +439,8 @@ [% END %] [% IF shelf.sortfield == "copyrightdate" %] + [% ELSIF shelf.sortfield == "publicationyear" %] + [% ELSE %] [% END %] diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index e3e7a868e4..b644fd60cd 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -120,7 +120,10 @@ if ( $op eq 'add_form' ) { if ( $shelf ) { $op = $referer; my $sortfield = $query->param('sortfield'); - $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded ); + $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate publicationyear itemcallnumber dateadded ); + if ($sortfield == 'copyrightdate' and C4::Context->preference('marcflavour')=='UNIMARC'){ + $sortfield = 'publicationyear'; + } if ( $shelf->can_be_managed( $loggedinuser ) ) { $shelf->shelfname( scalar $query->param('shelfname') ); $shelf->sortfield( $sortfield ); @@ -278,7 +281,10 @@ if ( $op eq 'view' ) { if ( $shelf ) { if ( $shelf->can_be_viewed( $loggedinuser ) ) { my $sortfield = $query->param('sortfield') || $shelf->sortfield || 'title'; # Passed in sorting overrides default sorting - $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded ); + $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate publicationyear itemcallnumber dateadded ); + if ($sortfield == 'copyrightdate' and C4::Context->preference('marcflavour')=='UNIMARC'){ + $sortfield = 'publicationyear'; + } my $direction = $query->param('direction') || 'asc'; $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc'; my $rows; -- 2.39.2