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

(-)a/Koha/Biblio.pm (+55 lines)
Lines 88-93 sub metadata { Link Here
88
    return Koha::Biblio::Metadata->_new_from_dbic($metadata);
88
    return Koha::Biblio::Metadata->_new_from_dbic($metadata);
89
}
89
}
90
90
91
=head3 metadata_record
92
93
    my $record = $biblio->metadata_record(
94
        {
95
            [ embed_items => 1|0,
96
              opac        => 1|0,
97
              patron      => $patron, ]
98
        }
99
    );
100
101
Returns the metadata serialized as appropriate for the metadata object
102
type. Currently only I<MARC::Record> objects are returned.
103
104
=cut
105
106
sub metadata_record {
107
    my ($self, $params) = @_;
108
109
    my $patron = $params->{patron};
110
111
    my $record = $self->metadata->record;
112
113
    if ( $params->{embed_items} or $params->{opac} ) {
114
        # There's need for a RecordProcessor, let's do it!
115
        my @filters;
116
        my $options = {};
117
118
        if ($params->{embed_items}) {
119
            push @filters, 'EmbedItems';
120
            $options->{items} = $self->items->filter_by_visible_in_opac(
121
                {
122
                    ( $params->{patron} ? patron => $params->{patron} : ())
123
                }
124
            );
125
        }
126
127
        if ( $params->{opac} ) {
128
            push @filters, 'ViewPolicy';
129
            $options->{interface}     = 'opac';
130
            $options->{frameworkcode} = $self->frameworkcode;
131
        }
132
133
        my $rp = Koha::RecordProcessor->new(
134
            {
135
                filters => \@filters,
136
                options => $options
137
            }
138
        );
139
140
        $rp->process( $record );
141
    }
142
143
    return $record;
144
}
145
91
=head3 orders
146
=head3 orders
92
147
93
my $orders = $biblio->orders();
148
my $orders = $biblio->orders();
(-)a/Koha/Biblio/Metadata.pm (-8 / +4 lines)
Lines 165-178 sub _embed_items { Link Here
165
        if ( $opac ) {
165
        if ( $opac ) {
166
            $items = $items->filter_by_visible_in_opac({ patron => $patron });
166
            $items = $items->filter_by_visible_in_opac({ patron => $patron });
167
        }
167
        }
168
        my @itemnumbers = $items->get_column('itemnumber');
169
        my @item_fields;
170
        for my $itemnumber ( @itemnumbers ) {
171
            my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
172
            push @item_fields, $item_marc->field($itemtag);
173
        }
174
        $record->append_fields(@item_fields);
175
168
169
        # convert items to MARC::Field objects
170
        my @item_fields = map { $_->as_marc_field } @{$items->as_list};
171
172
        $record->append_fields(@item_fields);
176
    }
173
    }
177
    else {
174
    else {
178
        Koha::Exceptions::Metadata->throw(
175
        Koha::Exceptions::Metadata->throw(
179
- 

Return to bug 31224