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

(-)a/Koha/Biblio.pm (+20 lines)
Lines 724-729 sub custom_cover_image_url { Link Here
724
    return $url;
724
    return $url;
725
}
725
}
726
726
727
=head3 to_api_mapping
728
729
This method returns the mapping for representing a Koha::Biblio object
730
on the API.
731
732
=cut
733
734
sub to_api_mapping {
735
    return {
736
        biblionumber     => 'biblio_id',
737
        frameworkcode    => 'framework_id',
738
        unititle         => 'uniform_title',
739
        seriestitle      => 'series_title',
740
        copyrightdate    => 'copyright_date',
741
        datecreated      => 'creation_date'
742
    };
743
}
744
745
=head2 Internal methods
746
727
=head3 type
747
=head3 type
728
748
729
=cut
749
=cut
(-)a/Koha/Biblioitem.pm (-2 / +32 lines)
Lines 29-39 Koha::Biblioitem - Koha Biblioitem Object class Link Here
29
29
30
=head1 API
30
=head1 API
31
31
32
=head2 Class Methods
32
=head2 Class methods
33
34
=head3 to_api_mapping
35
36
This method returns the mapping for representing a Koha::Biblioitem object
37
on the API.
33
38
34
=cut
39
=cut
35
40
36
=head3 type
41
sub to_api_mapping {
42
    return {
43
        agerestriction   => 'age_restriction',
44
        biblioitemnumber => undef, # meaningless
45
        collectionissn   => 'collection_issn',
46
        collectiontitle  => 'collection_title',
47
        collectionvolume => 'collection_volume',
48
        editionresponsibility => undef, # obsolete, not mapped
49
        editionstatement => 'edition_statement',
50
        illus            => 'illustrations',
51
        itemtype         => 'item_type',
52
        lccn             => 'lc_control_number',
53
        place            => 'publication_place',
54
        publicationyear  => 'publication_year',
55
        publishercode    => 'publisher',
56
        size             => 'material_size',
57
        totalissues      => 'serial_total_issues',
58
        volumedate       => 'volume_date',
59
        volumedesc       => 'volume_description',
60
61
    };
62
}
63
64
=head2 Internal methods
65
66
=head3 _type
37
67
38
=cut
68
=cut
39
69
(-)a/Koha/REST/V1/Biblios.pm (-70 / +4 lines)
Lines 28-34 use Try::Tiny; Link Here
28
28
29
=head1 API
29
=head1 API
30
30
31
=head2 Class methods
31
=head2 Methods
32
32
33
=head3 get
33
=head3 get
34
34
Lines 150-187 sub delete { Link Here
150
150
151
=head2 Internal methods
151
=head2 Internal methods
152
152
153
154
=head3 _to_api
155
156
Helper function that maps unblessed Koha::Patron objects into REST api
157
attribute names.
158
159
=cut
160
161
sub _to_api {
162
    my $biblio = shift;
163
164
    # Rename attributes
165
    foreach my $column ( keys %{$Koha::REST::V1::Biblios::to_api_mapping} ) {
166
        my $mapped_column = $Koha::REST::V1::Biblios::to_api_mapping->{$column};
167
        if ( exists $biblio->{$column}
168
            && defined $mapped_column )
169
        {
170
            # key != undef
171
            $biblio->{$mapped_column} = delete $biblio->{$column};
172
        }
173
        elsif ( exists $biblio->{$column}
174
            && !defined $mapped_column )
175
        {
176
            # key == undef
177
            delete $biblio->{$column};
178
        }
179
    }
180
181
    return $biblio;
182
}
183
184
185
=head3 build_json_biblio
153
=head3 build_json_biblio
186
154
187
Internal method that returns all the attributes from the biblio and biblioitems tables
155
Internal method that returns all the attributes from the biblio and biblioitems tables
Lines 193-239 sub build_json_biblio { Link Here
193
161
194
    my $biblio = $args->{biblio};
162
    my $biblio = $args->{biblio};
195
163
196
    my $response = $biblio->TO_JSON;
164
    my $response = $biblio->to_api;
197
    my $biblioitem = $biblio->biblioitem->TO_JSON;
165
    my $biblioitem = $biblio->biblioitem->to_api;
198
166
199
    foreach my $key ( keys %{ $biblioitem } ) {
167
    foreach my $key ( keys %{ $biblioitem } ) {
200
        $response->{$key} = $biblioitem->{$key};
168
        $response->{$key} = $biblioitem->{$key};
201
    }
169
    }
202
170
203
    return _to_api($response);
171
    return $response;
204
}
172
}
205
173
206
207
=head2 Global variables
208
209
=head3 $to_api_mapping
210
211
=cut
212
213
our $to_api_mapping = {
214
    agerestriction   => 'age_restriction',
215
    biblioitemnumber => undef, # meaningless
216
    biblionumber     => 'biblio_id',
217
    collectionissn   => 'collection_issn',
218
    collectiontitle  => 'collection_title',
219
    collectionvolume => 'collection_volume',
220
    copyrightdate    => 'copyright_date',
221
    datecreated      => 'creation_date',
222
    editionresponsibility => undef, # obsolete, not mapped
223
    editionstatement => 'edition_statement',
224
    frameworkcode    => 'framework_id',
225
    illus            => 'illustrations',
226
    itemtype         => 'item_type',
227
    lccn             => 'lc_control_number',
228
    place            => 'publication_place',
229
    publicationyear  => 'publication_year',
230
    publishercode    => 'publisher',
231
    seriestitle      => 'series_title',
232
    size             => 'material_size',
233
    totalissues      => 'serial_total_issues',
234
    unititle         => 'uniform_title',
235
    volumedate       => 'volume_date',
236
    volumedesc       => 'volume_description',
237
};
238
239
1;
174
1;
240
- 

Return to bug 24321