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

(-)a/Koha/Object/Mixin/AdditionalFields.pm (-1 / +79 lines)
Lines 225-230 sub additional_field_values { Link Here
225
    return Koha::AdditionalFieldValues->_new_from_dbic( $afv_rs );
225
    return Koha::AdditionalFieldValues->_new_from_dbic( $afv_rs );
226
}
226
}
227
227
228
=head3 extended_attributes
229
230
REST API embed of additional_field_values
231
232
=cut
233
234
sub extended_attributes {
235
    my ($self, $extended_attributes) = @_;
236
237
    if ($extended_attributes) {
238
        $self->set_additional_fields($extended_attributes);
239
    }
240
    my $afv_rs = $self->_result->extended_attributes;
241
    return Koha::AdditionalFieldValues->_new_from_dbic($afv_rs);
242
}
243
244
=head3 strings_map
245
246
Returns a map of column name to string representations including the string,
247
the mapping type and the mapping category where appropriate.
248
249
Currently handles additional fields values mappings.
250
251
Accepts a param hashref where the 'public' key denotes whether we want the public
252
or staff client strings.
253
254
=cut
255
256
sub strings_map {
257
    my ( $self, $params ) = @_;
258
259
    my $afvs    = $self->get_additional_field_values_for_template;
260
    my $strings = {};
261
262
    foreach my $af_id ( keys %{$afvs} ) {
263
264
        my $additional_field = Koha::AdditionalFields->find($af_id);
265
        my $av_cat           = $additional_field->effective_authorised_value_category;
266
        my @af_value_arr;
267
        my $af_value_str;
268
        my $value_to_push;
269
270
        foreach my $av_value ( @{ $afvs->{$af_id} } ) {
271
            if ($av_cat) {
272
                my $av = Koha::AuthorisedValues->search(
273
                    {
274
                        category         => $av_cat,
275
                        authorised_value => $av_value,
276
                    }
277
                );
278
279
                $value_to_push =
280
                    $av->count ? $params->{public} ? $av->next->opac_description : $av->next->lib : $av_value;
281
            } else {
282
                $value_to_push = $av_value;
283
            }
284
            push @af_value_arr, $value_to_push if $value_to_push;
285
        }
286
287
        $af_value_str = join( ", ", @af_value_arr );
288
289
        push(
290
            @{ $strings->{additional_field_values} },
291
            {
292
                field_label => $additional_field->name,
293
                value_str   => $af_value_str,
294
                type        => $av_cat ? 'av' : 'text',
295
                field_id    => $af_id,
296
            }
297
        );
298
    }
299
300
    my @sorted = sort { $a->{field_id} <=> $b->{field_id} } @{ $strings->{additional_field_values} };
301
    my @non_empty = grep { $_->{value_str} ne "" } @sorted;
302
    $strings->{additional_field_values} = \@non_empty;
303
304
    return $strings;
305
}
306
228
=head1 AUTHOR
307
=head1 AUTHOR
229
308
230
Koha Development Team <http://koha-community.org/>
309
Koha Development Team <http://koha-community.org/>
231
- 

Return to bug 35287