View | Details | Raw Unified | Return to bug 26314
Collapse All | Expand All

(-)a/C4/XSLT.pm (-7 lines)
Lines 281-293 sub XSLTParse4Display { Link Here
281
        }
281
        }
282
    }
282
    }
283
283
284
    # possibly show volumes link in Detail views
285
    if ($xslsyspref =~ m/Details/) {
286
        $biblio //= Koha::Biblios->find( $biblionumber );
287
        my $volumes = $biblio->get_marc_volumes();
288
        $variables->{show_volumes_link} = ( scalar @{$volumes} == 0 ) ? 0 : 1;
289
    }
290
291
    # embed variables
284
    # embed variables
292
    my $varxml = "<variables>\n";
285
    my $varxml = "<variables>\n";
293
    while (my ($key, $value) = each %$variables) {
286
    while (my ($key, $value) = each %$variables) {
(-)a/Koha/Biblio.pm (-73 / +90 lines)
Lines 568-573 sub get_components_query { Link Here
568
    return $searchstr;
568
    return $searchstr;
569
}
569
}
570
570
571
=head3 get_marc_volumes
572
573
  my $volumes = $self->get_marc_volumes();
574
575
Returns an array of MARCXML data, which are volumes parts of
576
this object (MARC21 773$w points to this)
577
578
=cut
579
580
sub get_marc_volumes {
581
    my ( $self, $max_results ) = @_;
582
583
    return $self->{_volumes} if defined( $self->{_volumes} );
584
585
    my $searchstr = $self->get_volumes_query;
586
587
    if ( defined($searchstr) ) {
588
        my $searcher = Koha::SearchEngine::Search->new(
589
            { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
590
        my ( $errors, $results, $total_hits ) =
591
          $searcher->simple_search_compat( $searchstr, 0, $max_results );
592
        $self->{_volumes} =
593
          ( defined($results) && scalar(@$results) ) ? $results : [];
594
    }
595
    else {
596
        $self->{_volumes} = [];
597
    }
598
599
    return $self->{_volumes};
600
}
601
602
=head2 get_volumes_query
603
604
Returns a query which can be used to search for all component parts of MARC21 biblios
605
606
=cut
607
608
sub get_volumes_query {
609
    my ($self) = @_;
610
611
    # MARC21 Only for now
612
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
613
614
    my $marc = $self->metadata->record;
615
616
    # Only build volumes query if we're in a 'Set' record 
617
    # or we have a monographic series.
618
    my $leader19 = substr( $marc->leader, 19, 1 );
619
    my $pf008    = $marc->field('008') || '';
620
    my $mseries  = ( $pf008 && substr( $pf008->data(), 21, 1 ) eq 'm' ) ? 1 : 0;
621
    return unless ( $leader19 eq 'a' || $mseries );
622
623
    my $builder = Koha::SearchEngine::QueryBuilder->new(
624
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
625
626
    my $searchstr;
627
    if ( C4::Context->preference('UseControlNumber') ) {
628
        my $pf001 = $marc->field('001') || undef;
629
630
        if ( defined($pf001) ) {
631
            $searchstr = "(";
632
            my $pf003 = $marc->field('003') || undef;
633
634
            if ( !defined($pf003) ) {
635
                # search for 773$w='Host001'
636
                $searchstr .= "rcn:" . $pf001->data();
637
            }
638
            else {
639
                $searchstr .= "(";
640
                # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001'
641
                $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")";
642
                $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\"";
643
                $searchstr .= ")";
644
            }
645
646
            # exclude monograph and serial component part records
647
            $searchstr .= " NOT (bib-level:a OR bib-level:b)";
648
            $searchstr .= ")";
649
        }
650
    }
651
    else {
652
        my $cleaned_title = $marc->subfield('245', "a");
653
        $cleaned_title =~ tr|/||;
654
        $cleaned_title = $builder->clean_search_term($cleaned_title);
655
        $searchstr = "ti,phr:($cleaned_title)";
656
    }
657
658
    return $searchstr;
659
}
660
571
=head3 subscriptions
661
=head3 subscriptions
572
662
573
my $subscriptions = $self->subscriptions
663
my $subscriptions = $self->subscriptions
Lines 1034-1112 sub get_marc_host { Link Here
1034
    }
1124
    }
1035
}
1125
}
1036
1126
1037
=head3 get_marc_volumes
1038
1039
  my $volumes = $self->get_marc_volumes();
1040
1041
Returns an array of MARCXML data, which are volumes parts of
1042
this object (MARC21 773$w points to this)
1043
1044
=cut
1045
1046
sub get_marc_volumes {
1047
    my ($self, $max_results) = @_;
1048
1049
    return [] if (C4::Context->preference('marcflavour') ne 'MARC21');
1050
1051
    my $searchstr = $self->get_volumes_query;
1052
1053
    if (defined($searchstr)) {
1054
        my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
1055
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results );
1056
        $self->{_volumes} = $results if ( defined($results) && scalar(@$results) );
1057
    }
1058
1059
    return $self->{_volumes} || [];
1060
}
1061
1062
=head2 get_volumes_query
1063
1064
Returns a query which can be used to search for all component parts of MARC21 biblios
1065
1066
=cut
1067
1068
sub get_volumes_query {
1069
    my ($self) = @_;
1070
1071
    my $builder = Koha::SearchEngine::QueryBuilder->new(
1072
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
1073
    my $marc = $self->metadata->record;
1074
1075
    my $searchstr;
1076
    if ( C4::Context->preference('UseControlNumber') ) {
1077
        my $pf001 = $marc->field('001') || undef;
1078
1079
        if ( defined($pf001) ) {
1080
            $searchstr = "(";
1081
            my $pf003 = $marc->field('003') || undef;
1082
1083
            if ( !defined($pf003) ) {
1084
                # search for 773$w='Host001'
1085
                $searchstr .= "rcn:" . $pf001->data();
1086
            }
1087
            else {
1088
                $searchstr .= "(";
1089
                # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001'
1090
                $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")";
1091
                $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\"";
1092
                $searchstr .= ")";
1093
            }
1094
1095
            # exclude monograph and serial component part records
1096
            $searchstr .= " NOT (bib-level:a OR bib-level:b)";
1097
            $searchstr .= ")";
1098
        }
1099
    }
1100
    else {
1101
        my $cleaned_title = $marc->subfield('245', "a");
1102
        $cleaned_title =~ tr|/||;
1103
        $cleaned_title = $builder->clean_search_term($cleaned_title);
1104
        $searchstr = "ti,phr:($cleaned_title)";
1105
    }
1106
1107
    return $searchstr;
1108
}
1109
1110
=head2 Internal methods
1127
=head2 Internal methods
1111
1128
1112
=head3 type
1129
=head3 type
(-)a/catalogue/detail.pl (-1 / +7 lines)
Lines 225-232 if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { Link Here
225
    $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->messages};
225
    $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->messages};
