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

(-)a/C4/XSLT.pm (-24 / +30 lines)
Lines 284-314 sub XSLTParse4Display { Link Here
284
    my $partsxml = '';
284
    my $partsxml = '';
285
    # possibly insert component records into Detail views
285
    # possibly insert component records into Detail views
286
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" ) {
286
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" ) {
287
        my $biblio = Koha::Biblios->find( $biblionumber );
288
        my $components = $biblio->get_marc_components(300);
289
        $variables->{show_analytics_link} = ( scalar @{$components} == 0 ) ? 0 : 1;
290
287
        my $showcomp = C4::Context->preference('ShowComponentRecords');
291
        my $showcomp = C4::Context->preference('ShowComponentRecords');
288
        if ( $showcomp eq 'both' ||
292
        if (
289
             ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) ||
293
            $variables->{show_analytics_link}
290
             ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/  ) ) {
294
            && (   $showcomp eq 'both'
291
            my $biblio = Koha::Biblios->find( $biblionumber );
295
                || ( $showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ )
292
            my $max_results = 300;
296
                || ( $showcomp eq 'opac'  && $xslsyspref =~ m/OPAC/ ) )
293
297
          )
294
            if ( $biblio->get_marc_components($max_results) ) {
298
        {
295
                my $search_query = Koha::Util::Search::get_component_part_query($biblionumber);
299
296
                $variables->{ComponentPartQuery} = $search_query;
300
             $variables->{show_analytics_link} = 0;
297
301
298
                my @componentPartRecordXML = ('<componentPartRecords>');
302
             my $search_query = Koha::Util::Search::get_component_part_query($biblionumber);
299
                for my $cb ( @{ $biblio->get_marc_components($max_results) } ) {
303
             $variables->{ComponentPartQuery} = $search_query;
300
                    if( ref $cb eq 'MARC::Record'){
304
301
                        $cb = $cb->as_xml_record();
305
             my @componentPartRecordXML = ('<componentPartRecords>');
302
                    } else {
306
             for my $cb ( @{ $components } ) {
303
                        $cb = decode('utf8', $cb);
307
                 if( ref $cb eq 'MARC::Record'){
304
                    }
308
                     $cb = $cb->as_xml_record();
305
                    # Remove the xml header
309
                 } else {
306
                    $cb =~ s/^<\?xml.*?\?>//;
310
                     $cb = decode('utf8', $cb);
307
                    push @componentPartRecordXML,$cb;
311
                 }
308
                }
312
                 # Remove the xml header
309
                push @componentPartRecordXML, '</componentPartRecords>';
313
                 $cb =~ s/^<\?xml.*?\?>//;
310
                $partsxml = join "\n", @componentPartRecordXML;
314
                 push @componentPartRecordXML,$cb;
311
            }
315
             }
316
             push @componentPartRecordXML, '</componentPartRecords>';
317
             $partsxml = join "\n", @componentPartRecordXML;
312
        }
318
        }
313
    }
319
    }
314
320
(-)a/Koha/Biblio.pm (-2 / +2 lines)
Lines 491-497 this object (MARC21 773$w points to this) Link Here
491
sub get_marc_components {
491
sub get_marc_components {
492
    my ($self, $max_results) = @_;
492
    my ($self, $max_results) = @_;
493
493
494
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
494
    return [] if (C4::Context->preference('marcflavour') ne 'MARC21');
495
495
496
    my $searchstr = Koha::Util::Search::get_component_part_query($self->id);
496
    my $searchstr = Koha::Util::Search::get_component_part_query($self->id);
497
497
Lines 501-507 sub get_marc_components { Link Here
501
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
501
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
502
    }
502
    }
503
503
504
    return $self->{_components} || ();
504
    return $self->{_components} || [];
505
}
505
}
506
506
507
=head3 subscriptions
507
=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 (-24 lines)
Lines 126-154 my $marcflavour = C4::Context->preference("marcflavour"); Link Here
126
{
126
{
127
    # XSLT processing of some stuff
127
    # XSLT processing of some stuff
128
128
129
    my $searcher = Koha::SearchEngine::Search->new(
130
        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
131
    );
132
    my $builder = Koha::SearchEngine::QueryBuilder->new(
133
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
134
135
    my $cleaned_title = $biblio->title;
136
    $cleaned_title =~ tr|/||;
137
    $cleaned_title = $builder->clean_search_term($cleaned_title);
138
139
    my $query =
140
      ( C4::Context->preference('UseControlNumber') and $record->field('001') )
141
      ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
142
      : "Host-item:($cleaned_title)";
143
    my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
144
145
    warn "Warning from simple_search_compat: $err"
146
        if $err;
147
148
    my $variables = {
149
        show_analytics_link => $count > 0 ? 1 : 0
150
    };
151
152
    $template->param(
129
    $template->param(
153
        XSLTDetailsDisplay => '1',
130
        XSLTDetailsDisplay => '1',
154
        XSLTBloc => XSLTParse4Display(
131
        XSLTBloc => XSLTParse4Display(
Lines 157-163 my $marcflavour = C4::Context->preference("marcflavour"); Link Here
157
                record         => $record,
134
                record         => $record,
158
                xsl_syspref    => "XSLTDetailsDisplay",
135
                xsl_syspref    => "XSLTDetailsDisplay",
159
                fix_amps       => 1,
136
                fix_amps       => 1,
160
                xslt_variables => $variables
161
            }
137
            }
162
        ),
138
        ),
163
    );
139
    );
(-)a/opac/opac-detail.pl (-21 lines)
Lines 195-223 my $marcflavour = C4::Context->preference("marcflavour"); Link Here
195
my $ean = GetNormalizedEAN( $record, $marcflavour );
195
my $ean = GetNormalizedEAN( $record, $marcflavour );
196
196
197
{
197
{
198
    my $searcher = Koha::SearchEngine::Search->new(
199
        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
200
    );
201
    my $builder = Koha::SearchEngine::QueryBuilder->new(
202
        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
203
    );
204
205
    my $cleaned_title = $biblio->title;
206
    $cleaned_title =~ tr|/||;
207
    $cleaned_title = $builder->clean_search_term($cleaned_title);
208
209
    my $query =
210
      ( C4::Context->preference('UseControlNumber') and $record->field('001') )
211
      ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
212
      : "Host-item:($cleaned_title)";
213
    my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
214
215
    warn "Warning from simple_search_compat: $err"
216
       if $err;
217
218
    my $variables = {
198
    my $variables = {
219
        anonymous_session   => ($borrowernumber) ? 0 : 1,
199
        anonymous_session   => ($borrowernumber) ? 0 : 1,
220
        show_analytics_link => $count > 0 ? 1 : 0
221
    };
200
    };
222
201
223
    my $lang   = C4::Languages::getlanguage();
202
    my $lang   = C4::Languages::getlanguage();
(-)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