diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index f3da2c7099..8546d0ac1f 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -87,6 +87,9 @@ sub get_private_shelves { my $rows = $params->{rows}; my $borrowernumber = $params->{borrowernumber} || 0; + my $sort_by = $params->{sort_by}; + my $order_by = _prepare_order_by_for_shelves( { sort_by => $sort_by } ); + $self->search( { public => 0, @@ -98,7 +101,7 @@ sub get_private_shelves { { join => ['virtualshelfshares'], distinct => 'shelfnumber', - order_by => 'shelfname', + order_by => $order_by, ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), } ); @@ -113,18 +116,46 @@ sub get_public_shelves { my $page = $params->{page}; my $rows = $params->{rows}; + my $sort_by = $params->{sort_by}; + my $order_by = _prepare_order_by_for_shelves( { sort_by => $sort_by } ); + $self->search( { public => 1, }, { distinct => 'shelfnumber', - order_by => 'shelfname', + order_by => $order_by, ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), } ); } +=head3 _prepare_order_by_for_shelves + +Create an "order_by" statement when sorting lists of lists + +=cut + +sub _prepare_order_by_for_shelves { + my ($args) = @_; + my $sort_by = $args->{sort_by}; + my $order_by_dir = '-asc'; + my $order_by_col = 'shelfname'; + if ($sort_by) { + my $sortfield = $sort_by->{sortfield}; + my $direction = $sort_by->{direction}; + if ( $direction eq 'asc' || $direction eq 'desc' ) { + $order_by_dir = '-' . $direction; + } + if ( $sortfield eq 'shelfname' || $sortfield eq 'lastmodified' ) { + $order_by_col = $sortfield; + } + } + my $order_by = { $order_by_dir => $order_by_col }; + return $order_by; +} + =head3 get_some_shelves =cut 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 875a88da23..60e609a856 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -751,11 +751,10 @@
[% END %] + [% SET show_new_list = 0 %] [% IF !public || Koha.Preference('OpacAllowPublicListCreation') %] [% IF loggedinusername %] -
New list
+ [% show_new_list = 1 %] [% ELSE %] [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
Log in to create a new list
@@ -764,6 +763,25 @@ [% END %] [% IF shelves.count %] +
+ [% IF ( show_new_list ) %] + New list | + [% END %] + +
[% IF !public %] diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 77f7ffb034..1f999d827c 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -518,13 +518,17 @@ if ( $op eq 'view' ) { push @messages, { type => 'error', code => 'does_not_exist' }; } } elsif ( $op eq 'list' ) { + my $direction = $query->param('direction') || 'asc'; + my $sortfield = $query->param('sortfield') || 'shelfname'; + my $sort_by = { sortfield => $sortfield, direction => $direction }; + my $shelves; my ($rows) = (20); if ( !$public ) { $shelves = Koha::Virtualshelves->get_private_shelves( - { page => $page, rows => $rows, borrowernumber => $loggedinuser, } ); + { page => $page, rows => $rows, borrowernumber => $loggedinuser, sort_by => $sort_by, } ); } else { - $shelves = Koha::Virtualshelves->get_public_shelves( { page => $page, rows => $rows, } ); + $shelves = Koha::Virtualshelves->get_public_shelves( { page => $page, rows => $rows, sort_by => $sort_by, } ); } my $pager = $shelves->pager; @@ -532,7 +536,11 @@ if ( $op eq 'view' ) { shelves => $shelves, pagination_bar => pagination_bar( q||, $pager->last_page - $pager->first_page + 1, - $page, "page", { op => 'list', public => $public, } + $page, "page", + { + op => 'list', public => $public, sortfield => $sortfield, + direction => $direction, + } ), ); }
Your lists