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

(-)a/C4/XSLT.pm (-7 lines)
Lines 224-236 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
    # embed variables
235
    my $varxml = "<variables>\n";
228
    my $varxml = "<variables>\n";
236
    while (my ($key, $value) = each %$variables) {
229
    while (my ($key, $value) = each %$variables) {
(-)a/Koha/Biblio.pm (-73 / +86 lines)
Lines 715-720 sub get_components_query { Link Here
715
    return ($query, $query_str, $sort);
715
    return ($query, $query_str, $sort);
716
}
716
}
717
717
718
=head3 get_marc_volumes
719
720
  my $volumes = $self->get_marc_volumes();
721
722
Returns an array of MARCXML data, which are volumes parts of
723
this object (MARC21 773$w points to this)
724
725
=cut
726
727
sub get_marc_volumes {
728
    my ( $self, $max_results ) = @_;
729
730
    return $self->{_volumes} if defined( $self->{_volumes} );
731
732
    my $searchstr = $self->get_volumes_query;
733
734
    if ( defined($searchstr) ) {
735
        my $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
736
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results );
737
        $self->{_volumes} =
738
            ( defined($results) && scalar(@$results) ) ? $results : [];
739
    } else {
740
        $self->{_volumes} = [];
741
    }
742
743
    return $self->{_volumes};
744
}
745
746
=head2 get_volumes_query
747
748
Returns a query which can be used to search for all component parts of MARC21 biblios
749
750
=cut
751
752
sub get_volumes_query {
753
    my ($self) = @_;
754
755
    # MARC21 Only for now
756
    return if ( C4::Context->preference('marcflavour') ne 'MARC21' );
757
758
    my $marc = $self->metadata->record;
759
760
    # Only build volumes query if we're in a 'Set' record
761
    # or we have a monographic series.
762
    my $leader19 = substr( $marc->leader, 19, 1 );
763
    my $pf008    = $marc->field('008') || '';
764
    my $mseries  = ( $pf008 && substr( $pf008->data(), 21, 1 ) eq 'm' ) ? 1 : 0;
765
    return unless ( $leader19 eq 'a' || $mseries );
766
767
    my $builder = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
768
769
    my $searchstr;
770
    if ( C4::Context->preference('UseControlNumber') ) {
771
        my $pf001 = $marc->field('001') || undef;
772
773
        if ( defined($pf001) ) {
774
            $searchstr = "(";
775
            my $pf003 = $marc->field('003') || undef;
776
777
            if ( !defined($pf003) ) {
778
779
                # search for 773$w='Host001'
780
                $searchstr .= "rcn:" . $pf001->data();
781
            } else {
782
                $searchstr .= "(";
783
784
                # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001'
785
                $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")";
786
                $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\"";
787
                $searchstr .= ")";
788
            }
789
790
            # exclude monograph and serial component part records
791
            $searchstr .= " NOT (bib-level:a OR bib-level:b)";
792
            $searchstr .= ")";
793
        }
794
    } else {
795
        my $cleaned_title = $marc->subfield( '245', "a" );
796
        $cleaned_title =~ tr|/||;
797
        $cleaned_title = $builder->clean_search_term($cleaned_title);
798
        $searchstr     = "ti,phr:($cleaned_title)";
799
    }
800
801
    return $searchstr;
802
}
803
718
=head3 subscriptions
804
=head3 subscriptions
719
805
720
my $subscriptions = $self->subscriptions
806
my $subscriptions = $self->subscriptions
Lines 1615-1693 sub opac_summary_html { Link Here
1615
    return $summary_html;
1701
    return $summary_html;
1616
}
1702
}
1617
1703
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 $builder = Koha::SearchEngine::QueryBuilder->new(
1653
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
1654
    my $marc = $self->metadata->record;
1655
1656
    my $searchstr;
1657
    if ( C4::Context->preference('UseControlNumber') ) {
1658
        my $pf001 = $marc->field('001') || undef;
1659
1660
        if ( defined($pf001) ) {
1661
            $searchstr = "(";
1662
            my $pf003 = $marc->field('003') || undef;
1663
1664
            if ( !defined($pf003) ) {
1665
                # search for 773$w='Host001'
1666
                $searchstr .= "rcn:" . $pf001->data();
1667
            }
1668
            else {
1669
                $searchstr .= "(";
1670
                # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001'
1671
                $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")";
1672
                $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\"";
1673
                $searchstr .= ")";
1674
            }
1675
1676
            # exclude monograph and serial component part records
1677
            $searchstr .= " NOT (bib-level:a OR bib-level:b)";
1678
            $searchstr .= ")";
1679
        }
1680
    }
1681
    else {
1682
        my $cleaned_title = $marc->subfield('245', "a");
1683
        $cleaned_title =~ tr|/||;
1684
        $cleaned_title = $builder->clean_search_term($cleaned_title);
1685
        $searchstr = "ti,phr:($cleaned_title)";
1686
    }
1687
1688
    return $searchstr;
1689
}
1690
1691
=head2 Internal methods
1704
=head2 Internal methods
1692
1705
1693
=head3 type
1706
=head3 type
(-)a/catalogue/detail.pl (-1 / +7 lines)
Lines 269-276 if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { Link Here
269
    $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->object_messages};
