From 6f9d5f347f46e23f0b1b1081ab7bd140aa0fe7f7 Mon Sep 17 00:00:00 2001 From: Chloe Zermatten Date: Mon, 16 Dec 2024 11:04:59 +0000 Subject: [PATCH] Bug 38712: order My Lists options alphabetically In the top header navigation menu, sets the order of the 'My Lists' dropdown to be alphabetical. Note: this patch was updated to also handle cases where $params->{search_attributes} is not defined, and well as ordering public lists when the user is not logged in. Test plan: - on the Koha OPAC, navigate to /cgi-bin/koha/opac-shelves.pl - create a few public and private lists - open the 'My List' dropdown in the top navigation menu - notice that the lists appear in the order they were created - apply the patch - open the 'My List' dropdown in the top navigation - notice that the lists are now sorted alphabetically fix: handle undefined search attributes order list when logged out --- C4/Auth.pm | 4 ++++ Koha/Virtualshelves.pm | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 0ee06104a4..c7f645815c 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -333,11 +333,13 @@ sub get_template_and_user { { borrowernumber => $borrowernumber, public => 0, + search_attributes => {order_by => { -asc => 'shelfname' }}, } ); my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( { public => 1, + search_attributes => {order_by => { -asc => 'shelfname' }}, } ); $template->param( @@ -420,6 +422,7 @@ sub get_template_and_user { my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( { public => 1, + search_attributes => {order_by => { -asc => 'shelfname' }}, } ); $template->param( @@ -1481,6 +1484,7 @@ sub checkauth { my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( { public => 1, + search_attributes => {order_by => { -asc => 'shelfname' }}, } ); $template->param( diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 58653130a4..b6c43b692b 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -191,16 +191,20 @@ sub get_some_shelves { }; } + my $default_search_attributes = { + join => [ 'virtualshelfshares' ], + distinct => 'shelfnumber', + order_by => { -desc => 'lastmodified' }, + }; + + my %search_attributes = defined($params->{search_attributes}) ? (%{$default_search_attributes}, %{$params->{search_attributes}}) : %{$default_search_attributes}; + $self->search( { public => $public, ( @conditions ? ( -and => \@conditions ) : () ), }, - { - join => [ 'virtualshelfshares' ], - distinct => 'shelfnumber', - order_by => { -desc => 'lastmodified' }, - } + \%search_attributes ); } -- 2.39.2