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

(-)a/C4/Record.pm (-2 / +8 lines)
Lines 592-611 sub marcrecord2csv { Link Here
592
592
593
                # Or a field
593
                # Or a field
594
                } else {
594
                } else {
595
                    my $authvalues = Koha::AuthorisedValues->get_descriptions_by_marc_field(
596
                        { frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, } );
597
595
598
                    foreach my $field ( @fields ) {
596
                    foreach my $field ( @fields ) {
599
                        my $value;
597
                        my $value;
600
598
601
                        # If it is a control field
599
                        # If it is a control field
602
                        if ($field->is_control_field) {
600
                        if ($field->is_control_field) {
601
                            my $authvalues = Koha::AuthorisedValues->get_descriptions_by_marc_field(
602
                                { frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, } );
603
                            $value = defined $authvalues->{$field->as_string} ? $authvalues->{$field->as_string} : $field->as_string;
603
                            $value = defined $authvalues->{$field->as_string} ? $authvalues->{$field->as_string} : $field->as_string;
604
                        } else {
604
                        } else {
605
                            # If it is a field, we gather all subfields, joined by the subfield separator
605
                            # If it is a field, we gather all subfields, joined by the subfield separator
606
                            my @subvaluesarray;
606
                            my @subvaluesarray;
607
                            my @subfields = $field->subfields;
607
                            my @subfields = $field->subfields;
608
                            foreach my $subfield (@subfields) {
608
                            foreach my $subfield (@subfields) {
609
                                my $authvalues = Koha::AuthorisedValues->get_descriptions_by_marc_field(
610
                                    {
611
                                        frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag},
612
                                        tagsubfield   => $subfield->[0],
613
                                    }
614
                                );
609
                                push (@subvaluesarray, defined $authvalues->{$subfield->[1]} ? $authvalues->{$subfield->[1]} : $subfield->[1]);
615
                                push (@subvaluesarray, defined $authvalues->{$subfield->[1]} ? $authvalues->{$subfield->[1]} : $subfield->[1]);
610
                            }
616
                            }
611
                            $value = join ($subfieldseparator, @subvaluesarray);
617
                            $value = join ($subfieldseparator, @subvaluesarray);
(-)a/t/db_dependent/AuthorisedValues.t (-2 / +27 lines)
Lines 156-172 subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v Link Here
156
    $mss->delete if $mss;
156
    $mss->delete if $mss;
157
    $mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => '5', frameworkcode => '' } );
157
    $mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => '5', frameworkcode => '' } );
158
    $mss->delete if $mss;
158
    $mss->delete if $mss;
159
    $mss = Koha::MarcSubfieldStructures->search( { tagfield => '003', frameworkcode => '' } );
160
    $mss->delete if $mss;
159
    Koha::AuthorisedValueCategory->new( { category_name => 'TEST' } )->store;
161
    Koha::AuthorisedValueCategory->new( { category_name => 'TEST' } )->store;
162
    Koha::AuthorisedValueCategory->new( { category_name => 'CONTROL_TEST' } )->store;
160
    Koha::AuthorisedValueCategory->new( { category_name => 'ANOTHER_4_TESTS' } )->store;
163
    Koha::AuthorisedValueCategory->new( { category_name => 'ANOTHER_4_TESTS' } )->store;
161
    Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => '', authorised_value => 'TEST', kohafield => 'items.location' } )->store;
164
    Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => '', authorised_value => 'TEST', kohafield => 'items.location' } )->store;
162
    Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => 'ACQ', authorised_value => 'TEST', kohafield => 'items.location' } )->store;
165
    Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => 'ACQ', authorised_value => 'TEST', kohafield => 'items.location' } )->store;
163
    Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'd', frameworkcode => '', authorised_value => 'ANOTHER_4_TESTS', kohafield => 'items.another_field' } )->store;
166
    Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'd', frameworkcode => '', authorised_value => 'ANOTHER_4_TESTS', kohafield => 'items.another_field' } )->store;
164
    Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => '5', frameworkcode => '', authorised_value => 'restricted_for_testing', kohafield => 'items.restricted' } )->store;
