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

(-)a/C4/Items.pm (-32 / +48 lines)
Lines 442-477 Returns item record Link Here
442
442
443
=cut
443
=cut
444
444
445
my %default_values_for_mod_from_marc = (
445
our %default_values_for_mod_from_marc;
446
    barcode              => undef, 
446
447
    booksellerid         => undef, 
447
sub _build_default_values_for_mod_marc {
448
    ccode                => undef, 
448
    my ( $frameworkcode ) = @_;
449
    'items.cn_source'    => undef, 
449
    return $default_values_for_mod_from_marc{$frameworkcode} if exists $default_values_for_mod_from_marc{$frameworkcode};
450
    coded_location_qualifier => undef,
450
    my $marc_structure = C4::Biblio::GetMarcStructure( 1 , $frameworkcode );
451
    copynumber           => undef, 
451
    my $default_values = {
452
    damaged              => 0,
452
        barcode => undef,
453
#    dateaccessioned      => undef,
453
        booksellerid => undef,
454
    enumchron            => undef, 
454
        ccode => undef,
455
    holdingbranch        => undef, 
455
        'items.cn_source' => undef,
456
    homebranch           => undef, 
456
        coded_location_qualifier => undef,
457
    itemcallnumber       => undef, 
457
        copynumber => undef,
458
    itemlost             => 0,
458
        damaged => 0,
459
    itemnotes            => undef, 
459
        enumchron => undef,
460
    itype                => undef, 
460
        holdingbranch => undef,
461
    location             => undef, 
461
        homebranch => undef,
462
    permanent_location   => undef,
462
        itemcallnumber => undef,
463
    materials            => undef, 
463
        itemlost => 0,
464
    notforloan           => 0,
464
        itemnotes => undef,
465
    paidfor              => undef, 
465
        itype => undef,
466
    price                => undef, 
466
        location => undef,
467
    replacementprice     => undef, 
467
        permanent_location => undef,
468
    replacementpricedate => undef, 
468
        materials => undef,
469
    restricted           => undef, 
469
        notforloan => 0,
470
    stack                => undef, 
470
        paidfor => undef,
471
    stocknumber          => undef, 
471
        price => undef,
472
    uri                  => undef, 
472
        replacementprice => undef,
473
    withdrawn             => 0,
473
        replacementpricedate => undef,
474
);
474
        restricted => undef,
475
        stack => undef,
476
        stocknumber => undef,
477
        uri => undef,
478
        withdrawn => 0,
479
    };
480
    while ( my ( $field, $default_value ) = each %$default_values ) {
481
        $field =~ s|[^\.]*\.?(.*)|items.$1|;
482
        $default_values_for_mod_from_marc{$frameworkcode}{$field} =
483
          $default_value
484
          if C4::Koha::IsKohaFieldLinked(
485
            { kohafield => $field, frameworkcode => $frameworkcode } );
486
    }
487
    return $default_values_for_mod_from_marc{$frameworkcode};
488
};
475
489
476
sub ModItemFromMarc {
490
sub ModItemFromMarc {
477
    my $item_marc = shift;
491
    my $item_marc = shift;
Lines 485-492 sub ModItemFromMarc { Link Here
485
    my $localitemmarc = MARC::Record->new;
499
    my $localitemmarc = MARC::Record->new;
486
    $localitemmarc->append_fields( $item_marc->field($itemtag) );
500
    $localitemmarc->append_fields( $item_marc->field($itemtag) );
487
    my $item = &TransformMarcToKoha( $dbh, $localitemmarc, $frameworkcode, 'items' );
501
    my $item = &TransformMarcToKoha( $dbh, $localitemmarc, $frameworkcode, 'items' );
488
    foreach my $item_field ( keys %default_values_for_mod_from_marc ) {
502
    my $default_values = _build_default_values_for_mod_marc();
489
        $item->{$item_field} = $default_values_for_mod_from_marc{$item_field} unless (exists $item->{$item_field});
503
    foreach my $item_field ( keys %$default_values ) {
504
        $item->{$item_field} = $default_values->{$item_field}
505
          unless exists $item->{$item_field};
490
    }
506
    }
491
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
507
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
492
508
(-)a/C4/Koha.pm (+25 lines)
Lines 1667-1672 sub GetVariationsOfISBNs { Link Here
1667
    return wantarray ? @isbns : join( " | ", @isbns );
1667
    return wantarray ? @isbns : join( " | ", @isbns );
1668
}
1668
}
1669
1669
1670
=head2 IsKohaFieldLinked
1671
1672
    my $is_linked = IsKohaFieldLinked({
1673
        kohafield => $kohafield,
1674
        frameworkcode => $frameworkcode,
1675
    });
1676
1677
    Return 1 if the field is linked
1678
1679
=cut
1680
1681
sub IsKohaFieldLinked {
1682
    my ( $params ) = @_;
1683
    my $kohafield = $params->{kohafield};
1684
    my $frameworkcode = $params->{frameworkcode} || '';
1685
    my $dbh = C4::Context->dbh;
1686
    my $is_linked = $dbh->selectcol_arrayref( q|
1687
        SELECT COUNT(*)
1688
        FROM marc_subfield_structure
1689
        WHERE frameworkcode = ?
1690
        AND kohafield = ?
1691
    |,{}, $frameworkcode, $kohafield );
1692
    return $is_linked->[0];
1693
}
1694
1670
1;
1695
1;
1671
1696
1672
__END__
1697
__END__
(-)a/t/db_dependent/Koha/IsKohaFieldLinked.t (-1 / +44 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use Test::More;
3
4
use C4::Context;
5
use C4::Koha;
6
7
my $dbh = C4::Context->dbh;
8
$dbh->{RaiseError} = 1;
9
$dbh->{AutoCommit} = 0;
10
11
my $frameworkcode = 'FCUT';
12
$dbh->do( qq|
13
    INSERT INTO marc_subfield_structure(
14
        tagfield, tagsubfield, liblibrarian, kohafield, frameworkcode
15
    ) VALUES
16
        ('952', 'p', 'Barcode', 'items.barcode', '$frameworkcode'),
17
        ('952', '8', 'Collection code', 'items.ccode', '$frameworkcode'),
18
        ('952', '7', 'Not for loan', 'items.notforloan', '$frameworkcode'),
19
        ('952', 'y', 'Koha item type', 'items.itype', '$frameworkcode'),
20
        ('952', 'c', 'Permanent location', '', '$frameworkcode')
21
|);
22
23
is ( C4::Koha::IsKohaFieldLinked( {
24
    kohafield => 'items.barcode',
25
    frameworkcode => $frameworkcode,
26
}), 1, 'items.barcode is linked' );
27
28
is ( C4::Koha::IsKohaFieldLinked( {
29
    kohafield => 'items.notforloan',
30
    frameworkcode => $frameworkcode,
31
}), 1, 'items.notforloan is linked' );
32
33
is ( C4::Koha::IsKohaFieldLinked( {
34
    kohafield => 'notforloan',
35
    frameworkcode => $frameworkcode,
36
}), 0, 'notforloan is not linked' );
37
38
is ( C4::Koha::IsKohaFieldLinked( {
39
    kohafield => 'items.permanent_location',
40
    frameworkcode => $frameworkcode,
41
}), 0, 'items.permanent_location is not linked' );
42
43
44
done_testing;

Return to bug 7817