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

(-)a/Koha/Biblio.pm (-8 / +27 lines)
Lines 470-480 Returns the related Koha::Items object for this biblio Link Here
470
=cut
470
=cut
471
471
472
sub items {
472
sub items {
473
    my ($self) = @_;
473
    my ($self,$params) = @_;
474
474
475
    my $items_rs = $self->_result->items;
475
    my $items_rs = $self->_result->items;
476
476
477
    return Koha::Items->_new_from_dbic( $items_rs );
477
    return Koha::Items->_new_from_dbic( $items_rs ) unless $params->{host_items};
478
479
    my $host_itemnumbers = $self->_host_itemnumbers();
480
    my $params = { -or => [biblionumber => $self->id] };
481
    push @{$params->{'-or'}}, itemnumber => { -in => $host_itemnumbers } if $host_itemnumbers;
482
483
    return Koha::Items->search($params);
478
}
484
}
479
485
480
=head3 host_items
486
=head3 host_items
Lines 491-502 sub host_items { Link Here
491
    return Koha::Items->new->empty
497
    return Koha::Items->new->empty
492
      unless C4::Context->preference('EasyAnalyticalRecords');
498
      unless C4::Context->preference('EasyAnalyticalRecords');
493
499
500
    my $host_itemnumbers = $self->_host_itemnumbers;
501
502
    return Koha::Items->search( { itemnumber => { -in => $host_itemnumbers } } );
503
}
504
505
=head3 _host_itemnumbers
506
507
my $host_itemnumber = $biblio->_host_itemnumbers();
508
509
Return the itemnumbers for analytical items on this record
510
511
=cut
512
513
sub _host_itemnumbers {
514
    my ($self) = @_;
515
494
    my $marcflavour = C4::Context->preference("marcflavour");
516
    my $marcflavour = C4::Context->preference("marcflavour");
495
    my $analyticfield = '773';
517
    my $analyticfield = '773';
496
    if ( $marcflavour eq 'MARC21' ) {
518
    if ( $marcflavour eq 'UNIMARC' ) {
497
        $analyticfield = '773';
498
    }
499
    elsif ( $marcflavour eq 'UNIMARC' ) {
500
        $analyticfield = '461';
519
        $analyticfield = '461';
501
    }
520
    }
502
    my $marc_record = $self->metadata->record;
521
    my $marc_record = $self->metadata->record;
Lines 504-513 sub host_items { Link Here
504
    foreach my $field ( $marc_record->field($analyticfield) ) {
523
    foreach my $field ( $marc_record->field($analyticfield) ) {
505
        push @itemnumbers, $field->subfield('9');
524
        push @itemnumbers, $field->subfield('9');
506
    }
525
    }
507
526
    return \@itemnumbers;
508
    return Koha::Items->search( { itemnumber => { -in => \@itemnumbers } } );
509
}
527
}
510
528
529
511
=head3 itemtype
530
=head3 itemtype
512
531
513
my $itemtype = $biblio->itemtype();
532
my $itemtype = $biblio->itemtype();
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +13 lines)
Lines 811-817 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
811
};
811
};
812
812
813
subtest 'host_items() tests' => sub {
813
subtest 'host_items() tests' => sub {
814
    plan tests => 6;
814
    plan tests => 7;
815
815
816
    $schema->storage->txn_begin;
816
    $schema->storage->txn_begin;
817
817
Lines 847-852 subtest 'host_items() tests' => sub { Link Here
847
    is( ref($host_items),   'Koha::Items' );
847
    is( ref($host_items),   'Koha::Items' );
848
    is( $host_items->count, 0 );
848
    is( $host_items->count, 0 );
849
849
850
    subtest 'test host_items param in items()' => sub {
851
        plan tests => 4;
852
853
        my $items = $biblio->items;
854
        is( $items->count, 1, "Without host_items param we only get the items on the biblio");
855
        $items = $biblio->items({ host_items => 1 });
856
        is( $items->count, 3, "With param host_items we get the biblio items plus analytics");
857
        is( ref($items), 'Koha::Items', "We correctly get an Items object");
858
        is_deeply( [ $items->get_column('itemnumber') ],
859
            [ $item_1->itemnumber, $host_item_1->itemnumber, $host_item_2->itemnumber ] );
860
    };
861
850
    $schema->storage->txn_rollback;
862
    $schema->storage->txn_rollback;
851
};
863
};
852
864
853
- 

Return to bug 33496