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

(-)a/Koha/Biblio.pm (-8 / +27 lines)
Lines 443-453 Returns the related Koha::Items object for this biblio Link Here
443
=cut
443
=cut
444
444
445
sub items {
445
sub items {
446
    my ($self) = @_;
446
    my ($self,$params) = @_;
447
447
448
    my $items_rs = $self->_result->items;
448
    my $items_rs = $self->_result->items;
449
449
450
    return Koha::Items->_new_from_dbic( $items_rs );
450
    return Koha::Items->_new_from_dbic( $items_rs ) unless $params->{host_items};
451
452
    my $host_itemnumbers = $self->_host_itemnumbers();
453
    my $params = { -or => [biblionumber => $self->id] };
454
    push @{$params->{'-or'}}, itemnumber => { -in => $host_itemnumbers } if $host_itemnumbers;
455
456
    return Koha::Items->search($params);
451
}
457
}
452
458
453
=head3 host_items
459
=head3 host_items
Lines 464-475 sub host_items { Link Here
464
    return Koha::Items->new->empty
470
    return Koha::Items->new->empty
465
      unless C4::Context->preference('EasyAnalyticalRecords');
471
      unless C4::Context->preference('EasyAnalyticalRecords');
466
472
473
    my $host_itemnumbers = $self->_host_itemnumbers;
474
475
    return Koha::Items->search( { itemnumber => { -in => $host_itemnumbers } } );
476
}
477
478
=head3 _host_itemnumbers
479
480
my $host_itemnumber = $biblio->_host_itemnumbers();
481
482
Return the itemnumbers for analytical items on this record
483
484
=cut
485
486
sub _host_itemnumbers {
487
    my ($self) = @_;
488
467
    my $marcflavour = C4::Context->preference("marcflavour");
489
    my $marcflavour = C4::Context->preference("marcflavour");
468
    my $analyticfield = '773';
490
    my $analyticfield = '773';
469
    if ( $marcflavour eq 'MARC21' ) {
491
    if ( $marcflavour eq 'UNIMARC' ) {
470
        $analyticfield = '773';
471
    }
472
    elsif ( $marcflavour eq 'UNIMARC' ) {
473
        $analyticfield = '461';
492
        $analyticfield = '461';
474
    }
493
    }
475
    my $marc_record = $self->metadata->record;
494
    my $marc_record = $self->metadata->record;
Lines 477-486 sub host_items { Link Here
477
    foreach my $field ( $marc_record->field($analyticfield) ) {
496
    foreach my $field ( $marc_record->field($analyticfield) ) {
478
        push @itemnumbers, $field->subfield('9');
497
        push @itemnumbers, $field->subfield('9');
479
    }
498
    }
480
499
    return \@itemnumbers;
481
    return Koha::Items->search( { itemnumber => { -in => \@itemnumbers } } );
482
}
500
}
483
501
502
484
=head3 itemtype
503
=head3 itemtype
485
504
486
my $itemtype = $biblio->itemtype();
505
my $itemtype = $biblio->itemtype();
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +13 lines)
Lines 799-805 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
799
};
799
};
800
800
801
subtest 'host_items() tests' => sub {
801
subtest 'host_items() tests' => sub {
802
    plan tests => 6;
802
    plan tests => 7;
803
803
804
    $schema->storage->txn_begin;
804
    $schema->storage->txn_begin;
805
805
Lines 835-840 subtest 'host_items() tests' => sub { Link Here
835
    is( ref($host_items),   'Koha::Items' );
835
    is( ref($host_items),   'Koha::Items' );
836
    is( $host_items->count, 0 );
836
    is( $host_items->count, 0 );
837
837
838
    subtest 'test host_items param in items()' => sub {
839
        plan tests => 4;
840
841
        my $items = $biblio->items;
842
        is( $items->count, 1, "Without host_items param we only get the items on the biblio");
843
        $items = $biblio->items({ host_items => 1 });
844
        is( $items->count, 3, "With param host_items we get the biblio items plus analytics");
845
        is( ref($items), 'Koha::Items', "We correctly get an Items object");
846
        is_deeply( [ $items->get_column('itemnumber') ],
847
            [ $item_1->itemnumber, $host_item_1->itemnumber, $host_item_2->itemnumber ] );
848
    };
849
838
    $schema->storage->txn_rollback;
850
    $schema->storage->txn_rollback;
839
};
851
};
840
852
841
- 

Return to bug 33167