Bug 3229: Fixes sort-by feature for jquery tablesorter in lists.
[koha.git] / C4 / VirtualShelves / Page.pm
index 8e45029..999692c 100644 (file)
@@ -170,6 +170,15 @@ SWITCH: {
         #check that the user can view the shelf
                if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
                        my $items;
+                       my $authorsort;
+                       my $copyrightsort;
+                       my $sortfield = ($query->param('sortfield') ? $query->param('sortfield') : 'title');
+                       if ($sortfield eq 'author') {
+                               $authorsort = 'author';
+                       }
+                       if ($sortfield eq 'copyrightdate'){
+                               $copyrightsort = 'copyrightdate';
+                       }
                        ($items, $totitems) = GetShelfContents($shelfnumber, $shelflimit, $shelfoffset);
                        for my $this_item (@$items) {
                                # the virtualshelfcontents table does not store these columns nor are they retrieved from the items
@@ -177,18 +186,19 @@ SWITCH: {
                                #$this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype}  }->{'imageurl'};
                                #$this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'};
                                $this_item->{'dateadded'} = format_date($this_item->{'dateadded'});
+                $this_item->{'imageurl'} = getitemtypeinfo($this_item->{'itemtype'})->{'imageurl'};
+                $this_item->{'coins'} = GetCOinSBiblio($this_item->{'biblionumber'});
                        }
                        push @paramsloop, {display => 'privateshelves'} if $category == 1;
                        $showadd = 1;
                        my $i = 0;
-                       foreach (grep {$i++ % 2} @$items) {     # every other item
-                               $_->{toggle} = 1;
-                       }
                        my $manageshelf = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
                        $template->param(
                                shelfname   => $shelflist->{$shelfnumber}->{'shelfname'} || $privshelflist->{$shelfnumber}->{'shelfname'},
                                shelfnumber => $shelfnumber,
                                viewshelf   => $shelfnumber,
+                               authorsort   => $authorsort,
+                               copyrightsort => $copyrightsort,
                                manageshelf => $manageshelf,
                                itemsloop => $items,
                        );
@@ -284,16 +294,18 @@ foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflis
        $shelflist->{$element}->{ownername} = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
        $numberCanManage++ if $canmanage;       # possibly outmoded
        if ($shelflist->{$element}->{'category'} eq '1') {
-               (scalar(@shelveslooppriv) % 2) and $shelflist->{$element}->{toggle} = 1;
                push (@shelveslooppriv, $shelflist->{$element});
        } else {
-               (scalar(@shelvesloop)     % 2) and $shelflist->{$element}->{toggle} = 1;
                push (@shelvesloop, $shelflist->{$element});
        }
 }
+
 my $url = $type eq 'opac' ? "/cgi-bin/koha/opac-shelves.pl" : "/cgi-bin/koha/virtualshelves/shelves.pl";
-$url .= "?display=" . $query->param('display') if $query->param('display');
-$url .= "?viewshelf=" . $query->param('viewshelf') if $query->param('viewshelf');
+my %qhash = ();
+foreach (qw(display viewshelf sortfield)) {
+    $qhash{$_} = $query->param($_) if $query->param($_);
+}
+(scalar keys %qhash) and $url .= '?' . join '&', map {"$_=$qhash{$_}"} keys %qhash;
 if ($query->param('viewshelf')) {
        $template->param( {pagination_bar => pagination_bar($url, (int($totitems/$shelflimit)) + (($totitems % $shelflimit) > 0 ? 1 : 0), $itemoff, "itemoff")} );
 } else {
@@ -311,7 +323,7 @@ if ($template->param('viewshelf') or
        $template->param(  'edit'   ) ) {
        $template->param(vseflag => 1);
 }
-if ($template->param( 'shelves' ) or
+if ($template->param( 'shelves' ) or    # note: this part looks duplicative, but is intentional
        $template->param(  'edit'   ) ) {
        $template->param( seflag => 1);
 }