From 9e45df737731ea8c1f46d4c4f2e93f3790dfe604 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 date acquired (items.dateaccessioned) in the OPAC When a list is sorted by date acquired 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 acquired' 4. Add several barcodes to the list belonging to items with a range of different date acquired dates 5. In the staff client observe the list records are ordered by the 'Date acquired' in descending order - i.e. titles with newest date acquired 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 acquired (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 Signed-off-by: baptiste --- .../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 aab73c6d4c..d5edd230aa 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -339,6 +339,19 @@ [% END %] + + [% IF sortfield == "dateaccessioned" && direction == 'asc' %] + + [% ELSE %] + + [% END %] + [% IF sortfield == "dateaccessioned" && direction == 'desc' %] + + + [% ELSE %] + + [% END %] + @@ -625,6 +638,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 85bfb38c6b..c72b6565d8 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.34.1