@@ -, +, @@ --- C4/XSLT.pm | 44 +++++++++++++++++++++++--------------------- Koha/Util/Search.pm | 42 ++++++++++++++++++++++++++++-------------- catalogue/detail.pl | 19 ------------------- opac/opac-detail.pl | 15 --------------- 4 files changed, 51 insertions(+), 69 deletions(-) --- a/C4/XSLT.pm +++ a/C4/XSLT.pm @@ -269,31 +269,33 @@ sub XSLTParse4Display { my $partsxml = ''; # possibly insert component records into Detail views if ($xslsyspref =~ m/Details/) { + my $biblio = Koha::Biblios->find( $biblionumber ); + my $components = $biblio->get_marc_components(300); + $variables->{show_analytics_link} = ( scalar @{$components} == 0 ) ? 0 : 1; + my $showcomp = C4::Context->preference('ShowComponentRecords'); if ( $showcomp eq 'both' || ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) || ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/ ) ) { - my $biblio = Koha::Biblios->find( $biblionumber ); - my $max_results = 300; - - if ( $biblio->get_marc_components($max_results) ) { - my $search_query = Koha::Util::Search::get_component_part_query($biblionumber); - $variables->{ComponentPartQuery} = $search_query; - - my @componentPartRecordXML = (''); - for my $cb ( @{ $biblio->get_marc_components($max_results) } ) { - if( ref $cb eq 'MARC::Record'){ - $cb = $cb->as_xml_record(); - } else { - $cb = decode('utf8', $cb); - } - # Remove the xml header - $cb =~ s/^<\?xml.*?\?>//; - push @componentPartRecordXML,$cb; - } - push @componentPartRecordXML, ''; - $partsxml = join "\n", @componentPartRecordXML; - } + + $variables->{show_analytics_link} = 0; + + my $search_query = Koha::Util::Search::get_component_part_query($biblionumber); + $variables->{ComponentPartQuery} = $search_query; + + my @componentPartRecordXML = (''); + for my $cb ( @{ $biblio->get_marc_components($max_results) } ) { + if( ref $cb eq 'MARC::Record'){ + $cb = $cb->as_xml_record(); + } else { + $cb = decode('utf8', $cb); + } + # Remove the xml header + $cb =~ s/^<\?xml.*?\?>//; + push @componentPartRecordXML,$cb; + } + push @componentPartRecordXML, ''; + $partsxml = join "\n", @componentPartRecordXML; } } --- a/Koha/Util/Search.pm +++ a/Koha/Util/Search.pm @@ -36,22 +36,36 @@ Returns a query which can be used to search for all component parts of MARC21 bi sub get_component_part_query { my ($biblionumber) = @_; - my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); - my $pf001 = $marc->field('001') || undef; - - if (defined($pf001)) { - my $pf003 = $marc->field('003') || undef; - my $searchstr; - - if (!defined($pf003)) { - # search for 773$w='Host001' - $searchstr = "rcn=\"".$pf001->data()."\""; - } else { - # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001') - $searchstr = "(rcn=\"".$pf001->data()."\" AND cni=\"".$pf003->data()."\")"; - $searchstr .= " OR rcn=\"".$pf003->data()." ".$pf001->data()."\""; + my $marc = C4::Biblio::GetMarcBiblio( { biblionumber => $biblionumber } ); + + my $searchstr; + if ( C4::Context->preference('UseControlNumber') ) { + my $pf001 = $marc->field('001') || undef; + + if ( defined($pf001) ) { + my $pf003 = $marc->field('003') || undef; + + if ( !defined($pf003) ) { + # search for 773$w='Host001' + $searchstr = "rcn=\"" . $pf001->data() . "\""; + } + else { + $searchstr = "("; + # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001') + $searchstr .= "(rcn=\"" . $pf001->data() . "\" AND cni=\"" . $pf003->data() . "\")"; + $searchstr .= " OR rcn=\"" . $pf003->data() . " " . $pf001->data() . "\""; + $searchstr .= ")"; + } + + # limit to monograph and serial component part records + $serachstr .= " AND (bib-level:a OR bib-level:b)"; } } + else { + my $cleaned_title = $marc->title; + $cleaned_title =~ tr|/||; + $searchstr = "Host-item:($cleaned_title)"; + } } 1; --- a/catalogue/detail.pl +++ a/catalogue/detail.pl @@ -129,30 +129,11 @@ 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 = { - show_analytics_link => $count > 0 ? 1 : 0 - }; - $template->param( XSLTDetailsDisplay => '1', XSLTBloc => XSLTParse4Display( $biblionumber, $record, "XSLTDetailsDisplay", 1, undef, $sysxml, $xslfile, $lang, - $variables ) ); } --- a/opac/opac-detail.pl +++ a/opac/opac-detail.pl @@ -200,23 +200,8 @@ 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, - show_analytics_link => $count > 0 ? 1 : 0 }; my @plugin_responses = Koha::Plugins->call( --