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

(-)a/Koha/Object/Mixin/AdditionalFields.pm (-1 / +79 lines)
Lines 196-201 sub additional_field_values { Link Here
196
    return Koha::AdditionalFieldValues->_new_from_dbic( $afv_rs );
196
    return Koha::AdditionalFieldValues->_new_from_dbic( $afv_rs );
197
}
197
}
198
198
199
=head3 extended_attributes
200
201
REST API embed of additional_field_values
202
203
=cut
204
205
sub extended_attributes {
206
    my ($self, $extended_attributes) = @_;
207
208
    if ($extended_attributes) {
209
        $self->set_additional_fields($extended_attributes);
210
    }
211
    my $afv_rs = $self->_result->extended_attributes;
212
    return Koha::AdditionalFieldValues->_new_from_dbic($afv_rs);
213
}
214
215
=head3 strings_map
216
217
Returns a map of column name to string representations including the string,
218
the mapping type and the mapping category where appropriate.
219
220
Currently handles additional fields values mappings.
221
222
Accepts a param hashref where the 'public' key denotes whether we want the public
223
or staff client strings.
224
225
=cut
226
227
sub strings_map {
228
    my ( $self, $params ) = @_;
229
230
    my $afvs    = $self->get_additional_field_values_for_template;
231
    my $strings = {};
232
233
    foreach my $af_id ( keys %{$afvs} ) {
234
235
        my $additional_field = Koha::AdditionalFields->find($af_id);
236
        my $av_cat           = $additional_field->effective_authorised_value_category;
237
        my @af_value_arr;
238
        my $af_value_str;
239
        my $value_to_push;
240
241
        foreach my $av_value ( @{ $afvs->{$af_id} } ) {
242
            if ($av_cat) {
243
                my $av = Koha::AuthorisedValues->search(
244
                    {
245
                        category         => $av_cat,
246
                        authorised_value => $av_value,
247
                    }
248
                );
249
250
                $value_to_push =
251
                    $av->count ? $params->{public} ? $av->next->opac_description : $av->next->lib : $av_value;
252
            } else {
253
                $value_to_push = $av_value;
254
            }
255
            push @af_value_arr, $value_to_push if $value_to_push;
256
        }
257
258
        $af_value_str = join( ", ", @af_value_arr );
259
260
        push(
261
            @{ $strings->{additional_field_values} },
262
            {
263
                field_label => $additional_field->name,
264
                value_str   => $af_value_str,
265
                type        => $av_cat ? 'av' : 'text',
266
                field_id    => $af_id,
267
            }
268
        );
269
    }
270
271
    my @sorted = sort { $a->{field_id} <=> $b->{field_id} } @{ $strings->{additional_field_values} };
272
    my @non_empty = grep { $_->{value_str} ne "" } @sorted;
273
    $strings->{additional_field_values} = \@non_empty;
274
275
    return $strings;
276
}
277
199
=head1 AUTHOR
278
=head1 AUTHOR
200
279
201
Koha Development Team <http://koha-community.org/>
280
Koha Development Team <http://koha-community.org/>
202
- 

Return to bug 35287