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

(-)a/C4/XSLT.pm (-1 / +1 lines)
Lines 285-291 sub XSLTParse4Display { Link Here
285
    # possibly show analytics link in Detail views
285
    # possibly show analytics link in Detail views
286
    if ($xslsyspref =~ m/Details/) {
286
    if ($xslsyspref =~ m/Details/) {
287
        $biblio //= Koha::Biblios->find( $biblionumber );
287
        $biblio //= Koha::Biblios->find( $biblionumber );
288
        my $components = $biblio->get_marc_analytics();
288
        my $components = $biblio->get_marc_components();
289
        $variables->{show_analytics_link} = ( scalar @{$components} == 0 ) ? 0 : 1;
289
        $variables->{show_analytics_link} = ( scalar @{$components} == 0 ) ? 0 : 1;
290
290
291
        my $showcomp = C4::Context->preference('ShowComponentRecords');
291
        my $showcomp = C4::Context->preference('ShowComponentRecords');
(-)a/Koha/Biblio.pm (-7 / +7 lines)
Lines 478-498 sub suggestions { Link Here
478
    return Koha::Suggestions->_new_from_dbic( $suggestions_rs );
478
    return Koha::Suggestions->_new_from_dbic( $suggestions_rs );
479
}
479
}
480
480
481
=head3 get_marc_analytics
481
=head3 get_marc_components
482
482
483
  my $analytics = $self->get_marc_analytics();
483
  my $components = $self->get_marc_components();
484
484
485
Returns an array of MARCXML data, which are analytic parts of
485
Returns an array of MARCXML data, which are component parts of
486
this object (MARC21 773$w points to this)
486
this object (MARC21 773$w points to this)
487
487
488
=cut
488
=cut
489
489
490
sub get_marc_analytics {
490
sub get_marc_components {
491
    my ($self, $max_results) = @_;
491
    my ($self, $max_results) = @_;
492
492
493
    return [] if (C4::Context->preference('marcflavour') ne 'MARC21');
493
    return [] if (C4::Context->preference('marcflavour') ne 'MARC21');
494
494
495
    my $searchstr = $self->get_analytics_query;
495
    my $searchstr = $self->get_components_query;
496
496
497
    if (defined($searchstr)) {
497
    if (defined($searchstr)) {
498
        my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
498
        my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
Lines 503-515 sub get_marc_analytics { Link Here
503
    return $self->{_components} || [];
503
    return $self->{_components} || [];
504
}
504
}
505
505
506
=head2 get_analytics_query
506
=head2 get_components_query
507
507
508
Returns a query which can be used to search for all component parts of MARC21 biblios
508
Returns a query which can be used to search for all component parts of MARC21 biblios
509
509
510
=cut
510
=cut
511
511
512
sub get_analytics_query {
512
sub get_components_query {
513
    my ($self) = @_;
513
    my ($self) = @_;
514
514
515
    my $marc = $self->metadata->record;
515
    my $marc = $self->metadata->record;
(-)a/catalogue/detail.pl (-1 / +1 lines)
Lines 214-220 foreach my $subscription (@subscriptions) { Link Here
214
# Get component parts details
214
# Get component parts details
215
my $showcomp = C4::Context->preference('ShowComponentRecords');
215
my $showcomp = C4::Context->preference('ShowComponentRecords');
216
if ( $showcomp eq 'both' || $showcomp eq 'staff' ) {
216
if ( $showcomp eq 'both' || $showcomp eq 'staff' ) {
217
    if ( my $components = $biblio->get_marc_analytics(300) ) {
217
    if ( my $components = $biblio->get_marc_components(300) ) {
218
        my $xslparts = C4::Context->preference('XSLTResultsDisplay') || "default";
218
        my $xslparts = C4::Context->preference('XSLTResultsDisplay') || "default";
219
        if ( $xslparts ) {
219
        if ( $xslparts ) {
220
            my $parts;
220
            my $parts;
(-)a/opac/opac-detail.pl (-1 / +1 lines)
Lines 660-666 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 5 Link Here
660
# Get component parts details
660
# Get component parts details
661
my $showcomp = C4::Context->preference('ShowComponentRecords');
661
my $showcomp = C4::Context->preference('ShowComponentRecords');
662
if ( $showcomp eq 'both' || $showcomp eq 'opac' ) {
662
if ( $showcomp eq 'both' || $showcomp eq 'opac' ) {
663
    if ( my $components = $biblio->get_marc_analytics(300) ) {
663
    if ( my $components = $biblio->get_marc_components(300) ) {
664
        my $xslparts = C4::Context->preference('OPACXSLTResultsDisplay') || "default";
664
        my $xslparts = C4::Context->preference('OPACXSLTResultsDisplay') || "default";
665
        if ( $xslparts ) {
665
        if ( $xslparts ) {
666
            my $parts;
666
            my $parts;
(-)a/t/db_dependent/Koha/Biblio.t (-10 / +9 lines)
Lines 507-513 subtest 'suggestions() tests' => sub { Link Here
507
    $schema->storage->txn_rollback;
507
    $schema->storage->txn_rollback;
508
};
508
};
509
509
510
subtest 'get_marc_analytics() tests' => sub {
510
subtest 'get_marc_components() tests' => sub {
511
511
512
    plan tests => 3;
512
    plan tests => 3;
513
513
Lines 519-531 subtest 'get_marc_analytics() tests' => sub { Link Here
519
    my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' );
519
    my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' );
520
    $search_mod->mock( 'simple_search_compat', \&search_component_record2 );
520
    $search_mod->mock( 'simple_search_compat', \&search_component_record2 );
521
521
522
    my @components = $host_biblio->get_marc_analytics;
522
    my @components = $host_biblio->get_marc_components;
523
    is( ref(\@components), 'ARRAY', 'Return type is correct' );
523
    is( ref(\@components), 'ARRAY', 'Return type is correct' );
524
524
525
    is_deeply(
525
    is_deeply(
526
        [@components],
526
        [@components],
527
        [[]],
527
        [[]],
528
        '->get_marc_analytics returns an empty ARRAY'
528
        '->get_marc_components returns an empty ARRAY'
529
    );
529
    );
530
530
531
    $search_mod->unmock( 'simple_search_compat');
531
    $search_mod->unmock( 'simple_search_compat');
Lines 533-548 subtest 'get_marc_analytics() tests' => sub { Link Here
533
    my $component_record = component_record1()->as_xml();
533
    my $component_record = component_record1()->as_xml();
534
534
535
    is_deeply(
535
    is_deeply(
536
        $host_biblio->get_marc_analytics,
536
        $host_biblio->get_marc_components,
537
        [($component_record)],
537
        [($component_record)],
538
        '->get_marc_analytics returns the related component part record'
538
        '->get_marc_components returns the related component part record'
539
    );
539
    );
540
    $search_mod->unmock( 'simple_search_compat');
540
    $search_mod->unmock( 'simple_search_compat');
541
541
542
    $schema->storage->txn_rollback;
542
    $schema->storage->txn_rollback;
543
};
543
};
544
544
545
subtest 'get_analytics_query' => sub {
545
subtest 'get_components_query' => sub {
546
    plan tests => 3;
546
    plan tests => 3;
547
547
548
    my $biblio = $builder->build_sample_biblio();
548
    my $biblio = $builder->build_sample_biblio();
Lines 550-556 subtest 'get_analytics_query' => sub { Link Here
550
    my $record = $biblio->metadata->record;
550
    my $record = $biblio->metadata->record;
551
551
552
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
552
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
553
    is($biblio->get_analytics_query, "Host-item:(Some boring read)", "UseControlNumber disabled");
553
    is($biblio->get_components_query, "Host-item:(Some boring read)", "UseControlNumber disabled");
554
554
555
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
555
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
556
    my $marc_001_field = MARC::Field->new('001', $biblionumber);
556
    my $marc_001_field = MARC::Field->new('001', $biblionumber);
Lines 558-571 subtest 'get_analytics_query' => sub { Link Here
558
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
558
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
559
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
559
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
560
560
561
    is($biblio->get_analytics_query, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode");
561
    is($biblio->get_components_query, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode");
562
562
563
    my $marc_003_field = MARC::Field->new('003', 'OSt');
563
    my $marc_003_field = MARC::Field->new('003', 'OSt');
564
    $record->append_fields($marc_003_field);
564
    $record->append_fields($marc_003_field);
565
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
565
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
566
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
566
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
567
567
568
    is($biblio->get_analytics_query, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode");
568
    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");
569
};
569
};
570
570
571
subtest 'orders() and active_orders() tests' => sub {
571
subtest 'orders() and active_orders() tests' => sub {
572
- 

Return to bug 11175