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

(-)a/C4/XSLT.pm (+8 lines)
Lines 224-229 sub XSLTParse4Display { Link Here
224
        }
224
        }
225
    }
225
    }
226
226
227
    # possibly show volumes link in Detail views
228
    if ($xslsyspref =~ m/Details/) {
229
        $biblio //= Koha::Biblios->find( $biblionumber );
230
        my $volumes = $biblio->get_marc_volumes();
231
        $variables->{show_volumes_link} = ( scalar @{$volumes} == 0 ) ? 0 : 1;
232
    }
233
234
    # embed variables
227
    my $varxml = "<variables>\n";
235
    my $varxml = "<variables>\n";
228
    while (my ($key, $value) = each %$variables) {
236
    while (my ($key, $value) = each %$variables) {
229
        $value //= q{};
237
        $value //= q{};
(-)a/Koha/Biblio.pm (+70 lines)
Lines 1615-1620 sub opac_summary_html { Link Here
1615
    return $summary_html;
1615
    return $summary_html;
1616
}
1616
}
1617
1617
1618
=head3 get_marc_volumes
1619
1620
  my $volumes = $self->get_marc_volumes();
1621
1622
Returns an array of MARCXML data, which are volumes parts of
1623
this object (MARC21 773$w points to this)
1624
1625
=cut
1626
1627
sub get_marc_volumes {
1628
    my ($self, $max_results) = @_;
1629
1630
    return [] if (C4::Context->preference('marcflavour') ne 'MARC21');
1631
1632
    my $searchstr = $self->get_volumes_query;
1633
1634
    if (defined($searchstr)) {
1635
        my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
1636
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results );
1637
        $self->{_volumes} = $results if ( defined($results) && scalar(@$results) );
1638
    }
1639
1640
    return $self->{_volumes} || [];
1641
}
1642
1643
=head2 get_volumes_query
1644
1645
Returns a query which can be used to search for all component parts of MARC21 biblios
1646
1647
=cut
1648
1649
sub get_volumes_query {
1650
    my ($self) = @_;
1651
1652
    my $marc = $self->metadata->record;
1653
1654
    my $searchstr;
1655
    if ( C4::Context->preference('UseControlNumber') ) {
1656
        my $pf001 = $marc->field('001') || undef;
1657
1658
        if ( defined($pf001) ) {
1659
            $searchstr = "(";
1660
            my $pf003 = $marc->field('003') || undef;
1661
1662
            if ( !defined($pf003) ) {
1663
                # search for 773$w='Host001'
1664
                $searchstr .= "rcn:" . $pf001->data();
1665
            }
1666
            else {
1667
                $searchstr .= "(";
1668
                # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001'
1669
                $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")";
1670
                $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\"";
1671
                $searchstr .= ")";
1672
            }
1673
1674
            # exclude monograph and serial component part records
1675
            $searchstr .= " NOT (bib-level:a OR bib-level:b)";
1676
            $searchstr .= ")";
1677
        }
1678
    }
1679
    else {
1680
        my $cleaned_title = $marc->title;
1681
        $cleaned_title =~ tr|/||;
1682
        $searchstr = "ti,phr:($cleaned_title)";
1683
    }
1684
1685
    return $searchstr;
1686
}
1687
1618
=head2 Internal methods
1688
=head2 Internal methods
1619
1689
1620
=head3 type
1690
=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 273-279 Link Here
273
        </xsl:if>
273
        </xsl:if>
274
274
275
        <!-- Volumes of sets and traced series -->
275
        <!-- Volumes of sets and traced series -->
276
        <xsl:if test="$materialTypeCode='ST' or substring($controlField008,22,1)='m'">
276
        <xsl:variable name="show_volumes_link" select="marc:variables/marc:variable[@name='show_volumes_link']" />
277
        <xsl:if test="$show_volumes_link='1' and ($materialTypeCode='ST' or substring($controlField008,22,1)='m')">
277
        <span class="results_summary volumes"><span class="label">Volumes: </span>
278
        <span class="results_summary volumes"><span class="label">Volumes: </span>
278
            <a>
279
            <a>
279
            <xsl:choose>
280
            <xsl:choose>
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +34 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 27;
20
use Test::More tests => 28;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 615-620 subtest 'get_components_query' => sub { Link Here
615
    }
615
    }
616
};
616
};
617
617
618
subtest 'get_volumes_query' => sub {
619
    plan tests => 3;
620
621
    my $biblio       = $builder->build_sample_biblio();
622
    my $biblionumber = $biblio->biblionumber;
623
    my $record       = $biblio->metadata->record;
624
625
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
626
    is( $biblio->get_volumes_query, "ti,phr:(Some boring read)", "UseControlNumber disabled" );
627
628
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
629
    my $marc_001_field = MARC::Field->new( '001', $biblionumber );
630
    $record->append_fields($marc_001_field);
631
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
632
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
633
634
    is(
635
        $biblio->get_volumes_query, "rcn:$biblionumber NOT (bib-level:a OR bib-level:b)",
636
        "UseControlNumber enabled without MarcOrgCode"
637
    );
638
639
    my $marc_003_field = MARC::Field->new( '003', 'OSt' );
640
    $record->append_fields($marc_003_field);
641
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
642
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
643
644
    is(
645
        $biblio->get_volumes_query,
646
        "((rcn:$biblionumber AND cni:OSt) OR rcn:OSt $biblionumber) NOT (bib-level:a OR bib-level:b)",
647
        "UseControlNumber enabled with MarcOrgCode"
648
    );
649
};
650
618
subtest 'orders() and active_orders() tests' => sub {
651
subtest 'orders() and active_orders() tests' => sub {
619
652
620
    plan tests => 5;
653
    plan tests => 5;
621
- 

Return to bug 26314