Bug 15760: Fix order by direction for shelves
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 11 Feb 2016 11:32:43 +0000 (11:32 +0000)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Thu, 11 Feb 2016 19:42:31 +0000 (19:42 +0000)
The order_by parameters should not be "$direction $order_by" with
quote_names enabled. The correct syntax is { -$direction => $order_by }

Test plan for Opac + Staff interfces:
Sort list by title or whatever and change the direction

Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
Koha/Virtualshelves.pm
opac/opac-shelves.pl
virtualshelves/shelves.pl

index 34b1003..152d517 100644 (file)
@@ -114,7 +114,7 @@ sub get_some_shelves {
         {
             join => [ 'virtualshelfshares' ],
             group_by => 'shelfnumber',
-            order_by => 'lastmodified desc',
+            order_by => { -desc => 'lastmodified' },
         }
     );
 }
index 2d810cb..76d632a 100755 (executable)
@@ -223,6 +223,7 @@ if ( $op eq 'view' ) {
             $category = $shelf->category;
             my $sortfield = $query->param('sortfield') || $shelf->sortfield;    # Passed in sorting overrides default sorting
             my $direction = $query->param('direction') || 'asc';
+            $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc';
             my ( $page, $rows );
             unless ( $query->param('print') or $query->param('rss') ) {
                 $rows = C4::Context->preference('OPACnumSearchResults') || 20;
@@ -235,7 +236,7 @@ if ( $op eq 'view' ) {
                     prefetch => [ { 'biblionumber' => { 'biblioitems' => 'items' } } ],
                     page     => $page,
                     rows     => $rows,
-                    order_by => "$order_by $direction",
+                    order_by => { "-$direction" => $order_by },
                 }
             );
 
index 3dfa211..74e31e4 100755 (executable)
@@ -195,6 +195,7 @@ if ( $op eq 'view' ) {
         if ( $shelf->can_be_viewed( $loggedinuser ) ) {
             my $sortfield = $query->param('sortfield') || $shelf->sortfield || 'title';    # Passed in sorting overrides default sorting
             my $direction = $query->param('direction') || 'asc';
+            $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc';
             my ( $rows, $page );
             unless ( $query->param('print') ) {
                 $rows = C4::Context->preference('numSearchResults') || 20;
@@ -208,7 +209,7 @@ if ( $op eq 'view' ) {
                     prefetch => [ { 'biblionumber' => { 'biblioitems' => 'items' } } ],
                     page     => $page,
                     rows     => $rows,
-                    order_by => "$order_by $direction",
+                    order_by => { "-$direction" => $order_by },
                 }
             );