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

(-)a/Koha/Exporter/Record.pm (+8 lines)
Lines 10-15 use C4::Record; Link Here
10
use Koha::Biblios;
10
use Koha::Biblios;
11
use Koha::CsvProfiles;
11
use Koha::CsvProfiles;
12
use Koha::Logger;
12
use Koha::Logger;
13
use Koha::RecordProcessor;
13
use List::Util qw( all any );
14
use List::Util qw( all any );
14
15
15
sub _get_record_for_export {
16
sub _get_record_for_export {
Lines 120-125 sub _get_biblio_for_export { Link Here
120
    my $itemnumbers  = $params->{itemnumbers};
121
    my $itemnumbers  = $params->{itemnumbers};
121
    my $export_items = $params->{export_items} // 1;
122
    my $export_items = $params->{export_items} // 1;
122
    my $only_export_items_for_branches = $params->{only_export_items_for_branches};
123
    my $only_export_items_for_branches = $params->{only_export_items_for_branches};
124
    my $embed_analytical_items = $params->{embed_analytical_items};
123
125
124
    my $biblio = Koha::Biblios->find($biblionumber);
126
    my $biblio = Koha::Biblios->find($biblionumber);
125
    my $record = eval { $biblio->metadata->record };
127
    my $record = eval { $biblio->metadata->record };
Lines 147-152 sub _get_biblio_for_export { Link Here
147
            }
149
            }
148
        }
150
        }
149
    }
151
    }
152
    
153
    if ( $embed_analytical_items && C4::Context->preference('EasyAnalyticalRecords') ) {
154
        my $eai_record_processor = Koha::RecordProcessor->new( { filters => 'EmbedAnalyticalItems' } );
155
        $eai_record_processor->process($record);
156
    }
157
150
    return $record;
158
    return $record;
151
}
159
}
152
160
(-)a/Koha/Filter/MARC/EmbedAnalyticalItems.pm (+74 lines)
Line 0 Link Here
1
package Koha::Filter::MARC::EmbedAnalyticalItems;
2
3
# Copyright 2022 Biblibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head1 NAME
21
22
Koha::Filter::MARC::EmbedAnalyticalItems - Appends analytical items information on MARC::Record objects.
23
24
=head1 DESCRIPTION
25
26
Filter to embed analytical items information into MARC::Record objects.
27
28
Does nothing if system preference EasyAnalyticalRecords is disabled.
29
30
=cut
31
32
use Modern::Perl;
33
34
use Koha::Item;
35
36
use base qw(Koha::RecordProcessor::Base);
37
our $NAME = 'EmbedAnalyticalItems';
38
39
=head2 filter
40
41
Embed analytical items into the MARC::Record object.
42
43
=cut
44
45
sub filter {
46
    my $self   = shift;
47
    my $record = shift;
48
49
    return unless defined $record and ref($record) eq 'MARC::Record';
50
51
    return $record unless C4::Context->preference('EasyAnalyticalRecords');
52
53
    my @item_fields;
54
    my $marcflavour = C4::Context->preference('marcflavour');
55
    my $analyticfield = '773';
56
    if ( $marcflavour eq 'MARC21' ) {
57
        $analyticfield = '773';
58
    }
59
    elsif ( $marcflavour eq 'UNIMARC' ) {
60
        $analyticfield = '461';
61
    }
62
    foreach my $field ( $record->field($analyticfield) ) {
63
        my $item = Koha::Item->find($field->subfield('9'));
64
        next unless defined $item;
65
        my $item_field = $item->as_marc_field;
66
        # TODO barcode
67
        push @item_fields, $item_field;
68
    }
69
    $record->append_fields(@item_fields);
70
71
    return $record;
72
}
73
74
1;
(-)a/misc/export_records.pl (-1 / +8 lines)
Lines 54-59 my ( Link Here
54
    $start_accession,
54
    $start_accession,
55
    $end_accession,
55
    $end_accession,
56
    $marc_conditions,
56
    $marc_conditions,
57
    $embed_analytical_items,
57
    $help
58
    $help
58
);
59
);
59
60
Lines 78-83 GetOptions( Link Here
78
    'start_accession=s'       => \$start_accession,
79
    'start_accession=s'       => \$start_accession,
79
    'end_accession=s'         => \$end_accession,
80
    'end_accession=s'         => \$end_accession,
80
    'marc_conditions=s'       => \$marc_conditions,
81
    'marc_conditions=s'       => \$marc_conditions,
82
    'embed_analytical_items' => \$embed_analytical_items,
81
    'h|help|?'                => \$help
83
    'h|help|?'                => \$help
82
) || pod2usage(1);
84
) || pod2usage(1);
83
85
Lines 256-261 else { Link Here
256
            csv_profile_id     => $csv_profile_id,
258
            csv_profile_id     => $csv_profile_id,
257
            export_items       => (not $dont_export_items),
259
            export_items       => (not $dont_export_items),
258
            clean              => $clean || 0,
260
            clean              => $clean || 0,
261
            embed_analytical_items => $embed_analytical_items || 0,
259
        }
262
        }
260
    );
263
    );
261
}
264
}
Lines 385-390 Print a brief help message. Link Here
385
                                "exists(<marc_target>)" will include marc records where
388
                                "exists(<marc_target>)" will include marc records where
386
                                no <marc_target> exists.
389
                                no <marc_target> exists.
387
390
391
=item B<--embed_analytical_items>
392
393
 --embed_analytical_items      Embed analytical items in bibliographic record.
394
                               Only valid with system preference EasyAnalyticalRecords enabled.
395
388
=back
396
=back
389
397
390
=head1 AUTHOR
398
=head1 AUTHOR
391
- 

Return to bug 32463