Bug 13188: Add PatronSelfModificationMandatoryField system preference
[srvgit] / opac / opac-detail.pl
index 9e12ef8..3b47a19 100755 (executable)
@@ -32,6 +32,7 @@ use C4::Koha qw(
     GetNormalizedOCLCNumber
     GetNormalizedUPC
 );
+use C4::Search qw( new_record_from_zebra );
 use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
 use C4::Output qw( parametrized_url output_html_with_http_headers );
 use C4::Biblio qw(
@@ -194,67 +195,6 @@ SetUTF8Flag($record);
 my $marcflavour      = C4::Context->preference("marcflavour");
 my $ean = GetNormalizedEAN( $record, $marcflavour );
 
-{
-    my $searcher = Koha::SearchEngine::Search->new(
-        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
-    );
-    my $builder = Koha::SearchEngine::QueryBuilder->new(
-        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
-    );
-
-    my $cleaned_title = $biblio->title;
-    $cleaned_title =~ tr|/||;
-    $cleaned_title = $builder->clean_search_term($cleaned_title);
-
-    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 );
-    eval {
-        ( $err, $result, $count ) =
-          $searcher->simple_search_compat( $query, 0, 0 );
-
-    };
-    if ($err || $@){
-        my $error = q{};
-        $error .= $err if $err;
-        $error .= $@ if $@;
-        warn "Warning from simple_search_compat: $error";
-    }
-
-    my $variables = {
-        anonymous_session   => ($borrowernumber) ? 0 : 1,
-        show_analytics_link => defined $count && $count > 0 ? 1 : 0
-    };
-
-    my $lang   = C4::Languages::getlanguage();
-    my @plugin_responses = Koha::Plugins->call(
-        'opac_detail_xslt_variables',
-        {
-            biblio_id => $biblionumber,
-            lang      => $lang,
-            patron_id => $borrowernumber
-
-        }
-    );
-    for my $plugin_variables ( @plugin_responses ) {
-        $variables = { %$variables, %$plugin_variables };
-    }
-
-    $template->param(
-        XSLTBloc => XSLTParse4Display(
-            {
-                biblionumber   => $biblionumber,
-                record         => $record,
-                xsl_syspref    => 'OPACXSLTDetailsDisplay',
-                fix_amps       => 1,
-                xslt_variables => $variables
-            }
-        ),
-    );
-}
-
 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
 
 # We look for the busc param to build the simple paging from the search
@@ -262,7 +202,6 @@ if ($OpacBrowseResults) {
 my $session = get_session($query->cookie("CGISESSID"));
 my %paging = (previous => {}, next => {});
 if ($session->param('busc')) {
-    use C4::Search;
     use URI::Escape qw( uri_escape_utf8 uri_unescape );
 
     # Rebuild the string to store on session
@@ -686,6 +625,58 @@ my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
 my $viewallitems = $query->param('viewallitems');
 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
 
+# Get component parts details
+my $showcomp = C4::Context->preference('ShowComponentRecords');
+my ( $parts, $show_analytics );
+if ( $showcomp eq 'both' || $showcomp eq 'opac' ) {
+    if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) {
+        $show_analytics = 1 if @{$components}; # just show link when having results
+        for my $part ( @{$components} ) {
+            $part = C4::Search::new_record_from_zebra( 'biblioserver', $part );
+            my $id = Koha::SearchEngine::Search::extract_biblionumber( $part );
+
+            push @{$parts},
+              XSLTParse4Display(
+                {
+                    biblionumber => $id,
+                    record       => $part,
+                    xsl_syspref  => 'OPACXSLTResultsDisplay',
+                    fix_amps     => 1,
+                }
+              );
+        }
+        $template->param( ComponentParts => $parts );
+        $template->param( ComponentPartsQuery => $biblio->get_components_query );
+    }
+} else { # check if we should show analytics anyway
+    $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not
+}
+
+# XSLT processing of some stuff
+my $variables = {};
+my @plugin_responses = Koha::Plugins->call(
+    'opac_detail_xslt_variables',
+    {
+        biblio_id => $biblionumber,
+        lang      => C4::Languages::getlanguage(),
+        patron_id => $borrowernumber,
+    },
+);
+for my $plugin_variables ( @plugin_responses ) {
+    $variables = { %$variables, %$plugin_variables };
+}
+$variables->{anonymous_session} = $borrowernumber ? 0 : 1;
+$variables->{show_analytics_link} = $show_analytics;
+$template->param(
+    XSLTBloc => XSLTParse4Display({
+        biblionumber   => $biblionumber,
+        record         => $record,
+        xsl_syspref    => 'OPACXSLTDetailsDisplay',
+        fix_amps       => 1,
+        xslt_variables => $variables,
+    }),
+);
+
 # Get items on order
 my ( @itemnumbers_on_order );
 if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {
@@ -809,7 +800,6 @@ my $norequests = ! $biblio->items->filter_by_for_hold->count;
     $template->param(
                      MARCNOTES               => $marcnotesarray,
                      norequests              => $norequests,
-                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
                      itemdata_ccode          => $itemfields{ccode},
                      itemdata_materials      => $itemfields{materials},
                      itemdata_enumchron      => $itemfields{enumchron},
@@ -933,7 +923,7 @@ if (C4::Context->preference("virtualshelves") ) {
     my $shelves = Koha::Virtualshelves->search(
         {
             biblionumber => $biblionumber,
-            category => 2,
+            public       => 1,
         },
         {
             join => 'virtualshelfcontents',
@@ -1214,6 +1204,8 @@ my $defaulttab =
         ? 'serialcollection' :
     $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
         ? 'holdings' :
+    ( $showcomp eq 'both' || $showcomp eq 'opac' ) && scalar (@itemloop) == 0 && $parts
+        ? 'components' :
     scalar (@itemloop) == 0
         ? 'media' :
     $subscriptionsnumber