From 9fd85b17eeefee6432a3eeb84491d0afffd88434 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 28 Feb 2024 05:28:57 +0000 Subject: [PATCH] Bug 36188: Sort lists by items.dateaccessioned in the OPAC When a list is sorted by dateaccessioned it should be ordered descending by default. This is to ensure the newest items are displayed first. Test plan: 1. Apply patches and restart services 2. In the Staff client, go to the Lists module and create a new list 3. Set the 'Sort this list by' dropdown = 'Date accessioned' 4. Add several barcodes to the list belonging to items with a range of different items.dateaccessioned dates 5. In the staff client observe the list records are ordered by the 'Date accessioned' in descending order - i.e. titles with newest dateaccessioned are displayed first 6. In a new browser window navigate to the list in the Koha OPAC 7. Confirm the list titles in the OPAC are ordered in the same order as the staff client 8. In the OPAC click on the 'Sort' button and select 'Date accession (oldest to newest) 9. Confirm the OPAC list order reverses 10. In the OPAC choose other values from the 'Sort' button and confirm the list is re-sorted correctly Sponsored-By: The Treasury, New Zealand --- .../bootstrap/en/modules/opac-shelves.tt | 18 ++++++++++++++++++ opac/opac-shelves.pl | 12 +++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index 78c3c1de658..52545872b5e 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -337,6 +337,19 @@ [% END %] + + [% IF sortfield == "dateaccessioned" && direction == 'asc' %] + + [% ELSE %] + + [% END %] + [% IF sortfield == "dateaccessioned" && direction == 'desc' %] + + + [% ELSE %] + + [% END %] + @@ -621,6 +634,11 @@ [% ELSE %] [% END %] + [% IF shelf.sortfield == "dateaccessioned" %] + + [% ELSE %] + + [% END %] [% IF Koha.Preference('OpacAllowPublicListCreation') OR public == 1 %] diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 5cecfc7b969..b351e6e16bd 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -147,7 +147,7 @@ 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 itemcallnumber dateadded dateaccessioned ); if ( $shelf->can_be_managed( $loggedinuser ) ) { $shelf->shelfname( scalar $query->param('shelfname') ); $shelf->sortfield( $sortfield ); @@ -311,9 +311,15 @@ if ( $op eq 'view' ) { $sortfield = $shelf->sortfield; $direction = 'asc'; } - $direction = $query->param('direction') if $query->param('direction'); + + # By default order descending if sorting by dateaccessioned + if ( $query->param('direction') ) { + $direction = $query->param('direction'); + } elsif ( $sortfield eq 'dateaccessioned' and !$query->param('direction') ) { + $direction = 'desc'; + } $direction = 'asc' if !$direction or ( $direction ne 'asc' and $direction ne 'desc' ); - $sortfield = 'title' if !$sortfield or !grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded ); + $sortfield = 'title' if !$sortfield or !grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded dateaccessioned ); my ( $page, $rows ); unless ( $query->param('print') or $query->param('rss') ) { -- 2.20.1