|
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 |
- |
|
|