167
    Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => '5', frameworkcode => '', authorised_value => 'restricted_for_testing', kohafield => 'items.restricted' } )->store;
168
    Koha::MarcSubfieldStructure->new( { tagfield => '003', frameworkcode => '', authorised_value => 'CONTROL_TEST', } )->store;
165
    Koha::AuthorisedValue->new( { category => 'TEST', authorised_value => 'location_1', lib => 'location_1' } )->store;
169
    Koha::AuthorisedValue->new( { category => 'TEST', authorised_value => 'location_1', lib => 'location_1' } )->store;
166
    Koha::AuthorisedValue->new( { category => 'TEST', authorised_value => 'location_2', lib => 'location_2' } )->store;
170
    Koha::AuthorisedValue->new( { category => 'TEST', authorised_value => 'location_2', lib => 'location_2' } )->store;
167
    Koha::AuthorisedValue->new( { category => 'TEST', authorised_value => 'location_3', lib => 'location_3' } )->store;
171
    Koha::AuthorisedValue->new( { category => 'TEST', authorised_value => 'location_3', lib => 'location_3' } )->store;
168
    Koha::AuthorisedValue->new( { category => 'ANOTHER_4_TESTS', authorised_value => 'an_av' } )->store;
172
    Koha::AuthorisedValue->new( { category => 'ANOTHER_4_TESTS', authorised_value => 'an_av' } )->store;
169
    Koha::AuthorisedValue->new( { category => 'ANOTHER_4_TESTS', authorised_value => 'another_av' } )->store;
173
    Koha::AuthorisedValue->new( { category => 'ANOTHER_4_TESTS', authorised_value => 'another_av' } )->store;
174
    Koha::AuthorisedValue->new( { category => 'CONTROL_TEST', authorised_value => 'lib1', lib => 'lib1' } )->store;
175
    Koha::AuthorisedValue->new( { category => 'CONTROL_TEST', authorised_value => 'lib2', lib => 'lib2' } )->store;
170
    subtest 'search_by_marc_field' => sub {
176
    subtest 'search_by_marc_field' => sub {
171
        plan tests => 4;
177
        plan tests => 4;
172
        my $avs;
178
        my $avs;
Lines 254-260 subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v Link Here
254
    };
260
    };
255
261
256
    subtest 'get_descriptions_by_marc_field' => sub {
262
    subtest 'get_descriptions_by_marc_field' => sub {
257
        plan tests => 1;
263
        plan tests => 4;
264
265
        my $control_descriptions = Koha::AuthorisedValues->get_descriptions_by_marc_field(
266
            { frameworkcode => '', tagfield => '003', } );
267
        is_deeply(
268
            $control_descriptions,
269
            {
270
                'lib1' => 'lib1',
271
                'lib2' => 'lib2',
272
            },
273
        );
274
275
        my $control_descriptions_cached = Koha::AuthorisedValues->get_descriptions_by_marc_field(
276
            { frameworkcode => '', tagfield => '003', } );
277
278
        is("$control_descriptions","$control_descriptions_cached","Same memory address used proves cached control desc data");
279
258
        my $descriptions = Koha::AuthorisedValues->get_descriptions_by_marc_field(
280
        my $descriptions = Koha::AuthorisedValues->get_descriptions_by_marc_field(
259
            { frameworkcode => '', tagfield => '952', tagsubfield => 'c' } );
281
            { frameworkcode => '', tagfield => '952', tagsubfield => 'c' } );
260
        is_deeply(
282
        is_deeply(
Lines 265-270 subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v Link Here
265
                'location_3' => 'location_3',
287
                'location_3' => 'location_3',
266
            },
288
            },
267
        );
289
        );
290
291
        my $descriptions_cached = Koha::AuthorisedValues->get_descriptions_by_marc_field(
292
            { frameworkcode => '', tagfield => '952', tagsubfield => 'c' } );
293
        is("$descriptions","$descriptions_cached","Same memory address used proves cached desc data");
268
    };
294
    };
269
295
270
    subtest 'authorised_values' => sub {
296
    subtest 'authorised_values' => sub {
271
- 

Return to bug 35588