|
Lines 102-108
sub get {
Link Here
|
| 102 |
}; |
102 |
}; |
| 103 |
} |
103 |
} |
| 104 |
|
104 |
|
| 105 |
=head3 get_availablity |
105 |
=head3 _check_availability |
|
|
106 |
|
| 107 |
Internal function to call CanBookBeIssued and return an appropriately filtered |
| 108 |
set return |
| 109 |
|
| 110 |
=cut |
| 111 |
|
| 112 |
sub _check_availability { |
| 113 |
my ( $c, $patron, $item ) = @_; |
| 114 |
|
| 115 |
my $inprocess = 0; # What does this do? |
| 116 |
my $ignore_reserves = 0; # Don't ignore reserves |
| 117 |
my $params = { item => $item }; |
| 118 |
|
| 119 |
my ( $impossible, $confirmation, $alerts, $messages ) = |
| 120 |
C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess, |
| 121 |
$ignore_reserves, $params ); |
| 122 |
|
| 123 |
if ( $c->stash('is_public') ) { |
| 124 |
|
| 125 |
# Upgrade some confirmations to blockers |
| 126 |
my @should_block = |
| 127 |
qw/TOO_MANY ISSUED_TO_ANOTHER RESERVED RESERVED_WAITING TRANSFERRED PROCESSING AGE_RESTRICTION/; |
| 128 |
for my $block (@should_block) { |
| 129 |
if ( exists( $confirmation->{$block} ) ) { |
| 130 |
$impossible->{$block} = $confirmation->{$block}; |
| 131 |
delete $confirmation->{$block}; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
# Remove any non-public info that's returned by CanBookBeIssued |
| 136 |
my @restricted_keys = |
| 137 |
qw/issued_borrowernumber issued_cardnumber issued_firstname issued_surname resborrowernumber resbranchcode rescardnumber reserve_id resfirstname resreservedate ressurname item_notforloan/; |
| 138 |
for my $key (@restricted_keys) { |
| 139 |
delete $confirmation->{$key}; |
| 140 |
delete $impossible->{$key}; |
| 141 |
delete $alerts->{$key}; |
| 142 |
delete $messages->{$key}; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
return ( $impossible, $confirmation, { %{$alerts}, %{$messages} } ); |
| 147 |
} |
| 148 |
|
| 149 |
=head3 get_availability |
| 106 |
|
150 |
|
| 107 |
Controller function that handles retrieval of Checkout availability |
151 |
Controller function that handles retrieval of Checkout availability |
| 108 |
|
152 |
|
|
Lines 112-130
sub get_availability {
Link Here
|
| 112 |
my $c = shift->openapi->valid_input or return; |
156 |
my $c = shift->openapi->valid_input or return; |
| 113 |
|
157 |
|
| 114 |
my $patron = Koha::Patrons->find( $c->validation->param('patron_id') ); |
158 |
my $patron = Koha::Patrons->find( $c->validation->param('patron_id') ); |
| 115 |
my $inprocess = 0; # What does this do? |
|
|
| 116 |
my $ignore_reserves = 0; # Don't ignore reserves |
| 117 |
my $item = Koha::Items->find( $c->validation->param('item_id') ); |
159 |
my $item = Koha::Items->find( $c->validation->param('item_id') ); |
| 118 |
my $params = { |
|
|
| 119 |
item => $item |
| 120 |
}; |
| 121 |
|
160 |
|
| 122 |
my ( $impossible, $confirmation, $alerts, $messages ) = |
161 |
my ( $impossible, $confirmation, $warnings ) = |
| 123 |
C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess, $ignore_reserves, |
162 |
$c->_check_availability( $patron, $item ); |
| 124 |
$params ); |
|
|
| 125 |
|
163 |
|
| 126 |
my $token; |
164 |
my $token; |
| 127 |
if (keys %{$confirmation}) { |
165 |
if ( keys %{$confirmation} ) { |
| 128 |
my $claims = { map { $_ => 1 } keys %{$confirmation} }; |
166 |
my $claims = { map { $_ => 1 } keys %{$confirmation} }; |
| 129 |
my $secret = |
167 |
my $secret = |
| 130 |
md5_base64( Encode::encode( 'UTF-8', C4::Context->config('pass') ) ); |
168 |
md5_base64( Encode::encode( 'UTF-8', C4::Context->config('pass') ) ); |
|
Lines 134-140
sub get_availability {
Link Here
|
| 134 |
my $response = { |
172 |
my $response = { |
| 135 |
blockers => $impossible, |
173 |
blockers => $impossible, |
| 136 |
confirms => $confirmation, |
174 |
confirms => $confirmation, |
| 137 |
warnings => { %{$alerts}, %{$messages} }, |
175 |
warnings => $warnings, |
| 138 |
confirmation_token => $token |
176 |
confirmation_token => $token |
| 139 |
}; |
177 |
}; |
| 140 |
|
178 |
|
|
Lines 178-197
sub add {
Link Here
|
| 178 |
); |
216 |
); |
| 179 |
} |
217 |
} |
| 180 |
|
218 |
|
| 181 |
my $inprocess = 0; # What does this do? |
219 |
my ( $impossible, $confirmation, $warnings ) = |
| 182 |
my $ignore_reserves = 0; # Don't ignore reserves |
220 |
$c->_check_availability( $patron, $item ); |
| 183 |
my $params = { item => $item }; |
|
|
| 184 |
|
| 185 |
# Call 'CanBookBeIssued' |
| 186 |
my ( $impossible, $confirmation, $alerts, $messages ) = |
| 187 |
C4::Circulation::CanBookBeIssued( |
| 188 |
$patron, |
| 189 |
undef, |
| 190 |
undef, |
| 191 |
$inprocess, |
| 192 |
$ignore_reserves, |
| 193 |
$params |
| 194 |
); |
| 195 |
|
221 |
|
| 196 |
# * Fail for blockers - render 403 |
222 |
# * Fail for blockers - render 403 |
| 197 |
if ( keys %{$impossible} ) { |
223 |
if ( keys %{$impossible} ) { |