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

(-)a/C4/Biblio.pm (-5 / +8 lines)
Lines 1199-1211 sub GetMarcFromKohaField { Link Here
1199
1199
1200
=head2 GetMarcSubfieldStructureFromKohaField
1200
=head2 GetMarcSubfieldStructureFromKohaField
1201
1201
1202
    my $str = GetMarcSubfieldStructureFromKohaField( $kohafield );
1202
    my $arrayref = GetMarcSubfieldStructureFromKohaField($kohafield);
1203
    my $hashref  = GetMarcSubfieldStructureFromKohaField($kohafield)->[0];
1203
1204
1204
    Returns marc subfield structure information for $kohafield.
1205
    Returns marc subfield structure information for $kohafield.
1205
    The Default framework is used, since it is authoritative for kohafield
1206
    The Default framework is used, since it is authoritative for kohafield
1206
    mappings.
1207
    mappings.
1207
    In list context returns a list of all hashrefs, since there may be
1208
1208
    multiple mappings. In scalar context the first hashref is returned.
1209
    Since there MAY be multiple mappings (not that often), you receive an
1210
    arrayref of all mappings found. In the second example above the first
1211
    one is picked only. If there are no mappings, you get an empty arrayref
1212
    (so in the call above $hashref will be undefined - without warnings).
1209
1213
1210
=cut
1214
=cut
1211
1215
Lines 1217-1224 sub GetMarcSubfieldStructureFromKohaField { Link Here
1217
    # The next call uses the Default framework since it is AUTHORITATIVE
1221
    # The next call uses the Default framework since it is AUTHORITATIVE
1218
    # for all Koha to MARC mappings.
1222
    # for all Koha to MARC mappings.
1219
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1223
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1220
    return unless $mss->{$kohafield};
1224
    return $mss->{$kohafield} // [];
1221
    return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0];
1222
}
1225
}
1223
1226
1224
=head2 GetXmlBiblio
1227
=head2 GetXmlBiblio
(-)a/reports/acquisitions_stats.pl (-1 / +1 lines)
Lines 173-179 else { Link Here
173
173
174
    my $libraries = Koha::Libraries->search({}, { order_by => 'branchname' });
174
    my $libraries = Koha::Libraries->search({}, { order_by => 'branchname' });
175
175
176
    my $ccode_subfield_structure = GetMarcSubfieldStructureFromKohaField('items.ccode');
176
    my $ccode_subfield_structure = GetMarcSubfieldStructureFromKohaField('items.ccode')->[0];    # assuming one result..
177
    my $ccode_label;
177
    my $ccode_label;
178
    my $ccode_avlist;
178
    my $ccode_avlist;
179
    if($ccode_subfield_structure) {
179
    if($ccode_subfield_structure) {
(-)a/reports/catalogue_stats.pl (-1 / +1 lines)
Lines 118-124 if ($do_it) { Link Here
118
    my @locations = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } );
118
    my @locations = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } );
119
119
120
    foreach my $kohafield (qw(items.notforloan items.materials)) {
120
    foreach my $kohafield (qw(items.notforloan items.materials)) {
121
        my $subfield_structure = GetMarcSubfieldStructureFromKohaField($kohafield);
121
        my $subfield_structure = GetMarcSubfieldStructureFromKohaField($kohafield)->[0];    # assuming one result..
122
        if($subfield_structure) {
122
        if($subfield_structure) {
123
            my $avlist;
123
            my $avlist;
124
            my $avcategory = $subfield_structure->{authorised_value};
124
            my $avcategory = $subfield_structure->{authorised_value};
(-)a/t/db_dependent/Biblio.t (-14 / +14 lines)
Lines 102-108 subtest 'AddBiblio' => sub { Link Here
102
};
102
};
103
103
104
subtest 'GetMarcSubfieldStructureFromKohaField' => sub {
104
subtest 'GetMarcSubfieldStructureFromKohaField' => sub {
105
    plan tests => 25;
105
    plan tests => 27;
106
106
107
    my @columns = qw(
107
    my @columns = qw(
108
        tagfield tagsubfield liblibrarian libopac repeatable mandatory kohafield tab
108
        tagfield tagsubfield liblibrarian libopac repeatable mandatory kohafield tab
Lines 113-135 subtest 'GetMarcSubfieldStructureFromKohaField' => sub { Link Here
113
    # biblio.biblionumber must be mapped so this should return something
113
    # biblio.biblionumber must be mapped so this should return something
114
    my $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber');
114
    my $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber');
115
115
116
    ok(defined $marc_subfield_structure, "There is a result");
116
    is( ref $marc_subfield_structure, "ARRAY", "Result is an arrayref" );
117
    is(ref $marc_subfield_structure, "HASH", "Result is a hashref");
117
    is( @$marc_subfield_structure, 1, 'Expecting one hit only' );
118
    foreach my $col (@columns) {
118
    foreach my $col (@columns) {
119
        ok(exists $marc_subfield_structure->{$col}, "Hashref contains key '$col'");
119
        ok( exists $marc_subfield_structure->[0]->{$col}, "Hashref contains key '$col'" );
120
    }
120
    }
121
    is($marc_subfield_structure->{kohafield}, 'biblio.biblionumber', "Result is the good result");
121
    is( $marc_subfield_structure->[0]->{kohafield}, 'biblio.biblionumber', "Result is the good result" );
122
    like($marc_subfield_structure->{tagfield}, qr/^\d{3}$/, "tagfield is a valid tagfield");
122
    like( $marc_subfield_structure->[0]->{tagfield}, qr/^\d{3}$/, "tagfield is a valid tagfield" );
123
123
124
    # Add a test for list context (BZ 10306)
124
    # Multiple mappings expected for kohafield biblio.copyrightdate (in 260, 264)
125
    my @results = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber');
125
    $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('biblio.copyrightdate');
126
    is( @results, 1, 'We expect only one mapping' );
126
    is( ref $marc_subfield_structure, "ARRAY", "Result is again an arrayref" );
127
    is_deeply( $results[0], $marc_subfield_structure,
127
    is( @$marc_subfield_structure,    2,       'We expect two hits' );
128
        'The first entry should be the same hashref as we had before' );
128
    ok( exists $marc_subfield_structure->[0]->{tagsubfield}, 'Testing a random column for existence in 1st hash' );
129
    ok( exists $marc_subfield_structure->[1]->{hidden}, 'Testing a random column for existence in 2nd hash' );
129
130
130
    # foo.bar does not exist so this should return undef
131
    # foo.bar does not exist so this should return []
131
    $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('foo.bar');
132
    $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('foo.bar');
132
    is($marc_subfield_structure, undef, "invalid kohafield returns undef");
133
    is_deeply( $marc_subfield_structure, [], "invalid kohafield returns empty arrayref" );
133
134
134
};
135
};
135
136
136
- 

Return to bug 19097