269
    $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->object_messages};
270
}
270
}
271
271
272
# Display volumes link
273
my $show_volumes = 1 if @{$biblio->get_marc_volumes(1)};
274
272
# XSLT processing of some stuff
275
# XSLT processing of some stuff
273
my $xslt_variables = { show_analytics_link => $show_analytics };
276
my $xslt_variables = {
277
    show_analytics_link => $show_analytics,
278
    show_volumes_link   => $show_volumes
279
};
274
$template->param(
280
$template->param(
275
    XSLTDetailsDisplay => '1',
281
    XSLTDetailsDisplay => '1',
276
    XSLTBloc => XSLTParse4Display({
282
    XSLTBloc => XSLTParse4Display({
(-)a/opac/opac-detail.pl (+4 lines)
Lines 620-625 if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { Link Here
620
    $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not
620
    $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not
621
}
621
}
622
622
623
# Display volumes link
624
my $show_volumes = 1 if @{$biblio->get_marc_volumes(1)};
625
623
# XSLT processing of some stuff
626
# XSLT processing of some stuff
624
my $variables = {};
627
my $variables = {};
625
my $lang = C4::Languages::getlanguage();
628
my $lang = C4::Languages::getlanguage();
Lines 636-641 for my $plugin_variables ( @plugin_responses ) { Link Here
636
}
639
}
637
$variables->{anonymous_session} = $borrowernumber ? 0 : 1;
640
$variables->{anonymous_session} = $borrowernumber ? 0 : 1;
638
$variables->{show_analytics_link} = $show_analytics;
641
$variables->{show_analytics_link} = $show_analytics;
642
$variables->{show_volumes_link} = $show_volumes;
639
$template->param(
643
$template->param(
640
    XSLTBloc => XSLTParse4Display({
644
    XSLTBloc => XSLTParse4Display({
641
        biblionumber   => $biblionumber,
645
        biblionumber   => $biblionumber,
(-)a/t/db_dependent/Koha/Biblio.t (-3 / +9 lines)
Lines 622-627 subtest 'get_volumes_query' => sub { Link Here
622
    my $biblionumber = $biblio->biblionumber;
622
    my $biblionumber = $biblio->biblionumber;
623
    my $record       = $biblio->metadata->record;
623
    my $record       = $biblio->metadata->record;
624
624
625
    # Ensure our mocked record is captured as a set or monographic series
626
    my $ldr = $record->leader();
627
    substr( $ldr, 19, 1 ) = 'a';
628
    $record->leader($ldr);
629
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
630
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
631
625
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
632
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
626
    is( $biblio->get_volumes_query, "ti,phr:(Some boring read)", "UseControlNumber disabled" );
633
    is( $biblio->get_volumes_query, "ti,phr:(Some boring read)", "UseControlNumber disabled" );
627
634
Lines 632-638 subtest 'get_volumes_query' => sub { Link Here
632
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
639
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
633
640
634
    is(
641
    is(
635
        $biblio->get_volumes_query, "rcn:$biblionumber NOT (bib-level:a OR bib-level:b)",
642
        $biblio->get_volumes_query, "(rcn:$biblionumber NOT (bib-level:a OR bib-level:b))",
636
        "UseControlNumber enabled without MarcOrgCode"
643
        "UseControlNumber enabled without MarcOrgCode"
637
    );
644
    );
638
645
Lines 643-649 subtest 'get_volumes_query' => sub { Link Here
643
650
644
    is(
651
    is(
645
        $biblio->get_volumes_query,
652
        $biblio->get_volumes_query,
646
        "((rcn:$biblionumber AND cni:OSt) OR rcn:OSt $biblionumber) NOT (bib-level:a OR bib-level:b)",
653
        "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") NOT (bib-level:a OR bib-level:b))",
647
        "UseControlNumber enabled with MarcOrgCode"
654
        "UseControlNumber enabled with MarcOrgCode"
648
    );
655
    );
649
};
656
};
650
- 

Return to bug 26314