Bug 36277: Do not fetch the whole library list
[koha.git] / Koha / Illrequest / Workflow.pm
1 package Koha::Illrequest::Workflow;
2
3 # Copyright 2023 PTFS Europe Ltd
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 <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use JSON;
23 use MIME::Base64 qw( encode_base64 );
24 use URI::Escape  qw( uri_escape );
25 use Encode       qw( encode );
26
27 use Koha::Plugins;
28
29 =head1 NAME
30
31 Koha::Illrequest::Workflow - Koha ILL Workflow parent class
32
33 =head1 SYNOPSIS
34
35 Object-oriented parent class for ILL workflow stages
36
37 =head1 DESCRIPTION
38
39 This class contains methods do be used by ILL workflow stages
40
41 =head1 API
42
43 =head2 Class Methods
44
45 =head3 new
46
47     my $availability = Koha::Illrequest::Workflow::Availability->new( $params, 'opac' )
48
49 Create a new Koha::Illrequest::Workflow child class object.
50 We store the metadata and ui_context
51
52 =cut
53
54 sub new {
55     my ( $class, $metadata, $ui_context ) = @_;
56     my $self = {};
57
58     $self->{metadata}   = $metadata;
59     $self->{ui_context} = $ui_context;
60
61     bless $self, $class;
62
63     return $self;
64 }
65
66 =head3 prep_metadata
67
68     my $prepared = Koha::Illrequest::Workflow->prep_metadata($metadata);
69
70 Given our metadata, return a string representing that metadata that can be
71 passed in a URL (encoded in JSON then Base64 encoded)
72
73 =cut
74
75 sub prep_metadata {
76     my ( $self, $metadata ) = @_;
77
78     # We sort the metadata hashref by key before encoding it, primarily
79     # so this function returns something predictable that we can test!
80     my $json = JSON->new;
81     $json->canonical( [1] );
82     return uri_escape(
83         encode_base64( encode( 'utf-8', $json->encode($metadata) ) ) );
84 }
85
86 =head1 AUTHOR
87
88 Pedro Amorim <pedro.amorim@ptfs-europe.com>
89
90 =cut
91
92 1;