Bug 28519: Add lib to koha-shell
[srvgit] / opac / opac-detail.pl
index f4bdf3d..6173b72 100755 (executable)
@@ -45,7 +45,6 @@ use C4::Letters;
 use MARC::Record;
 use MARC::Field;
 use List::MoreUtils qw/any none/;
-use C4::Images;
 use Koha::DateUtils;
 use C4::HTML5Media;
 use C4::CourseReserves qw(GetItemCourseReservesInfo);
@@ -62,6 +61,7 @@ use Koha::Patrons;
 use Koha::Plugins;
 use Koha::Ratings;
 use Koha::Reviews;
+use Koha::SearchEngine::Search;
 
 use Try::Tiny;
 
@@ -89,10 +89,6 @@ if( $specific_item ) {
 }
 my @hiddenitems;
 my $patron = Koha::Patrons->find( $borrowernumber );
-our $borcat= q{};
-if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
-    $borcat = $patron ? $patron->categorycode : q{};
-}
 
 my $record = GetMarcBiblio({
     biblionumber => $biblionumber,
@@ -102,17 +98,20 @@ if ( ! $record ) {
     exit;
 }
 
-if ( scalar @all_items >= 1 ) {
-    push @hiddenitems,
-      GetHiddenItemnumbers( { items => \@all_items, borcat => $borcat } );
-
-    if (scalar @hiddenitems == scalar @all_items ) {
-        print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
+my $biblio = Koha::Biblios->find( $biblionumber );
+unless ( $patron and $patron->category->override_hidden_items ) {
+    # only skip this check if there's a logged in user
+    # and its category overrides OpacHiddenItems
+    if ( $biblio->hidden_in_opac({ rules => C4::Context->yaml_preference('OpacHiddenItems') }) ) {
+        print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early
         exit;
     }
+    if ( scalar @all_items >= 1 ) {
+        push @hiddenitems,
+          GetHiddenItemnumbers( { items => \@all_items, borcat => $patron ? $patron->categorycode : undef } );
+    }
 }
 
-my $biblio = Koha::Biblios->find( $biblionumber );
 my $framework = $biblio ? $biblio->frameworkcode : q{};
 my $record_processor = Koha::RecordProcessor->new({
     filters => 'ViewPolicy',
@@ -181,8 +180,23 @@ my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
 
 if ( $xslfile ) {
 
+    my $searcher = Koha::SearchEngine::Search->new(
+        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
+    );
+    my $cleaned_title = $biblio->title;
+    $cleaned_title =~ tr|/||;
+    my $query =
+      ( C4::Context->preference('UseControlNumber') and $record->field('001') )
+      ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
+      : "Host-item:$cleaned_title";
+    my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
+
+    warn "Warning from simple_search_compat: $err"
+        if $err;
+
     my $variables = {
-        anonymous_session => ($borrowernumber) ? 0 : 1
+        anonymous_session   => ($borrowernumber) ? 0 : 1,
+        show_analytics_link => $count > 0 ? 1 : 0
     };
 
     my @plugin_responses = Koha::Plugins->call(
@@ -265,7 +279,7 @@ if ($session->param('busc')) {
         my @newresults;
         my $search_context = {
             'interface' => 'opac',
-            'category'  => $borcat
+            'category'  => ($patron) ? $patron->categorycode : q{}
         };
         for (my $i=0;$i<@servers;$i++) {
             my $server = $servers[$i];
@@ -693,6 +707,7 @@ if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {
 }
 
 my $allow_onshelf_holds;
+my ( $itemloop_has_images, $otheritemloop_has_images );
 if ( not $viewallitems and @items > $max_items_to_display ) {
     $template->param(
         too_many_items => 1,
@@ -746,15 +761,22 @@ if ( not $viewallitems and @items > $max_items_to_display ) {
           if grep { $_ eq $itm->{itemnumber} } @itemnumbers_on_order;
     }
 
+    if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) {
+        $itm->{cover_images} = $item->cover_images;
+    }
+
     my $itembranch = $itm->{$separatebranch};
     if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
         if ($itembranch and $itembranch eq $currentbranch) {
             push @itemloop, $itm;
+            $itemloop_has_images++ if $item->cover_images->count;
         } else {
             push @otheritemloop, $itm;
+            $otheritemloop_has_images++ if $item->cover_images->count;
         }
     } else {
         push @itemloop, $itm;
+        $itemloop_has_images++ if $item->cover_images->count;
     }
   }
 }
@@ -763,6 +785,11 @@ if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_item
     $template->param( ReservableItems => 1 );
 }
 
+$template->param(
+    itemloop_has_images      => $itemloop_has_images,
+    otheritemloop_has_images => $otheritemloop_has_images,
+);
+
 # Display only one tab if one items list is empty
 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
     $template->param(SeparateHoldings => 0);
@@ -788,7 +815,7 @@ if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
     );
 }
 
-my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour,1);
+my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
 
 if( C4::Context->preference('ArticleRequests') ) {
     my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
@@ -872,7 +899,7 @@ my $coins = eval { $biblio->get_coins };
 $template->param( ocoins => $coins );
 
 my ( $loggedincommenter, $reviews );
-if ( C4::Context->preference('reviewson') ) {
+if ( C4::Context->preference('OPACComments') ) {
     $reviews = Koha::Reviews->search(
         {
             biblionumber => $biblionumber,
@@ -1218,8 +1245,7 @@ my $defaulttab =
 $template->param('defaulttab' => $defaulttab);
 
 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
-    my @images = ListImagesForBiblio($biblionumber);
-    $template->{VARS}->{localimages} = \@images;
+    $template->param( localimages => $biblio->cover_images );
 }
 
 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');