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

(-)a/Koha/Biblio.pm (-8 / +27 lines)
Lines 429-439 Returns the related Koha::Items object for this biblio Link Here
429
=cut
429
=cut
430
430
431
sub items {
431
sub items {
432
    my ($self) = @_;
432
    my ($self,$params) = @_;
433
433
434
    my $items_rs = $self->_result->items;
434
    my $items_rs = $self->_result->items;
435
435
436
    return Koha::Items->_new_from_dbic( $items_rs );
436
    return Koha::Items->_new_from_dbic( $items_rs ) unless $params->{host_items};
437
438
    my $host_itemnumbers = $self->_host_itemnumbers();
439
    my $params = { -or => [biblionumber => $self->id] };
440
    push @{$params->{'-or'}}, itemnumber => { -in => $host_itemnumbers } if $host_itemnumbers;
441
442
    return Koha::Items->search($params);
437
}
443
}
438
444
439
=head3 host_items
445
=head3 host_items
Lines 450-461 sub host_items { Link Here
450
    return Koha::Items->new->empty
456
    return Koha::Items->new->empty
451
      unless C4::Context->preference('EasyAnalyticalRecords');
457
      unless C4::Context->preference('EasyAnalyticalRecords');
452
458
459
    my $host_itemnumbers = $self->_host_itemnumbers;
460
461
    return Koha::Items->search( { itemnumber => { -in => $host_itemnumbers } } );
462
}
463
464
=head3 _host_itemnumbers
465
466
my $host_itemnumber = $biblio->_host_itemnumbers();
467
468
Return the itemnumbers for analytical items on this record
469
470
=cut
471
472
sub _host_itemnumbers {
473
    my ($self) = @_;
474
453
    my $marcflavour = C4::Context->preference("marcflavour");
475
    my $marcflavour = C4::Context->preference("marcflavour");
454
    my $analyticfield = '773';
476
    my $analyticfield = '773';
455
    if ( $marcflavour eq 'MARC21' ) {
477
    if ( $marcflavour eq 'UNIMARC' ) {
456
        $analyticfield = '773';
457
    }
458
    elsif ( $marcflavour eq 'UNIMARC' ) {
459
        $analyticfield = '461';
478
        $analyticfield = '461';
460
    }
479
    }
461
    my $marc_record = $self->metadata->record;
480
    my $marc_record = $self->metadata->record;
Lines 463-472 sub host_items { Link Here
463
    foreach my $field ( $marc_record->field($analyticfield) ) {
482
    foreach my $field ( $marc_record->field($analyticfield) ) {
464
        push @itemnumbers, $field->subfield('9');
483
        push @itemnumbers, $field->subfield('9');
465
    }
484
    }
466
485
    return \@itemnumbers;
467
    return Koha::Items->search( { itemnumber => { -in => \@itemnumbers } } );
468
}
486
}
469
487
488
470
=head3 itemtype
489
=head3 itemtype
471
490
472
my $itemtype = $biblio->itemtype();
491
my $itemtype = $biblio->itemtype();
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +13 lines)
Lines 804-810 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
804
};
804
};
805
805
806
subtest 'host_items() tests' => sub {
806
subtest 'host_items() tests' => sub {
807
    plan tests => 6;
807
    plan tests => 7;
808
808
809
    $schema->storage->txn_begin;
809
    $schema->storage->txn_begin;
810
810
Lines 840-845 subtest 'host_items() tests' => sub { Link Here
840
    is( ref($host_items),   'Koha::Items' );
840
    is( ref($host_items),   'Koha::Items' );
841
    is( $host_items->count, 0 );
841
    is( $host_items->count, 0 );
842
842
843
    subtest 'test host_items param in items()' => sub {
844
        plan tests => 4;
845
846
        my $items = $biblio->items;
847
        is( $items->count, 1, "Without host_items param we only get the items on the biblio");
848
        $items = $biblio->items({ host_items => 1 });
849
        is( $items->count, 3, "With param host_items we get the biblio items plus analytics");
850
        is( ref($items), 'Koha::Items', "We correctly get an Items object");
851
        is_deeply( [ $items->get_column('itemnumber') ],
852
            [ $item_1->itemnumber, $host_item_1->itemnumber, $host_item_2->itemnumber ] );
853
    };
854
843
    $schema->storage->txn_rollback;
855
    $schema->storage->txn_rollback;
844
};
856
};
845
857
846
- 

Return to bug 33167