View | Details | Raw Unified | Return to bug 33716
Collapse All | Expand All

(-)a/Koha/Illrequest/Availability.pm (-127 lines)
Lines 1-127 Link Here
1
package Koha::Illrequest::Availability;
2
3
# Copyright 2019 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::Availability - Koha ILL Availability Searching
32
33
=head1 SYNOPSIS
34
35
Object-oriented class that provides availability searching via
36
availability plugins
37
38
=head1 DESCRIPTION
39
40
This class provides the ability to identify and fetch API services
41
that can be used to search for item availability
42
43
=head1 API
44
45
=head2 Class Methods
46
47
=head3 new
48
49
    my $availability = Koha::Illrequest::Logger->new($metadata);
50
51
Create a new Koha::Illrequest::Availability object.
52
We also store the metadata to be used for searching
53
54
=cut
55
56
sub new {
57
    my ( $class, $metadata ) = @_;
58
    my $self  = {};
59
60
    $self->{metadata} = $metadata;
61
62
    bless $self, $class;
63
64
    return $self;
65
}
66
67
=head3 get_services
68
69
    my $services = Koha::Illrequest::Availability->get_services($params);
70
71
Given our metadata, iterate plugins with the right method and
72
check if they can service our request and, if so, return an arrayref
73
of services. Optionally accept a hashref specifying additional filter
74
parameters
75
76
=cut
77
78
sub get_services {
79
    my ( $self, $params ) = @_;
80
81
    my $plugin_filter = {
82
        method => 'ill_availability_services'
83
    };
84
85
    if ($params->{metadata}) {
86
        $plugin_filter->{metadata} = $params->{metadata};
87
    }
88
89
    my @candidates = Koha::Plugins->new()->GetPlugins($plugin_filter);
90
    my @services = ();
91
    foreach my $plugin(@candidates) {
92
        my $valid_service = $plugin->ill_availability_services({
93
            metadata => $self->{metadata},
94
            ui_context => $params->{ui_context}
95
        });
96
        push @services, $valid_service if $valid_service;
97
    }
98
99
    return \@services;
100
}
101
102
=head3 prep_metadata
103
104
    my $prepared = Koha::Illrequest::Availability->prep_metadata($metadata);
105
106
Given our metadata, return a string representing that metadata that can be
107
passed in a URL (encoded in JSON then Base64 encoded)
108
109
=cut
110
111
sub prep_metadata {
112
    my ( $self, $metadata ) = @_;
113
114
    # We sort the metadata hashref by key before encoding it, primarily
115
    # so this function returns something predictable that we can test!
116
    my $json = JSON->new;
117
    $json->canonical([1]);
118
    return uri_escape(encode_base64(encode('utf-8',$json->encode($metadata))));
119
}
120
121
=head1 AUTHOR
122
123
Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
124
125
=cut
126
127
1;
(-)a/Koha/Illrequest/Workflow.pm (+93 lines)
Line 0 Link Here
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::TypeDisclaimer - Koha ILL TypeDisclaimer
32
33
=head1 SYNOPSIS
34
35
Object-oriented class that provides the ILL request type disclaimer
36
37
=head1 DESCRIPTION
38
39
This class provides the ability to verify if it should render type disclaimer
40
and handle the template params accordingly
41
42
=head1 API
43
44
=head2 Class Methods
45
46
=head3 new
47
48
    my $type_disclaimer = Koha::Illrequest::Logger->new($metadata);
49
50
Create a new Koha::Illrequest::TypeDisclaimer object.
51
We also store the metadata to be used to retrieve the request type
52
53
=cut
54
55
sub new {
56
    my ( $class, $metadata, $ui_context ) = @_;
57
    my $self = {};
58
59
    $self->{metadata}   = $metadata;
60
    $self->{ui_context} = $ui_context;
61
62
    bless $self, $class;
63
64
    return $self;
65
}
66
67
=head3 prep_metadata
68
69
    my $prepared = Koha::Illrequest::Workflow->prep_metadata($metadata);
