1 package Koha::Illrequest::Workflow::Availability;
3 # Copyright 2019 PTFS Europe Ltd
5 # This file is part of Koha.
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.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use base qw(Koha::Illrequest::Workflow);
30 Koha::Illrequest::Workflow::Availability - Koha ILL Availability Searching
34 Object-oriented class that provides availability searching via
39 This class provides the ability to identify and fetch API services
40 that can be used to search for item availability
49 Koha::Illrequest::Workflow::Availability->get_services($params);
51 Given our metadata, iterate plugins with the right method and
52 check if they can service our request and, if so, return an arrayref
53 of services. Optionally accept a hashref specifying additional filter
59 my ( $self, $params ) = @_;
61 my $plugin_filter = { method => 'ill_availability_services' };
63 if ( $params->{metadata} ) {
64 $plugin_filter->{metadata} = $params->{metadata};
67 return [] unless C4::Context->config("enable_plugins");
69 my @candidates = Koha::Plugins->new()->GetPlugins($plugin_filter);
71 foreach my $plugin (@candidates) {
72 my $valid_service = $plugin->ill_availability_services(
74 metadata => $self->{metadata},
75 ui_context => $self->{ui_context},
78 push @services, $valid_service if $valid_service;
84 =head3 show_availability
86 my $show_availability =
87 Koha::Illrequest::Workflow::Availability->show_availability($params);
89 Given $params, return true if availability should be shown
93 sub show_availability {
94 my ( $self, $request ) = @_;
96 my $services = $self->get_services;
100 # ILLCheckAvailability is enabled
101 C4::Context->preference("ILLCheckAvailability")
103 # At least 1 availability service exists
104 && scalar @{$services}
106 # Availability has not yet been checked
107 && !$self->{metadata}->{checked_availability}
109 # The form has been submitted and the backend is able to create the request
110 && $request->_backend_capability( 'can_create_request',
114 =head3 availability_template_params
116 my $availability_template_params =
117 Koha::Illrequest::Workflow::Availability->availability_template_params(
120 Given $params, return true if availability should be shown
124 sub availability_template_params {
125 my ( $self, $params ) = @_;
127 $params->{method} = 'availability' if $self->{ui_context} eq 'staff';
128 delete $params->{stage} if $self->{ui_context} eq 'staff';
129 my $services = $self->get_services;
133 metadata => $self->prep_metadata($params),
134 services_json => scalar encode_json($services),
135 services => $services,
136 $self->{ui_context} eq 'opac'
138 illrequestsview => 1,
139 message => $params->{message},
140 method => 'availability',
148 Andrew Isherwood <andrew.isherwood@ptfs-europe.com>