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

Return to bug 11175