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

(-)a/C4/XSLT.pm (-24 / +30 lines)
Lines 269-299 sub XSLTParse4Display { Link Here
269
    my $partsxml = '';
269
    my $partsxml = '';
270
    # possibly insert component records into Detail views
270
    # possibly insert component records into Detail views
271
    if ($xslsyspref =~ m/Details/) {
271
    if ($xslsyspref =~ m/Details/) {
272
        my $biblio = Koha::Biblios->find( $biblionumber );
273
        my $components = $biblio->get_marc_components(300);
274
        $variables->{show_analytics_link} = ( scalar @{$components} == 0 ) ? 0 : 1;
275
272
        my $showcomp = C4::Context->preference('ShowComponentRecords');
276
        my $showcomp = C4::Context->preference('ShowComponentRecords');
273
        if ( $showcomp eq 'both' ||
277
        if (
274
             ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) ||
278
            $variables->{show_analytics_link}
275
             ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/  ) ) {
279
            && (   $showcomp eq 'both'
276
            my $biblio = Koha::Biblios->find( $biblionumber );
280
                || ( $showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ )
277
            my $max_results = 300;
281
                || ( $showcomp eq 'opac'  && $xslsyspref =~ m/OPAC/ ) )
278
282
          )
279
            if ( $biblio->get_marc_components($max_results) ) {
283
        {
280
                my $search_query = Koha::Util::Search::get_component_part_query($biblionumber);
284
281
                $variables->{ComponentPartQuery} = $search_query;
285
             $variables->{show_analytics_link} = 0;
282
286
283
                my @componentPartRecordXML = ('<componentPartRecords>');
287
             my $search_query = Koha::Util::Search::get_component_part_query($biblionumber);
284
                for my $cb ( @{ $biblio->get_marc_components($max_results) } ) {
288
             $variables->{ComponentPartQuery} = $search_query;
285
                    if( ref $cb eq 'MARC::Record'){
289
286
                        $cb = $cb->as_xml_record();
290
             my @componentPartRecordXML = ('<componentPartRecords>');
287
                    } else {
291
             for my $cb ( @{ $components } ) {
288
                        $cb = decode('utf8', $cb);
292
                 if( ref $cb eq 'MARC::Record'){
289
                    }
293
                     $cb = $cb->as_xml_record();
290
                    # Remove the xml header
294
                 } else {
291
                    $cb =~ s/^<\?xml.*?\?>//;
295
                     $cb = decode('utf8', $cb);
292
                    push @componentPartRecordXML,$cb;
296
                 }
293
                }
297
                 # Remove the xml header
294
                push @componentPartRecordXML, '</componentPartRecords>';
298
                 $cb =~ s/^<\?xml.*?\?>//;
295
                $partsxml = join "\n", @componentPartRecordXML;
299
                 push @componentPartRecordXML,$cb;
296
            }
300
             }
301
             push @componentPartRecordXML, '</componentPartRecords>';
302
             $partsxml = join "\n", @componentPartRecordXML;
297
        }
303
        }
298
    }
304
    }