70
71
Given our metadata, return a string representing that metadata that can be
72
passed in a URL (encoded in JSON then Base64 encoded)
73
74
=cut
75
76
sub prep_metadata {
77
    my ( $self, $metadata ) = @_;
78
79
    # We sort the metadata hashref by key before encoding it, primarily
80
    # so this function returns something predictable that we can test!
81
    my $json = JSON->new;
82
    $json->canonical( [1] );
83
    return uri_escape(
84
        encode_base64( encode( 'utf-8', $json->encode($metadata) ) ) );
85
}
86
87
=head1 AUTHOR
88
89
Pedro Amorim <pedro.amorim@ptfs-europe.com>
90
91
=cut
92
93
1;
(-)a/Koha/Illrequest/Workflow/Availability.pm (+150 lines)
Line 0 Link Here
1
package Koha::Illrequest::Workflow::Availability;
2
3
# Copyright 2019 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
24
use base qw(Koha::Illrequest::Workflow);
25
26
use Koha::Plugins;
27
28
=head1 NAME
29
30
Koha::Illrequest::Workflow::Availability - Koha ILL Availability Searching
31
32
=head1 SYNOPSIS
33
34
Object-oriented class that provides availability searching via
35
availability plugins
36
37
=head1 DESCRIPTION
38
39
This class provides the ability to identify and fetch API services
40
that can be used to search for item availability
41
42
=head1 API
43
44
=head2 Class Methods
45
46
=head3 get_services
47
48
    my $services =
49
      Koha::Illrequest::Workflow::Availability->get_services($params);
50
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
54
parameters
55
56
=cut
57
58
sub get_services {
59
    my ( $self, $params ) = @_;
60
61
    my $plugin_filter = { method => 'ill_availability_services' };
62
63
    if ( $params->{metadata} ) {
64
        $plugin_filter->{metadata} = $params->{metadata};
65
    }
66
67
    my @candidates = Koha::Plugins->new()->GetPlugins($plugin_filter);
68
    my @services   = ();
69
    foreach my $plugin (@candidates) {
70
        my $valid_service = $plugin->ill_availability_services(
71
            {
72
                metadata   => $self->{metadata},
73
                ui_context => $self->{ui_context},
74
            }
75
        );
76
        push @services, $valid_service if $valid_service;
77
    }
78
79
    return \@services;
80
}
81
82
=head3 show_availability
83
84
    my $show_availability =
85
    Koha::Illrequest::Workflow::Availability->show_availability($params);
86
87
Given $params, return true if availability should be shown
88
89
=cut
90
91
sub show_availability {
92
    my ( $self, $request ) = @_;
93
94
    my $services = $self->get_services;
95
96
    return
97
98
      # ILLCheckAvailability is enabled
99
      C4::Context->preference("ILLCheckAvailability")
100
101
      # At least 1 availability service exists
102
      && scalar @{$services}
103
104
      # Availability has not yet been checked
105
      && !$self->{metadata}->{checked_availability}
106
107
     # The form has been submitted and the backend is able to create the request
108
      && $request->_backend_capability( 'can_create_request',
109
        $self->{metadata} );
110
}
111
112
=head3 availability_template_params
113
114
    my $availability_template_params =
115
    Koha::Illrequest::Workflow::Availability->availability_template_params(
116
        $params);
117
118
Given $params, return true if availability should be shown
119
120
=cut
121
122
sub availability_template_params {
123
    my ( $self, $params ) = @_;
124
125
    $params->{method} = 'availability' if $self->{ui_context} eq 'staff';
126
    delete $params->{stage}            if $self->{ui_context} eq 'staff';
127
    my $services = $self->get_services;
128
129
    return (
130
        whole         => $params,
131
        metadata      => $self->prep_metadata($params),
132
        services_json => scalar encode_json($services),
133
        services      => $services,
134
        $self->{ui_context} eq 'opac'
135
        ? (
136
            illrequestsview => 1,
137
            message         => $params->{message},
138
            method          => 'availability',
139
          )
140
        : ()
141
    );
142
}
143
144
=head1 AUTHOR
145
146
Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
147
148
=cut
149
150
1;
(-)a/Koha/Illrequest/Workflow/TypeDisclaimer.pm (-1 / +194 lines)
Line 0 Link Here
0
- 
1
package Koha::Illrequest::Workflow::TypeDisclaimer;
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 POSIX qw( strftime );
23
24
use base qw(Koha::Illrequest::Workflow);
25
26
=head1 NAME
27
28
Koha::Illrequest::TypeDisclaimer - Koha ILL TypeDisclaimer
29
30
=head1 SYNOPSIS
31
32
Object-oriented class that provides the ILL request type disclaimer
33
34
=head1 DESCRIPTION
35
36
This class provides the ability to verify if it should render type disclaimer
37
and handle the template params accordingly
38
39
=head1 API
40
41
=head2 Class Methods
42
43
=head3 show_type_disclaimer
44
45
    my $show_type_disclaimer =
46
    Koha::Illrequest::TypeDisclaimer->show_type_disclaimer($params);
