Bug 17600: Standardize our EXPORT_OK
[srvgit] / opac / opac-shelves.pl
index 8fe037b..b9eee82 100755 (executable)
 use Modern::Perl;
 
 use CGI qw ( -utf8 );
-use C4::Auth;
-use C4::Biblio;
+use C4::Auth qw( get_template_and_user );
+use C4::Biblio qw( GetBiblioData GetFrameworkCode GetMarcBiblio );
 use C4::External::BakerTaylor qw( image_url link_url );
-use C4::Koha;
-use C4::Items;
+use C4::Koha qw(
+    GetNormalizedEAN
+    GetNormalizedISBN
+    GetNormalizedOCLCNumber
+    GetNormalizedUPC
+);
 use C4::Members;
-use C4::Output;
+use C4::Output qw( pagination_bar output_with_http_headers );
 use C4::Tags qw( get_tags );
 use C4::XSLT;
 
@@ -263,8 +267,8 @@ if ( $op eq 'view' ) {
                 $sortfield = $shelf->sortfield;
                 $direction = 'asc';
             }
-            $sortfield = 'title' unless grep $_ eq $sortfield, qw( title author copyrightdate itemcallnumber dateadded );
-            $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc';
+            $sortfield = 'title' if !$sortfield or !grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded );
+            $direction = 'asc' if !$direction or ( $direction ne 'asc' and $direction ne 'desc' );
             my ( $page, $rows );
             unless ( $query->param('print') or $query->param('rss') ) {
                 $rows = C4::Context->preference('OPACnumSearchResults') || 20;
@@ -274,7 +278,8 @@ if ( $op eq 'view' ) {
             my $contents = $shelf->get_contents->search(
                 {},
                 {
-                    prefetch => [ { 'biblionumber' => { 'biblioitems' => 'items' } } ],
+                    distinct => 'biblionumber',
+                    join     => [ { 'biblionumber' => { 'biblioitems' => 'items' } } ],
                     page     => $page,
                     rows     => $rows,
                     order_by => { "-$direction" => $order_by },
@@ -348,23 +353,18 @@ if ( $op eq 'view' ) {
                     });
                 }
 
-                my @items;
-                my $items = $biblio->items;
+                my $items = $biblio->items->filter_by_visible_in_opac({ patron => $patron });
                 my $allow_onshelf_holds;
-                my @hidden_items;
                 while ( my $item = $items->next ) {
-                    if ( $item->hidden_in_opac({rules => C4::Context->yaml_preference('OpacHiddenItems')} ) ) {
-                        push @hidden_items, $item->itemnumber;
-                        next;
-                    }
 
+                    # This method must take a Koha::Items rs
                     $allow_onshelf_holds ||= Koha::CirculationRules->get_onshelfholds_policy(
                         { item => $item, patron => $patron } );
 
-                    push @items, $item; # This is for non-xslt only
                 }
+
                 $this_item->{allow_onshelf_holds} = $allow_onshelf_holds;
-                $this_item->{'ITEM_RESULTS'} = \@items;
+                $this_item->{'ITEM_RESULTS'} = $items;
 
                 if ($xslfile) {
                     my $variables = {
@@ -373,9 +373,9 @@ if ( $op eq 'view' ) {
                     $this_item->{XSLTBloc} = XSLTParse4Display(
                         $biblionumber,          $record,
                         "OPACXSLTListsDisplay", 1,
-                        \@hidden_items,         $sysxml,
-                        $xslfile,               $lang,
-                        $variables
+                        undef,                 $sysxml,
+                        $xslfile,              $lang,
+                        $variables,            $items->reset
                     );
                 }