299
305
(-)a/Koha/Biblio.pm (-2 / +2 lines)
Lines 510-516 this object (MARC21 773$w points to this) Link Here
510
sub get_marc_components {
510
sub get_marc_components {
511
    my ($self, $max_results) = @_;
511
    my ($self, $max_results) = @_;
512
512
513
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
513
    return [] if (C4::Context->preference('marcflavour') ne 'MARC21');
514
514
515
    my $searchstr = Koha::Util::Search::get_component_part_query($self->id);
515
    my $searchstr = Koha::Util::Search::get_component_part_query($self->id);
516
516
Lines 520-526 sub get_marc_components { Link Here
520
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
520
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
521
    }
521
    }
522
522
523
    return $self->{_components} || ();
523
    return $self->{_components} || [];
524
}
524
}
525
525
526
=head3 subscriptions
526
=head3 subscriptions
(-)a/Koha/Util/Search.pm (-13 / +29 lines)
Lines 19-25 package Koha::Util::Search; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use C4::Biblio;
22
use C4::Biblio qw( GetMarcBiblio );
23
23
24
=head1 NAME
24
=head1 NAME
25
25
Lines 36-57 Returns a query which can be used to search for all component parts of MARC21 bi Link Here
36
sub get_component_part_query {
36
sub get_component_part_query {
37
    my ($biblionumber) = @_;
37
    my ($biblionumber) = @_;
38
38
39
    my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
39
    my $marc = GetMarcBiblio( { biblionumber => $biblionumber } );
40
    my $pf001 = $marc->field('001') || undef;
41
40
42
    if (defined($pf001)) {
41
    my $searchstr;
43
        my $pf003 = $marc->field('003') || undef;
42
    if ( C4::Context->preference('UseControlNumber') ) {
44
        my $searchstr;
43
        my $pf001 = $marc->field('001') || undef;
45
44
46
        if (!defined($pf003)) {
45
        if ( defined($pf001) ) {
47
            # search for 773$w='Host001'
46
            my $pf003 = $marc->field('003') || undef;
48
            $searchstr = "rcn=\"".$pf001->data()."\"";
47
49
        } else {
48
            if ( !defined($pf003) ) {
50
            # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001')
49
                # search for 773$w='Host001'
51
            $searchstr = "(rcn=\"".$pf001->data()."\" AND cni=\"".$pf003->data()."\")";
50
                $searchstr = "rcn:" . $pf001->data();
52
            $searchstr .= " OR rcn=\"".$pf003->data()." ".$pf001->data()."\"";
51
            }
52
            else {
53
                $searchstr  = "(";
54
                # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001')
55
                $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")";
56
                $searchstr .= " OR rcn:" . $pf003->data() . " " . $pf001->data();
57
                $searchstr .= ")";
58
            }
59
60
            # limit to monograph and serial component part records
61
            $searchstr .= " AND (bib-level:a OR bib-level:b)";
53
        }
62
        }
54
    }
63
    }
64
    else {
65
        my $cleaned_title = $marc->title;
66
        $cleaned_title =~ tr|/||;
67
        $searchstr = "Host-item:($cleaned_title)";
68
    }
69
70
    return $searchstr;
55
}
71
}
56
72
57
1;
73
1;
(-)a/catalogue/detail.pl (-19 lines)
Lines 129-158 my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; Link Here
129
129
130
if ( $xslfile ) {
130
if ( $xslfile ) {
131
131
132
    my $searcher = Koha::SearchEngine::Search->new(
133
        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
134
    );
135
    my $cleaned_title = $biblio->title;
136
    $cleaned_title =~ tr|/||;
137
    my $query =
138
      ( C4::Context->preference('UseControlNumber') and $record->field('001') )
139
      ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
140
      : "Host-item:($cleaned_title)";
141
    my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
142
143
    warn "Warning from simple_search_compat: $err"
144
        if $err;
145
146
    my $variables = {
147
        show_analytics_link => $count > 0 ? 1 : 0
148
    };
149
150
    $template->param(
132
    $template->param(
151
        XSLTDetailsDisplay => '1',
133
        XSLTDetailsDisplay => '1',
152
        XSLTBloc           => XSLTParse4Display(
134
        XSLTBloc           => XSLTParse4Display(
153
            $biblionumber, $record, "XSLTDetailsDisplay", 1,
135
            $biblionumber, $record, "XSLTDetailsDisplay", 1,
154
            undef,         $sysxml, $xslfile,             $lang,
136
            undef,         $sysxml, $xslfile,             $lang,
155
            $variables
156
        )
137
        )
157
    );
138
    );
158
}
139
}
(-)a/opac/opac-detail.pl (-15 lines)
Lines 200-222 my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; Link Here
200
200
201
if ( $xslfile ) {
201
if ( $xslfile ) {
202
202
203
    my $searcher = Koha::SearchEngine::Search->new(
204
        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
205
    );
206
    my $cleaned_title = $biblio->title;
207
    $cleaned_title =~ tr|/||;
208
    my $query =
209
      ( C4::Context->preference('UseControlNumber') and $record->field('001') )
210
      ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
211
      : "Host-item:($cleaned_title)";
212
    my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
213
214
    warn "Warning from simple_search_compat: $err"
215
        if $err;
216
217
    my $variables = {
203
    my $variables = {
218
        anonymous_session   => ($borrowernumber) ? 0 : 1,
204
        anonymous_session   => ($borrowernumber) ? 0 : 1,
219
        show_analytics_link => $count > 0 ? 1 : 0
220
    };
205
    };
221
206
222
    my @plugin_responses = Koha::Plugins->call(
207
    my @plugin_responses = Koha::Plugins->call(
(-)a/t/Koha/Util/Search.t (-4 / +15 lines)
Lines 20-42 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 1;
23
24
use t::lib::Mocks;
23
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
24
26
25
use C4::Biblio;
27
use C4::Biblio qw( GetMarcBiblio ModBiblioMarc );
26
use Koha::Util::Search;
28
use Koha::Util::Search;
27
use MARC::Field;
29
use MARC::Field;
28
30
29
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
30
32
31
subtest 'get_component_part_query' => sub {
33
subtest 'get_component_part_query' => sub {
32
    plan tests => 1;
34
    plan tests => 3;
33
35
34
    my $biblio = $builder->build_sample_biblio();
36
    my $biblio = $builder->build_sample_biblio();
35
    my $biblionumber = $biblio->biblionumber;
37
    my $biblionumber = $biblio->biblionumber;
36
    my $record = GetMarcBiblio({ biblionumber => $biblionumber });
38
    my $record = GetMarcBiblio({ biblionumber => $biblionumber });
39
40
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
41
    is(Koha::Util::Search::get_component_part_query($biblionumber), "Host-item:(Some boring read)", "UseControlNumber disabled");
42
43
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
37
    my $marc_001_field = MARC::Field->new('001', $biblionumber);
44
    my $marc_001_field = MARC::Field->new('001', $biblionumber);
38
    $record->append_fields($marc_001_field);
45
    $record->append_fields($marc_001_field);
39
    ModBiblioMarc($record, $biblionumber);
46
    ModBiblioMarc($record, $biblionumber);
40
47
41
    is(Koha::Util::Search::get_component_part_query($biblionumber), "rcn=\"$biblionumber\"");
48
    is(Koha::Util::Search::get_component_part_query($biblionumber), "rcn:$biblionumber AND (bib-level:a OR bib-level:b)", "UseControlNumber enabled without MarcOrgCode");
49
50
    my $marc_003_field = MARC::Field->new('003', 'OSt');
51
    $record->append_fields($marc_003_field);
52
    ModBiblioMarc($record, $biblionumber);
53
    is(Koha::Util::Search::get_component_part_query($biblionumber), "((rcn:$biblionumber AND cni:OSt) OR rcn:OSt $biblionumber) AND (bib-level:a OR bib-level:b)", "UseControlNumber enabled with MarcOrgCode");
42
};
54
};
43
- 

Return to bug 11175