47
48
Given $params, return true if type disclaimer should be shown
49
50
=cut
51
52
sub show_type_disclaimer {
53
    my ( $self, $request ) = @_;
54
55
    my $disc_sys_pref = $self->_get_type_disclaimer_sys_pref;
56
57
    my $disc_info =
58
      $self->_get_type_disclaimer_info( $self->_get_type_disclaimer_sys_pref,
59
        $self->{metadata}->{type} );
60
61
    return
62
63
      # ILLModuleDisclaimerByType contains correct YAML
64
      %{$disc_sys_pref}
65
66
      # Check that we have info to display for this type
67
      && $disc_info
68
69
      # ILLModuleDisclaimerByType contains at least 'all'
70
      && $disc_sys_pref->{all}
71
72
      # Type disclaimer has not yet been submitted
73
      && !$self->{metadata}->{type_disclaimer_submitted}
74
75
     # The form has been submitted and the backend is able to create the request
76
      && $request->_backend_capability( 'can_create_request',
77
        $self->{metadata} );
78
}
79
80
=head3 type_disclaimer_template_params
81
82
    my $type_disclaimer_template_params =
83
    Koha::Illrequest::TypeDisclaimer->type_disclaimer_template_params(
84
        $params);
85
86
Given $params, return true if type disclaimer should be rendered
87
88
=cut
89
90
sub type_disclaimer_template_params {
91
    my ( $self, $params ) = @_;
92
93
    my $disc_info =
94
      $self->_get_type_disclaimer_info( $self->_get_type_disclaimer_sys_pref,
95
        $params->{type} );
96
97
    $params->{method} = 'typedisclaimer' if $self->{ui_context} eq 'staff';
98
    delete $params->{stage}              if $self->{ui_context} eq 'staff';
99
100
    return (
101
        whole      => $params,
102
        metadata   => $self->prep_metadata($params),
103
        disclaimer => $disc_info,
104
        $self->{ui_context} eq 'opac'
105
        ? (
106
            illrequestsview => 1,
107
            message         => $params->{message},
108
            method          => 'typedisclaimer',
109
          )
110
        : ()
111
    );
112
}
113
114
=head3 after_request_created
115
116
    #example here
117
118
#description here
119
120
=cut
121
122
sub after_request_created {
123
    my ( $self, $params, $request ) = @_;
124
125
    # Store type disclaimer date and value
126
    my $type_disclaimer_date = {
127
        illrequest_id => $request->illrequest_id,
128
        type          => "type_disclaimer_date",
129
        value         => strftime( "%Y-%m-%dT%H:%M:%S", localtime( time() ) ),
130
        readonly      => 0
131
    };
132
    Koha::Illrequestattribute->new($type_disclaimer_date)->store;
133
134
    my $type_disclaimer_value = {
135
        illrequest_id => $request->illrequest_id,
136
        type          => "type_disclaimer_value",
137
        value         => $params->{type_disclaimer_value},
138
        readonly      => 0
139
    };
140
    Koha::Illrequestattribute->new($type_disclaimer_value)->store;
141
}
142
143
=head3 _get_type_disclaimer_info
144
145
    my $type_disclaimer_info =
146
      $self->_get_type_disclaimer_info( $type_disclaimer_sys_pref, $request_type );
147
148
Given ILLModuleDisclaimerByType sys pref and type, returns the respective
149
type disclaimer info
150
Returns undef if sys pref is empty or malformed
151
=cut
152
153
sub _get_type_disclaimer_info {
154
    my ( $self, $disc_sys_pref, $type ) = @_;
155
156
    my @matching_request_type =
157
      map ( $_ eq $type ? $_ : (), keys %$disc_sys_pref );
158
159
    my $disc_info = undef;
160
    if ( scalar @matching_request_type ) {
161
        return if $disc_sys_pref->{$type}->{bypass};
162
163
        $disc_info->{text}   = $disc_sys_pref->{$type}->{text};
164
        $disc_info->{av_cat} = $disc_sys_pref->{$type}->{av_category_code};
165
    }
166
    elsif ( $disc_sys_pref->{all} ) {
167
        $disc_info->{text}   = $disc_sys_pref->{all}->{text};
168
        $disc_info->{av_cat} = $disc_sys_pref->{all}->{av_category_code};
169
    }
170
    return $disc_info;
171
}
172
173
=head3 _get_type_disclaimer_sys_pref
174
175
    my $disc_sys_pref = $self->_get_type_disclaimer_sys_pref;
176
177
Returns YAML from ILLModuleDisclaimerByType syspref
178
Returns empty if empty or YAML error
179
180
=cut
181
182
sub _get_type_disclaimer_sys_pref {
183
    my ($self) = @_;
184
185
    return C4::Context->yaml_preference("ILLModuleDisclaimerByType") // {};
186
}
187
188
=head1 AUTHOR
189
190
Pedro Amorim <pedro.amorim@ptfs-europe.com>
191
192
=cut
193
194
1;

Return to bug 33716