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

(-)a/Koha/Object.pm (+34 lines)
Lines 356-361 sub _numeric_column_type { Link Here
356
    return ( grep { $column_type eq $_ } @numeric_types) ? 1 : 0;
356
    return ( grep { $column_type eq $_ } @numeric_types) ? 1 : 0;
357
}
357
}
358
358
359
=head3 to_api
360
361
    my $object_for_api = $object->to_api;
362
363
Returns a representation of the object, suitable for API output.
364
365
=cut
366
367
sub to_api {
368
    my ( $self ) = @_;
369
    my $json_object = $self->TO_JSON;
370
371
    # Rename attributes if there's a mapping
372
    if ( $self->can('to_api_mapping') ) {
373
        foreach my $column ( keys %{$self->to_api_mapping} ) {
374
            my $mapped_column = $self->to_api_mapping->{$column};
375
            if ( exists $json_object->{$column}
376
                && defined $mapped_column )
377
            {
378
                # key != undef
379
                $json_object->{$mapped_column} = delete $json_object->{$column};
380
            }
381
            elsif ( exists $json_object->{$column}
382
                && !defined $mapped_column )
383
            {
384
                # key == undef
385
                delete $json_object->{$column};
386
            }
387
        }
388
    }
389
390
    return $json_object;
391
}
392
359
=head3 $object->unblessed_all_relateds
393
=head3 $object->unblessed_all_relateds
360
394
361
my $everything_into_one_hashref = $object->unblessed_all_relateds
395
my $everything_into_one_hashref = $object->unblessed_all_relateds
(-)a/Koha/Objects.pm (-1 / +12 lines)
Lines 308-313 sub TO_JSON { Link Here
308
    return [ map { $_->TO_JSON } $self->as_list ];
308
    return [ map { $_->TO_JSON } $self->as_list ];
309
}
309
}
310
310
311
=head3 Koha::Objects->to_api
312
313
Returns a representation of the objects, suitable for API output .
314
315
=cut
316
317
sub to_api {
318
    my ($self) = @_;
319
320
    return [ map { $_->to_api } $self->as_list ];
321
}
322
311
=head3 Koha::Objects->_wrap
323
=head3 Koha::Objects->_wrap
312
324
313
wraps the DBIC object in a corresponding Koha object
325
wraps the DBIC object in a corresponding Koha object
314
- 

Return to bug 23770