|
Line 0
Link Here
|
|
|
1 |
package Koha::Item::Checkout::Availability; |
| 2 |
|
| 3 |
# Copyright 2026 Koha Development Team |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use C4::Circulation qw( CanBookBeIssued ); |
| 23 |
use Koha::Availability::Result; |
| 24 |
|
| 25 |
=head1 NAME |
| 26 |
|
| 27 |
Koha::Item::Checkout::Availability - Checkout availability validation for items |
| 28 |
|
| 29 |
=head1 SYNOPSIS |
| 30 |
|
| 31 |
my $availability = Koha::Item::Checkout::Availability->check( $item, |
| 32 |
{ |
| 33 |
patron => $patron, |
| 34 |
} |
| 35 |
); |
| 36 |
|
| 37 |
# Or via instance method |
| 38 |
my $availability = $item->checkout_availability( { patron => $patron } ); |
| 39 |
|
| 40 |
=head1 DESCRIPTION |
| 41 |
|
| 42 |
This class provides validation logic for item checkout operations, wrapping |
| 43 |
C4::Circulation::CanBookBeIssued in a Result object interface. |
| 44 |
|
| 45 |
The result categorizes conditions as: |
| 46 |
- blockers: Prevent checkout (e.g., item already checked out, patron debarred) |
| 47 |
- confirmations: Require user confirmation (e.g., item on hold for another patron) |
| 48 |
- warnings: Informational (e.g., patron has many checkouts) |
| 49 |
|
| 50 |
=head1 API |
| 51 |
|
| 52 |
=head2 Class methods |
| 53 |
|
| 54 |
=head3 check |
| 55 |
|
| 56 |
my $availability = Koha::Item::Checkout::Availability->check( $item, |
| 57 |
{ |
| 58 |
patron => $patron, |
| 59 |
} |
| 60 |
); |
| 61 |
|
| 62 |
Validates checkout availability for an item. |
| 63 |
|
| 64 |
Parameters: |
| 65 |
$item - Koha::Item object (required) |
| 66 |
$params - hashref with: |
| 67 |
patron => $patron (required) |
| 68 |
|
| 69 |
Returns a Koha::Availability::Result object with: |
| 70 |
blockers => {} # Conditions that prevent checkout |
| 71 |
confirmations => {} # Conditions requiring confirmation |
| 72 |
warnings => {} # Informational messages |
| 73 |
context => { |
| 74 |
patron => $patron # Koha::Patron object |
| 75 |
item => $item # Koha::Item object |
| 76 |
} |
| 77 |
|
| 78 |
=cut |
| 79 |
|
| 80 |
sub check { |
| 81 |
my ( $class, $item, $params ) = @_; |
| 82 |
|
| 83 |
my $patron = $params->{patron}; |
| 84 |
|
| 85 |
my $result = Koha::Availability::Result->new(); |
| 86 |
|
| 87 |
# Set context |
| 88 |
$result->set_context( patron => $patron ); |
| 89 |
$result->set_context( item => $item ); |
| 90 |
|
| 91 |
# Call CanBookBeIssued |
| 92 |
my ( $impossible, $confirmation, $alerts, $messages ) = |
| 93 |
CanBookBeIssued( $patron, undef, undef, 0, 0, { item => $item } ); |
| 94 |
|
| 95 |
# Map impossible to blockers |
| 96 |
for my $key ( keys %{$impossible} ) { |
| 97 |
$result->add_blocker( $key => $impossible->{$key} ); |
| 98 |
} |
| 99 |
|
| 100 |
# Map confirmation to confirmations |
| 101 |
for my $key ( keys %{$confirmation} ) { |
| 102 |
$result->add_confirmation( $key => $confirmation->{$key} ); |
| 103 |
} |
| 104 |
|
| 105 |
# Map alerts and messages to warnings |
| 106 |
for my $key ( keys %{$alerts} ) { |
| 107 |
$result->add_warning( $key => $alerts->{$key} ); |
| 108 |
} |
| 109 |
for my $key ( keys %{$messages} ) { |
| 110 |
$result->add_warning( $key => $messages->{$key} ); |
| 111 |
} |
| 112 |
|
| 113 |
return $result; |
| 114 |
} |
| 115 |
|
| 116 |
=head1 AUTHOR |
| 117 |
|
| 118 |
Koha Development Team <https://koha-community.org/> |
| 119 |
|
| 120 |
=cut |
| 121 |
|
| 122 |
1; |