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

(-)a/C4/Biblio.pm (-16 / +8 lines)
Lines 1075-1096 sub GetMarcSubfieldStructure { Link Here
1075
sub GetMarcFromKohaField {
1075
sub GetMarcFromKohaField {
1076
    my ( $kohafield ) = @_;
1076
    my ( $kohafield ) = @_;
1077
    return unless $kohafield;
1077
    return unless $kohafield;
1078
1078
    # The next call uses the Default framework since it is AUTHORITATIVE
1079
    my $cache     = Koha::Caches->get_instance();
1079
    # for all Koha to MARC mappings.
1080
    my $cache_key = "MarcFromKohaField-$kohafield";
1080
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1081
    my $cached    = $cache->get_from_cache($cache_key);
1081
    my @retval;
1082
    if ( !defined $cached ) {
1082
    foreach( @{ $mss->{$kohafield} } ) {
1083
        # The next call uses the Default framework since it is AUTHORITATIVE
1083
        push @retval, $_->{tagfield}, $_->{tagsubfield};
1084
        # for all Koha to MARC mappings.
1084
    }
1085
        my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1085
    return wantarray ? @retval : ( @retval ? $retval[0] : undef );
1086
        my @retval;
1087
        foreach( @{ $mss->{$kohafield} } ) {
1088
            push @retval, $_->{tagfield}, $_->{tagsubfield};
1089
        }
1090
        $cached = \@retval;
1091
        $cache->set_in_cache( $cache_key, $cached );
1092
    }
1093
    return wantarray ? @$cached : ( @$cached ? $cached->[0] : undef );
1094
}
1086
}
1095
1087
1096
=head2 GetMarcSubfieldStructureFromKohaField
1088
=head2 GetMarcSubfieldStructureFromKohaField
(-)a/C4/Items.pm (-20 / +16 lines)
Lines 1354-1378 Returns an array of MARC::Record objects of the items for the biblio. Link Here
1354
sub GetMarcItemFields {
1354
sub GetMarcItemFields {
1355
    my ( $biblionumber, $itemnumbers, $hidingrules ) = @_;
1355
    my ( $biblionumber, $itemnumbers, $hidingrules ) = @_;
1356
1356
1357
    my $item_level_itype = C4::Context->preference('item-level_itypes');
1357
    my $params = {
1358
    # This is so much faster than using Koha::Items->search that it makes sense even if it's ugly.
1358
        biblionumber => $biblionumber
1359
    my $query = 'SELECT * FROM items WHERE biblionumber = ?';
1359
    };
1360
    if (@$itemnumbers) {
1360
    if (@$itemnumbers) {
1361
        $query .= ' AND itemnumber IN (' . join(',', @$itemnumbers) . ')';
1361
        my @itemnumberlist;
1362
        foreach my $itemnumber (@$itemnumbers) {
1363
            push @itemnumberlist, {itemnumber => $itemnumber};
1364
        }
1365
        $params->{-or} = \@itemnumberlist;
1362
    }
1366
    }
1363
    my $sth = C4::Context->dbh->prepare($query);
1367
    my $items = Koha::Items->search($params);
1364
    $sth->execute($biblionumber);
1365
    my $items = $sth->fetchall_arrayref({});
1366
    $sth->finish();
1367
    my @item_fields;
1368
    my @item_fields;
1368
    my ($itemtag, $itemsubfield) = GetMarcFromKohaField('items.itemnumber');
1369
    my ($itemtag, $itemsubfield) = GetMarcFromKohaField('items.itemnumber');
1369
1370
1370
    ITEMLOOP: foreach my $item (@$items) {
1371
    ITEMLOOP: while ( my $item = $items->next() ) {
1372
1373
        my $item_unblessed = $item->unblessed;
1374
        $item_unblessed->{itype} = $item->effective_itemtype() unless $item_unblessed->{itype};
1371
1375
1372
        # Check hiding rules
1376
        # Check hiding rules
1373
        if (defined $hidingrules) {
1377
        if (defined $hidingrules) {
1374
            foreach my $field (keys %$hidingrules) {
1378
            foreach my $field (keys %$hidingrules) {
1375
                my $val = $item->{$field};
1379
                my $val = $item_unblessed->{$field};
1376
                $val = '' unless defined $val;
1380
                $val = '' unless defined $val;
1377
1381
1378
                # If the results matches the values in the hiding rules, skip the item
1382
                # If the results matches the values in the hiding rules, skip the item
Lines 1382-1398 sub GetMarcItemFields { Link Here
1382
            }
1386
            }
1383
        }
1387
        }
1384
1388
1385
        # Set correct item type
1386
        if (!$item_level_itype || !$item->{itype}) {
1387
            warn 'item-level_itypes set but no itemtype set for item (' . $item->{itemnumber} . ')' if (!$item->{itype});
1388
            my $biblioitem = Koha::Biblioitems->find($item->{biblioitemnumber});
1389
            $item->{itype} = $biblioitem->itemtype();
1390
        }
1391
1392
        my $mungeditem = {
1389
        my $mungeditem = {
1393
            map {
1390
            map {
1394
                defined($item->{$_}) && $item->{$_} ne '' ? ("items.$_" => $item->{$_}) : ()
1391
                defined($item_unblessed->{$_}) && $item_unblessed->{$_} ne '' ? ("items.$_" => $item_unblessed->{$_}) : ()
1395
            } keys %{ $item }
1392
            } keys %{ $item_unblessed }
1396
        };
1393
        };
1397
        my $itemmarc = TransformKohaToMarc($mungeditem);
1394
        my $itemmarc = TransformKohaToMarc($mungeditem);
1398
1395
1399
- 

Return to bug 20664