From a492bce299283fd146b69f8c93d7cb4d604755ab 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 Signed-off-by: Olivier V --- .../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 9c85e423c8..9e972152f1 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -348,6 +348,19 @@ [% END %] + + [% IF sortfield == "dateaccessioned" && direction == 'asc' %] + + [% ELSE %] + + [% END %] + [% IF sortfield == "dateaccessioned" && direction == 'desc' %] + + + [% ELSE %] + + [% END %] + @@ -606,6 +619,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 728dad57d1..e0833ca066 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -148,7 +148,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 ); @@ -312,9 +312,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 $rows; unless ( $query->param('print') or $query->param('rss') ) { -- 2.34.1