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

(-)a/Koha/Biblio.pm (-2 / +2 lines)
Lines 616-628 sub get_components_query { Link Here
616
        $cleaned_title = $builder->clean_search_term($cleaned_title);
616
        $cleaned_title = $builder->clean_search_term($cleaned_title);
617
        $searchstr = qq#Host-item:("$cleaned_title")#;
617
        $searchstr = qq#Host-item:("$cleaned_title")#;
618
    }
618
    }
619
    my ($error, $query_str) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 );
619
    my ($error, $query ,$query_str) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 );
620
    if( $error ){
620
    if( $error ){
621
        warn $error;
621
        warn $error;
622
        return;
622
        return;
623
    }
623
    }
624
624
625
    return ($query_str, $sort);
625
    return ($query, $query_str, $sort);
626
}
626
}
627
627
628
=head3 subscriptions
628
=head3 subscriptions
(-)a/catalogue/detail.pl (-2 / +2 lines)
Lines 265-272 if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { Link Here
265
              );
265
              );
266
        }
266
        }
267
        $template->param( ComponentParts => $parts );
267
        $template->param( ComponentParts => $parts );
268
        my ( $comp_query, $comp_sort ) = $biblio->get_components_query;
268
        my ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
269
        my $cpq = $comp_query . "&sort_by=" . $comp_sort;
269
        my $cpq = $comp_query_str . "&sort_by=" . $comp_sort;
270
        $template->param( ComponentPartsQuery => $cpq );
270
        $template->param( ComponentPartsQuery => $cpq );
271
    }
271
    }
272
} else { # check if we should show analytics anyway
272
} else { # check if we should show analytics anyway
(-)a/opac/opac-detail.pl (-2 / +2 lines)
Lines 616-623 if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { Link Here
616
              );
616
              );
617
        }
617
        }
618
        $template->param( ComponentParts => $parts );
618
        $template->param( ComponentParts => $parts );
619
        my ( $comp_query, $comp_sort ) = $biblio->get_components_query;
619
        my ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
620
        my $cpq = $comp_query . "&sort_by=" . $comp_sort;
620
        my $cpq = $comp_query_str . "&sort_by=" . $comp_sort;
621
        $template->param( ComponentPartsQuery => $cpq );
621
        $template->param( ComponentPartsQuery => $cpq );
622
    }
622
    }
623
} else { # check if we should show analytics anyway
623
} else { # check if we should show analytics anyway
(-)a/t/db_dependent/Koha/Biblio.t (-30 / +34 lines)
Lines 562-601 subtest 'get_marc_components() tests' => sub { Link Here
562
};
562
};
563
563
564
subtest 'get_components_query' => sub {
564
subtest 'get_components_query' => sub {
565
    plan tests => 6;
565
    plan tests => 12;
566
566
567
    my $biblio = $builder->build_sample_biblio();
567
    my $biblio = $builder->build_sample_biblio();
568
    my $biblionumber = $biblio->biblionumber;
568
    my $biblionumber = $biblio->biblionumber;
569
    my $record = $biblio->metadata->record;
569
    my $record = $biblio->metadata->record;
570
570
571
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
571
    foreach my $engine ('Zebra','Elasticsearch'){
572
    t::lib::Mocks::mock_preference( 'ComponentSortField', 'author' );
572
        t::lib::Mocks::mock_preference( 'SearchEngine', $engine );
573
    t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'za' );
573
574
    my ( $comp_q, $comp_s ) = $biblio->get_components_query;
574
        t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
575
    is($comp_q, 'Host-item:("Some boring read")', "UseControlNumber disabled");
575
        t::lib::Mocks::mock_preference( 'ComponentSortField', 'author' );
576
    is($comp_s, "author_za", "UseControlNumber disabled sort is correct");
576
        t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'za' );
577
577
        my ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
578
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
578
        is($comp_query_str, 'Host-item:("Some boring read")', "$engine: UseControlNumber disabled");
579
    t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'az' );
579
        is($comp_sort, "author_za", "$engine: UseControlNumber disabled sort is correct");
580
    my $marc_001_field = MARC::Field->new('001', $biblionumber);
580
581
    $record->append_fields($marc_001_field);
581
        t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
582
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
582
        t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'az' );
583
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
583
        my $marc_001_field = MARC::Field->new('001', $biblionumber);
584
584
        $record->append_fields($marc_001_field);
585
    ( $comp_q, $comp_s ) = $biblio->get_components_query;
585
        C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
586
    is($comp_q, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode");
586
        $biblio = Koha::Biblios->find( $biblio->biblionumber);
587
    is($comp_s, "author_az", "UseControlNumber enabled without MarcOrgCode sort is correct");
587
588
588
        ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
589
    my $marc_003_field = MARC::Field->new('003', 'OSt');
589
        is($comp_query_str, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "$engine: UseControlNumber enabled without MarcOrgCode");
590
    $record->append_fields($marc_003_field);
590
        is($comp_sort, "author_az", "$engine: UseControlNumber enabled without MarcOrgCode sort is correct");
591
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
591
592
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
592
        my $marc_003_field = MARC::Field->new('003', 'OSt');
593
593
        $record->append_fields($marc_003_field);
594
    t::lib::Mocks::mock_preference( 'ComponentSortField', 'title' );
594
        C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
595
    t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'asc' );
595
        $biblio = Koha::Biblios->find( $biblio->biblionumber);
596
    ( $comp_q, $comp_s ) = $biblio->get_components_query;
596
597
    is($comp_q, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode");
597
        t::lib::Mocks::mock_preference( 'ComponentSortField', 'title' );
598
    is($comp_s, "title_asc", "UseControlNumber enabled with MarcOrgCode sort if correct");
598
        t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'asc' );
599
        ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
600
        is($comp_query_str, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "$engine: UseControlNumber enabled with MarcOrgCode");
601
        is($comp_sort, "title_asc", "$engine: UseControlNumber enabled with MarcOrgCode sort if correct");
602
        $record->delete_field($marc_003_field);
603
    }
599
};
604
};
600
605
601
subtest 'orders() and active_orders() tests' => sub {
606
subtest 'orders() and active_orders() tests' => sub {
602
- 

Return to bug 31543