Bugzilla – Attachment 93831 Details for
Bug 23770
Add Koha::Object(s)->to_api method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23770: Add Koha::Object(s)->to_api method
Bug-23770-Add-KohaObjects-toapi-method.patch (text/plain), 1.76 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-10-07 18:57:11 UTC
(
hide
)
Description:
Bug 23770: Add Koha::Object(s)->to_api method
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-10-07 18:57:11 UTC
Size:
1.76 KB
patch
obsolete
>From 216d286dffb65b298f39c6b15512613c01aee41d Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 7 Oct 2019 15:55:09 -0300 >Subject: [PATCH] Bug 23770: Add Koha::Object(s)->to_api method > >Generic method that changes the attribute names of an object in the >presence of the to_api_mapping method. It otherwise falls back to >returning the TO_JSON output. > >This is WIP submitted early for scrutiny. Tests and example usage in an >API controller coming. >--- > Koha/Object.pm | 32 ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index 04d34c49e3..706a9e4a93 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -356,6 +356,38 @@ sub _numeric_column_type { > return ( grep { $column_type eq $_ } @numeric_types) ? 1 : 0; > } > >+=head3 to_api >+ >+ my $object_for_api = $object->to_api; >+ >+=cut >+ >+sub to_api { >+ my ( $self ) = @_; >+ my $json_object = $self->TO_JSON; >+ >+ # Rename attributes if there's a mapping >+ if ( $self->can('to_api_mapping') ) { >+ foreach my $column ( keys %{$self->to_api_mapping} ) { >+ my $mapped_column = $self->to_api_mapping->{$column}; >+ if ( exists $json_object->{$column} >+ && defined $mapped_column ) >+ { >+ # key != undef >+ $json_object->{$mapped_column} = delete $json_object->{$column}; >+ } >+ elsif ( exists $json_object->{$column} >+ && !defined $mapped_column ) >+ { >+ # key == undef >+ delete $json_object->{$column}; >+ } >+ } >+ } >+ >+ return $json_object; >+} >+ > =head3 $object->unblessed_all_relateds > > my $everything_into_one_hashref = $object->unblessed_all_relateds >-- >2.23.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23770
:
93831
|
93881
|
93882
|
93883
|
93888
|
93890
|
93891
|
93892
|
93893
|
93894
|
93895
|
94396
|
94397
|
94398
|
94399
|
94400