Lines 19-24
package Koha::Biblio::Availability;
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use Scalar::Util qw(looks_like_number); |
21 |
use Scalar::Util qw(looks_like_number); |
|
|
22 |
use Mojo::JSON; |
22 |
|
23 |
|
23 |
use base qw(Koha::Availability); |
24 |
use base qw(Koha::Availability); |
24 |
|
25 |
|
Lines 129-132
sub new {
Link Here
|
129 |
return $self; |
130 |
return $self; |
130 |
} |
131 |
} |
131 |
|
132 |
|
|
|
133 |
=head3 swaggerize |
134 |
|
135 |
Returns a HASHref that contains biblio availability information as well as |
136 |
availability information for each item of this biblio. |
137 |
|
138 |
Numifies numbers for Swagger to be numbers instead of strings. |
139 |
|
140 |
=cut |
141 |
|
142 |
sub swaggerize { |
143 |
my ($self) = @_; |
144 |
|
145 |
my $item_availabilities = []; |
146 |
foreach my $item_availability (@{$self->item_availabilities}) { |
147 |
push $item_availabilities, $item_availability->swaggerize; |
148 |
} |
149 |
foreach my $item_availability (@{$self->item_unavailabilities}) { |
150 |
push $item_availabilities, $item_availability->swaggerize; |
151 |
} |
152 |
my $confirmations = $self->SUPER::_swaggerize_exception($self->confirmations); |
153 |
my $notes = $self->SUPER::_swaggerize_exception($self->notes); |
154 |
my $unavailabilities = $self->SUPER::_swaggerize_exception($self->unavailabilities); |
155 |
my $availability = { |
156 |
available => $self->available |
157 |
? Mojo::JSON->true |
158 |
: Mojo::JSON->false, |
159 |
}; |
160 |
if (keys %{$confirmations} > 0) { |
161 |
$availability->{'confirmations'} = $confirmations; |
162 |
} |
163 |
if (keys %{$notes} > 0) { |
164 |
$availability->{'notes'} = $notes; |
165 |
} |
166 |
if (keys %{$unavailabilities} > 0) { |
167 |
$availability->{'unavailabilities'} = $unavailabilities; |
168 |
} |
169 |
|
170 |
my $hash = { |
171 |
biblionumber => 0+$self->biblio->biblionumber, |
172 |
availability => $availability, |
173 |
item_availabilities => $item_availabilities, |
174 |
}; |
175 |
return $hash; |
176 |
} |
177 |
|
132 |
1; |
178 |
1; |