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

(-)a/C4/Biblio.pm (-5 / +8 lines)
Lines 1191-1203 sub GetMarcFromKohaField { Link Here
1191
1191
1192
=head2 GetMarcSubfieldStructureFromKohaField
1192
=head2 GetMarcSubfieldStructureFromKohaField
1193
1193
1194
    my $str = GetMarcSubfieldStructureFromKohaField( $kohafield );
1194
    my $arrayref = GetMarcSubfieldStructureFromKohaField($kohafield);
1195
    my $hashref  = GetMarcSubfieldStructureFromKohaField($kohafield)->[0];
1195
1196
1196
    Returns marc subfield structure information for $kohafield.
1197
    Returns marc subfield structure information for $kohafield.
1197
    The Default framework is used, since it is authoritative for kohafield
1198
    The Default framework is used, since it is authoritative for kohafield
1198
    mappings.
1199
    mappings.
1199
    In list context returns a list of all hashrefs, since there may be
1200
1200
    multiple mappings. In scalar context the first hashref is returned.
1201
    Since there MAY be multiple mappings (not that often), you receive an
1202
    arrayref of all mappings found. In the second example above the first
1203
    one is picked only. If there are no mappings, you get an empty arrayref
1204
    (so in the call above $hashref will be undefined - without warnings).
1201
1205
1202
=cut
1206
=cut
1203
1207
Lines 1209-1216 sub GetMarcSubfieldStructureFromKohaField { Link Here
1209
    # The next call uses the Default framework since it is AUTHORITATIVE
1213
    # The next call uses the Default framework since it is AUTHORITATIVE
1210
    # for all Koha to MARC mappings.
1214
    # for all Koha to MARC mappings.
1211
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1215
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1212
    return unless $mss->{$kohafield};
1216
    return $mss->{$kohafield} // [];
1213
    return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0];
1214
}
1217
}
1215
1218
1216
=head2 GetXmlBiblio
1219
=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