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 <roman.dolny@jezuici.pl>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Baptiste Wojtkowski 2024-07-31 14:47:28 +02:00 committed by Katrin Fischer
parent ab3e951c9c
commit 7d65987a4a
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 12 additions and 2 deletions

View file

@ -462,6 +462,8 @@
[% END %]
[% IF shelf.sortfield == "copyrightdate" %]
<option value="copyrightdate" selected="selected">Copyrightdate</option>
[% ELSIF shelf.sortfield == "publicationyear" %]
<option value="publicationyear" selected="selected">Publication year</option>
[% ELSE %]
<option value="copyrightdate">Copyrightdate</option>
[% END %]

View file

@ -123,7 +123,11 @@ 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);
@ -291,7 +295,11 @@ if ( $op eq 'view' ) {
|| $shelf->sortfield
|| 'title'; # Passed in sorting overrides default sorting
$sortfield = 'title'
unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded );
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;