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

(-)a/C4/XSLT.pm (+8 lines)
Lines 281-286 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
    my $varxml = "<variables>\n";
292
    my $varxml = "<variables>\n";
285
    while (my ($key, $value) = each %$variables) {
293
    while (my ($key, $value) = each %$variables) {
286
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
294
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
(-)a/Koha/Biblio.pm (+70 lines)
Lines 1034-1039 sub get_marc_host { Link Here
1034
    }
1034
    }
1035
}
1035
}
1036
1036
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 $marc = $self->metadata->record;
1072
1073
    my $searchstr;
1074
    if ( C4::Context->preference('UseControlNumber') ) {
1075
        my $pf001 = $marc->field('001') || undef;
1076
1077
        if ( defined($pf001) ) {
1078
            $searchstr = "(";
1079
            my $pf003 = $marc->field('003') || undef;
1080
1081
            if ( !defined($pf003) ) {
1082
                # search for 773$w='Host001'
1083
                $searchstr .= "rcn:" . $pf001->data();
1084
            }
1085
            else {
1086
                $searchstr .= "(";
1087
                # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001'
1088
                $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")";
1089
                $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\"";
1090
                $searchstr .= ")";
1091
            }
1092
1093
            # exclude monograph and serial component part records
1094
            $searchstr .= " NOT (bib-level:a OR bib-level:b)";
1095
            $searchstr .= ")";
1096
        }
1097
    }
1098
    else {
1099
        my $cleaned_title = $marc->title;
1100
        $cleaned_title =~ tr|/||;
1101
        $searchstr = "ti,phr:($cleaned_title)";
1102
    }
1103
1104
    return $searchstr;
1105
}
1106
1037
=head2 Internal methods
1107
=head2 Internal methods
1038
1108
1039
=head3 type
1109
=head3 type
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl (-1 / +2 lines)
Lines 231-237 Link Here
231
        </xsl:if>
231
        </xsl:if>
232
232
233
        <!-- Volumes of sets and traced series -->
233
        <!-- Volumes of sets and traced series -->
234
        <xsl:if test="$materialTypeCode='ST' or substring($controlField008,22,1)='m'">
234
        <xsl:variable name="show_volumes_link" select="marc:variables/marc:variable[@name='show_volumes_link']" />
235
        <xsl:if test="$show_volumes_link='1' and ($materialTypeCode='ST' or substring($controlField008,22,1)='m')">
235
        <span class="results_summary volumes"><span class="label">Volumes: </span>
236
        <span class="results_summary volumes"><span class="label">Volumes: </span>
236
            <a>
237
            <a>
237
            <xsl:choose>
238
            <xsl:choose>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACDetail.xsl (-1 / +2 lines)
Lines 266-272 Link Here
266
        </xsl:if>
266
        </xsl:if>
267
267
268
        <!-- Volumes of sets and traced series -->
268
        <!-- Volumes of sets and traced series -->
269
        <xsl:if test="$materialTypeCode='ST' or substring($controlField008,22,1)='m'">
269
        <xsl:variable name="show_volumes_link" select="marc:variables/marc:variable[@name='show_volumes_link']" />
270
        <xsl:if test="$show_volumes_link='1' and ($materialTypeCode='ST' or substring($controlField008,22,1)='m')">
270
        <span class="results_summary volumes"><span class="label">Volumes: </span>
271
        <span class="results_summary volumes"><span class="label">Volumes: </span>
271
            <a>
272
            <a>
272
            <xsl:choose>
273
            <xsl:choose>
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +27 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 18;
20
use Test::More tests => 19;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
Lines 588-593 subtest 'get_components_query' => sub { Link Here
588
    is($biblio->get_components_query, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode");
588
    is($biblio->get_components_query, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode");
589
};
589
};
590
590
591
subtest 'get_volumes_query' => sub {
592
    plan tests => 3;
593
594
    my $biblio = $builder->build_sample_biblio();
595
    my $biblionumber = $biblio->biblionumber;
596
    my $record = $biblio->metadata->record;
597
598
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
599
    is($biblio->get_volumes_query, "ti,phr:(Some boring read)", "UseControlNumber disabled");
600
601
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
602
    my $marc_001_field = MARC::Field->new('001', $biblionumber);
603
    $record->append_fields($marc_001_field);
604
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
605
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
606
607
    is($biblio->get_volumes_query, "rcn:$biblionumber NOT (bib-level:a OR bib-level:b)", "UseControlNumber enabled without MarcOrgCode");
608
609
    my $marc_003_field = MARC::Field->new('003', 'OSt');
610
    $record->append_fields($marc_003_field);
611
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
612
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
613
614
    is($biblio->get_volumes_query, "((rcn:$biblionumber AND cni:OSt) OR rcn:OSt $biblionumber) NOT (bib-level:a OR bib-level:b)", "UseControlNumber enabled with MarcOrgCode");
615
};
616
591
subtest 'orders() and active_orders() tests' => sub {
617
subtest 'orders() and active_orders() tests' => sub {
592
618
593
    plan tests => 5;
619
    plan tests => 5;
594
- 

Return to bug 26314