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

(-)a/C4/Biblio.pm (-5 / +7 lines)
Lines 1191-1208 sub GetMarcFromKohaField { Link Here
1191
1191
1192
=head2 GetMarcSubfieldStructureFromKohaField
1192
=head2 GetMarcSubfieldStructureFromKohaField
1193
1193
1194
    my $str = GetMarcSubfieldStructureFromKohaField( $kohafield );
1194
    my $str = GetMarcSubfieldStructureFromKohaField( $kohafield, { list => 0|1 } );
1195
1195
1196
    Returns marc subfield structure information for $kohafield.
1196
    Returns marc subfield structure information for $kohafield.
1197
    The Default framework is used, since it is authoritative for kohafield
1197
    The Default framework is used, since it is authoritative for kohafield
1198
    mappings.
1198
    mappings.
1199
    In list context returns a list of all hashrefs, since there may be
1199
    Normally returns first subfield structure hash found.
1200
    multiple mappings. In scalar context the first hashref is returned.
1200
    With list parameter, returns an arrayref of hashes. (NOTE: replace
1201
    previous  wantarray construct. Parameter is currently not yet used as
1202
    of 10/2023.)
1201
1203
1202
=cut
1204
=cut
1203
1205
1204
sub GetMarcSubfieldStructureFromKohaField {
1206
sub GetMarcSubfieldStructureFromKohaField {
1205
    my ( $kohafield ) = @_;
1207
    my ( $kohafield, $params ) = @_;
1206
1208
1207
    return unless $kohafield;
1209
    return unless $kohafield;
1208
1210
Lines 1210-1216 sub GetMarcSubfieldStructureFromKohaField { Link Here
1210
    # for all Koha to MARC mappings.
1212
    # for all Koha to MARC mappings.
1211
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1213
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1212
    return unless $mss->{$kohafield};
1214
    return unless $mss->{$kohafield};
1213
    return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0];
1215
    return $params && $params->{list} ? $mss->{$kohafield} : $mss->{$kohafield}->[0];
1214
}
1216
}
1215
1217
1216
=head2 GetXmlBiblio
1218
=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');    # 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);    # 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 (-7 / +9 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 => 26;
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 121-131 subtest 'GetMarcSubfieldStructureFromKohaField' => sub { Link Here
121
    is($marc_subfield_structure->{kohafield}, 'biblio.biblionumber', "Result is the good result");
121
    is($marc_subfield_structure->{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->{tagfield}, qr/^\d{3}$/, "tagfield is a valid tagfield");
123
123
124
    # Add a test for list context (BZ 10306)
124
    # Add a test for list parameter
125
    my @results = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber');
125
    my $results = GetMarcSubfieldStructureFromKohaField( 'biblio.biblionumber', { list => 1 } );
126
    is( @results, 1, 'We expect only one mapping' );
126
    is( ref $results, "ARRAY", "Result is an arrayref when using list => 1" );
127
    is_deeply( $results[0], $marc_subfield_structure,
127
    is( @$results,    1,       'We expect only one mapping' );
128
        'The first entry should be the same hashref as we had before' );
128
    is_deeply(
129
        $results->[0], $marc_subfield_structure,
130
        'The first entry should be the same hashref as we had before'
131
    );
129
132
130
    # foo.bar does not exist so this should return undef
133
    # foo.bar does not exist so this should return undef
131
    $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('foo.bar');
134
    $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('foo.bar');
132
- 

Return to bug 19097