226
}
226
}
227
227
228
# Display volumes link
229
my $show_volumes = 1 if @{$biblio->get_marc_volumes(1)};
230
228
# XSLT processing of some stuff
231
# XSLT processing of some stuff
229
my $xslt_variables = { show_analytics_link => $show_analytics };
232
my $xslt_variables = {
233
    show_analytics_link => $show_analytics,
234
    show_volumes_link   => $show_volumes
235
};
230
$template->param(
236
$template->param(
231
    XSLTDetailsDisplay => '1',
237
    XSLTDetailsDisplay => '1',
232
    XSLTBloc => XSLTParse4Display({
238
    XSLTBloc => XSLTParse4Display({
(-)a/opac/opac-detail.pl (-1 / +4 lines)
Lines 652-657 if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { Link Here
652
    $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not
652
    $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not
653
}
653
}
654
654
655
# Display volumes link
656
my $show_volumes = 1 if @{$biblio->get_marc_volumes(1)};
657
655
# XSLT processing of some stuff
658
# XSLT processing of some stuff
656
my $variables = {};
659
my $variables = {};
657
my @plugin_responses = Koha::Plugins->call(
660
my @plugin_responses = Koha::Plugins->call(
Lines 667-672 for my $plugin_variables ( @plugin_responses ) { Link Here
667
}
670
}
668
$variables->{anonymous_session} = $borrowernumber ? 0 : 1;
671
$variables->{anonymous_session} = $borrowernumber ? 0 : 1;
669
$variables->{show_analytics_link} = $show_analytics;
672
$variables->{show_analytics_link} = $show_analytics;
673
$variables->{show_volumes_link} = $show_volumes;
670
$template->param(
674
$template->param(
671
    XSLTBloc => XSLTParse4Display({
675
    XSLTBloc => XSLTParse4Display({
672
        biblionumber   => $biblionumber,
676
        biblionumber   => $biblionumber,
673
- 

Return to bug 26314