Bug 11175: Add syspref MaxComponentRecords to remove hardcoded limit
[srvgit] / catalogue / detail.pl
index 4efffed..8eae183 100755 (executable)
@@ -39,7 +39,7 @@ use C4::Reserves;
 use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
 use C4::XISBN qw( get_xisbns );
 use C4::External::Amazon qw( get_amazon_tld );
-use C4::Search qw( z3950_search_args enabled_staff_search_views );
+use C4::Search qw( z3950_search_args enabled_staff_search_views new_record_from_zebra );
 use C4::Tags qw( get_tags );
 use C4::XSLT qw( XSLTParse4Display );
 use Koha::DateUtils qw( format_sqldatetime );
@@ -126,35 +126,6 @@ my $marcflavour  = C4::Context->preference("marcflavour");
 {
     # XSLT processing of some stuff
 
-    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 || $@){
-        warn "Warning from simple_search_compat: $err.$@";
-        $template->param( analytics_error => 1 );
-    }
-
-    my $variables = {
-        show_analytics_link => $count > 0 ? 1 : 0
-    };
-
     $template->param(
         XSLTDetailsDisplay => '1',
         XSLTBloc => XSLTParse4Display(
@@ -163,7 +134,6 @@ my $marcflavour  = C4::Context->preference("marcflavour");
                 record         => $record,
                 xsl_syspref    => "XSLTDetailsDisplay",
                 fix_amps       => 1,
-                xslt_variables => $variables
             }
         ),
     );
@@ -241,6 +211,28 @@ foreach my $subscription (@subscriptions) {
     push @subs, \%cell;
 }
 
+# Get component parts details
+my $showcomp = C4::Context->preference('ShowComponentRecords');
+if ( $showcomp eq 'both' || $showcomp eq 'staff' ) {
+    if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) {
+        my $parts;
+        for my $part ( @{$components} ) {
+            $part = C4::Search::new_record_from_zebra( 'biblioserver', $part );
+
+            push @{$parts},
+              XSLTParse4Display(
+                {
+                    biblionumber => $biblionumber,
+                    record       => $part,
+                    xsl_syspref  => "XSLTResultsDisplay",
+                    fix_amps     => 1,
+                }
+              );
+        }
+        $template->param( ComponentParts => $parts );
+        $template->param( ComponentPartsQuery => $biblio->get_components_query );
+    }
+}
 
 # Get acquisition details
 if ( C4::Context->preference('AcquisitionDetails') ) {