<<

NAME

Koha::Result::Availability - Base class for availability check results

SYNOPSIS

    my $result = Koha::Result::Availability->new();

    $result->add_blocker( bad_barcode => $barcode );
    $result->add_confirmation( not_issued => $barcode );
    $result->add_warning( withdrawn => 1 );

    if ( $result->available ) {
        # Proceed with action
    }

DESCRIPTION

This class provides a standardized structure for availability check results across different operations (check-in, checkout, hold, renewal, etc.).

Results are categorized into: - blockers: Conditions that prevent the action - confirmations: Conditions requiring user confirmation - warnings: Informational messages that don't prevent the action

API

Class methods

new

    my $result = Koha::Result::Availability->new();

Constructor. Creates a new result object with empty blockers, confirmations, and warnings.

Instance methods

add_blocker

    $result->add_blocker( $key => $value );

Adds a blocker. Blockers prevent the action from proceeding.

add_confirmation

    $result->add_confirmation( $key => $value );

Adds a confirmation requirement. Confirmations require user acknowledgment before proceeding.

add_warning

    $result->add_warning( $key => $value );

Adds a warning. Warnings are informational and don't prevent the action.

set_context

    $result->set_context( $key => $value );

Sets a context value. Context provides additional information about the availability check (e.g., related objects like item, checkout, patron).

available

    if ( $result->available ) { ... }

Returns true if there are no blockers, false otherwise.

needs_confirmation

    if ( $result->needs_confirmation ) { ... }

Returns true if there are confirmations required, false otherwise.

blockers

    my $blockers = $result->blockers;

Returns the blockers hashref.

confirmations

    my $confirmations = $result->confirmations;

Returns the confirmations hashref.

warnings

    my $warnings = $result->warnings;

Returns the warnings hashref.

context

    my $context = $result->context;
    my $item = $result->context->{item};

Returns the context hashref.

token_params

Abstract method. Subclasses override to return an arrayref of context keys used for token generation.

TOKEN_EXPIRY_SECONDS

How long an as_token confirmation token remains valid for. Confirmation tokens are meant to be round-tripped within a single staff interaction (scan, see the confirmation prompt, confirm), not stored or reused later.

as_token

Generates a JWT confirmation token, valid for TOKEN_EXPIRY_SECONDS.

check_token

Validates a JWT confirmation token.

_token_id

to_api

    my $hashref = $result->to_api;

Returns a hashref suitable for API responses. Includes a confirmation_token when confirmations exist.

to_hashref

    my $hashref = $result->to_hashref;

Returns a plain hashref representation of the result, suitable for backward compatibility or serialization.

AUTHOR

Koha Development Team <https://koha-community.org/>

<<