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

(-)a/Koha/Illrequest/Workflow.pm (-5 / +5 lines)
Lines 1-4 Link Here
1
package Koha::Illrequest::Workflow;
1
package Koha::ILL::Request::Workflow;
2
2
3
# Copyright 2023 PTFS Europe Ltd
3
# Copyright 2023 PTFS Europe Ltd
4
#
4
#
Lines 28-34 use Koha::Plugins; Link Here
28
28
29
=head1 NAME
29
=head1 NAME
30
30
31
Koha::Illrequest::Workflow - Koha ILL Workflow parent class
31
Koha::ILL::Request::Workflow - Koha ILL Workflow parent class
32
32
33
=head1 SYNOPSIS
33
=head1 SYNOPSIS
34
34
Lines 44-52 This class contains methods do be used by ILL workflow stages Link Here
44
44
45
=head3 new
45
=head3 new
46
46
47
    my $availability = Koha::Illrequest::Workflow::Availability->new( $params, 'opac' )
47
    my $availability = Koha::ILL::Request::Workflow::Availability->new( $params, 'opac' )
48
48
49
Create a new Koha::Illrequest::Workflow child class object.
49
Create a new Koha::ILL::Request::Workflow child class object.
50
We store the metadata and ui_context
50
We store the metadata and ui_context
51
51
52
=cut
52
=cut
Lines 65-71 sub new { Link Here
65
65
66
=head3 prep_metadata
66
=head3 prep_metadata
67
67
68
    my $prepared = Koha::Illrequest::Workflow->prep_metadata($metadata);
68
    my $prepared = Koha::ILL::Request::Workflow->prep_metadata($metadata);
69
69
70
Given our metadata, return a string representing that metadata that can be
70
Given our metadata, return a string representing that metadata that can be
71
passed in a URL (encoded in JSON then Base64 encoded)
71
passed in a URL (encoded in JSON then Base64 encoded)
(-)a/Koha/Illrequest/Workflow/Availability.pm (-6 / +6 lines)
Lines 1-4 Link Here
1
package Koha::Illrequest::Workflow::Availability;
1
package Koha::ILL::Request::Workflow::Availability;
2
2
3
# Copyright 2019 PTFS Europe Ltd
3
# Copyright 2019 PTFS Europe Ltd
4
#
4
#
Lines 21-33 use Modern::Perl; Link Here
21
21
22
use JSON;
22
use JSON;
23
23
24
use base qw(Koha::Illrequest::Workflow);
24
use base qw(Koha::ILL::Request::Workflow);
25
25
26
use Koha::Plugins;
26
use Koha::Plugins;
27
27
28
=head1 NAME
28
=head1 NAME
29
29
30
Koha::Illrequest::Workflow::Availability - Koha ILL Availability Searching
30
Koha::ILL::Request::Workflow::Availability - Koha ILL Availability Searching
31
31
32
=head1 SYNOPSIS
32
=head1 SYNOPSIS
33
33
Lines 46-52 that can be used to search for item availability Link Here
46
=head3 get_services
46
=head3 get_services
47
47
48
    my $services =
48
    my $services =
49
      Koha::Illrequest::Workflow::Availability->get_services($params);
49
      Koha::ILL::Request::Workflow::Availability->get_services($params);
50
50
51
Given our metadata, iterate plugins with the right method and
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
52
check if they can service our request and, if so, return an arrayref
Lines 84-90 sub get_services { Link Here
84
=head3 show_availability
84
=head3 show_availability
85
85
86
    my $show_availability =
86
    my $show_availability =
87
    Koha::Illrequest::Workflow::Availability->show_availability($params);
87
    Koha::ILL::Request::Workflow::Availability->show_availability($params);
88
88
89
Given $params, return true if availability should be shown
89
Given $params, return true if availability should be shown
90
90
Lines 114-120 sub show_availability { Link Here
114
=head3 availability_template_params
114
=head3 availability_template_params
115
115
116
    my $availability_template_params =
116
    my $availability_template_params =
117
    Koha::Illrequest::Workflow::Availability->availability_template_params(
117
    Koha::ILL::Request::Workflow::Availability->availability_template_params(
118
        $params);
118
        $params);
119
119
120
Given $params, return true if availability should be shown
120
Given $params, return true if availability should be shown
(-)a/Koha/Illrequest/Workflow/TypeDisclaimer.pm (-25 / +28 lines)
Lines 1-4 Link Here
1
package Koha::Illrequest::Workflow::TypeDisclaimer;
1
package Koha::ILL::Request::Workflow::TypeDisclaimer;
2
2
3
# Copyright 2023 PTFS Europe Ltd
3
# Copyright 2023 PTFS Europe Ltd
4
#
4
#
Lines 21-27 use Modern::Perl; Link Here
21
21
22
use POSIX qw( strftime );
22
use POSIX qw( strftime );
23
23
24
use base qw(Koha::Illrequest::Workflow);
24
use base qw(Koha::ILL::Request::Workflow);
25
25
26
=head1 NAME
26
=head1 NAME
27
27
Lines 54-80 sub show_type_disclaimer { Link Here
54
54
55
    my $disc_sys_pref = $self->_get_type_disclaimer_sys_pref;
55
    my $disc_sys_pref = $self->_get_type_disclaimer_sys_pref;
56
56
57
    my $disc_info =
57
    my $disc_info = $self->_get_type_disclaimer_info(
58
      $self->_get_type_disclaimer_info( $self->_get_type_disclaimer_sys_pref,
58
        $self->_get_type_disclaimer_sys_pref,
59
        $self->{metadata}->{type} );
59
        $self->{metadata}->{type}
60
    );
60
61
61
    return
62
    return
62
63
63
      # ILLModuleDisclaimerByType contains correct YAML
64
        # ILLModuleDisclaimerByType contains correct YAML
64
      %{$disc_sys_pref}
65
        %{$disc_sys_pref}
65
66
66
      # Check that we have info to display for this type
67
        # Check that we have info to display for this type
67
      && $disc_info
68
        && $disc_info
68
69
69
      # ILLModuleDisclaimerByType contains at least 'all'
70
        # ILLModuleDisclaimerByType contains at least 'all'
70
      && $disc_sys_pref->{all}
71
        && $disc_sys_pref->{all}
71
72
72
      # Type disclaimer has not yet been submitted
73
        # Type disclaimer has not yet been submitted
73
      && !$self->{metadata}->{type_disclaimer_submitted}
74
        && !$self->{metadata}->{type_disclaimer_submitted}
74
75
75
     # The form has been submitted and the backend is able to create the request
76
        # The form has been submitted and the backend is able to create the request
76
      && $request->_backend_capability( 'can_create_request',
77
        && $request->_backend_capability(
77
        $self->{metadata} );
78
        'can_create_request',
79
        $self->{metadata}
80
        );
78
}
81
}
79
82
80
=head3 type_disclaimer_template_params
83
=head3 type_disclaimer_template_params
Lines 90-101 Given $params, return true if type disclaimer should be rendered Link Here
90
sub type_disclaimer_template_params {
93
sub type_disclaimer_template_params {
91
    my ( $self, $params ) = @_;
94
    my ( $self, $params ) = @_;
92
95
93
    my $disc_info =
96
    my $disc_info = $self->_get_type_disclaimer_info(
94
      $self->_get_type_disclaimer_info( $self->_get_type_disclaimer_sys_pref,
97
        $self->_get_type_disclaimer_sys_pref,
95
        $params->{type} );
98
        $params->{type}
99
    );
96
100
97
    $params->{method} = 'typedisclaimer' if $self->{ui_context} eq 'staff';
101
    $params->{method} = 'typedisclaimer' if $self->{ui_context} eq 'staff';
98
    delete $params->{stage}              if $self->{ui_context} eq 'staff';
102
    delete $params->{stage} if $self->{ui_context} eq 'staff';
99
103
100
    return (
104
    return (
101
        whole      => $params,
105
        whole      => $params,
Lines 129-135 sub after_request_created { Link Here
129
        value         => strftime( "%Y-%m-%dT%H:%M:%S", localtime( time() ) ),
133
        value         => strftime( "%Y-%m-%dT%H:%M:%S", localtime( time() ) ),
130
        readonly      => 0
134
        readonly      => 0
131
    };
135
    };
132
    Koha::Illrequestattribute->new($type_disclaimer_date)->store;
136
    Koha::ILL::Request::Attribute->new($type_disclaimer_date)->store;
133
137
134
    my $type_disclaimer_value = {
138
    my $type_disclaimer_value = {
135
        illrequest_id => $request->illrequest_id,
139
        illrequest_id => $request->illrequest_id,
Lines 137-143 sub after_request_created { Link Here
137
        value         => $params->{type_disclaimer_value},
141
        value         => $params->{type_disclaimer_value},
138
        readonly      => 0
142
        readonly      => 0
139
    };
143
    };
140
    Koha::Illrequestattribute->new($type_disclaimer_value)->store;
144
    Koha::ILL::Request::Attribute->new($type_disclaimer_value)->store;
141
}
145
}
142
146
143
=head3 _get_type_disclaimer_info
147
=head3 _get_type_disclaimer_info
Lines 154-160 sub _get_type_disclaimer_info { Link Here
154
    my ( $self, $disc_sys_pref, $type ) = @_;
158
    my ( $self, $disc_sys_pref, $type ) = @_;
155
159
156
    my @matching_request_type =
160
    my @matching_request_type =
157
      map ( $_ eq $type ? $_ : (), keys %$disc_sys_pref );
161
        map ( $_ eq $type ? $_ : (), keys %$disc_sys_pref );
158
162
159
    my $disc_info = undef;
163
    my $disc_info = undef;
160
    if ( scalar @matching_request_type ) {
164
    if ( scalar @matching_request_type ) {
Lines 162-169 sub _get_type_disclaimer_info { Link Here
162
166
163
        $disc_info->{text}   = $disc_sys_pref->{$type}->{text};
167
        $disc_info->{text}   = $disc_sys_pref->{$type}->{text};
164
        $disc_info->{av_cat} = $disc_sys_pref->{$type}->{av_category_code};
168
        $disc_info->{av_cat} = $disc_sys_pref->{$type}->{av_category_code};
165
    }
169
    } elsif ( $disc_sys_pref->{all} ) {
166
    elsif ( $disc_sys_pref->{all} ) {
167
        $disc_info->{text}   = $disc_sys_pref->{all}->{text};
170
        $disc_info->{text}   = $disc_sys_pref->{all}->{text};
168
        $disc_info->{av_cat} = $disc_sys_pref->{all}->{av_category_code};
171
        $disc_info->{av_cat} = $disc_sys_pref->{all}->{av_category_code};
169
    }
172
    }
(-)a/ill/ill-requests.pl (-6 / +6 lines)
Lines 29-36 use Koha::ILL::Comment; Link Here
29
use Koha::Illrequests;
29
use Koha::Illrequests;
30
use Koha::Illrequest;
30
use Koha::Illrequest;
31
use Koha::ILL::Batches;
31
use Koha::ILL::Batches;
32
use Koha::Illrequest::Workflow::Availability;
32
use Koha::ILL::Request::Workflow::Availability;
33
use Koha::Illrequest::Workflow::TypeDisclaimer;
33
use Koha::ILL::Request::Workflow::TypeDisclaimer;
34
use Koha::Libraries;
34
use Koha::Libraries;
35
use Koha::Plugins;
35
use Koha::Plugins;
36
36
Lines 128-136 if ( $backends_available ) { Link Here
128
128
129
        # Before request creation operations - Preparation
129
        # Before request creation operations - Preparation
130
        my $availability =
130
        my $availability =
131
          Koha::Illrequest::Workflow::Availability->new( $params, 'staff' );
131
          Koha::ILL::Request::Workflow::Availability->new( $params, 'staff' );
132
        my $type_disclaimer =
132
        my $type_disclaimer =
133
          Koha::Illrequest::Workflow::TypeDisclaimer->new( $params, 'staff' );
133
        Koha::ILL::Request::Workflow::TypeDisclaimer->new( $params, 'staff' );
134
134
135
        # ILLCheckAvailability operation
135
        # ILLCheckAvailability operation
136
        if ($availability->show_availability($request)) {
136
        if ($availability->show_availability($request)) {
Lines 324-330 if ( $backends_available ) { Link Here
324
            # Prepare availability searching, if required
324
            # Prepare availability searching, if required
325
            # Get the definition for the z39.50 plugin
325
            # Get the definition for the z39.50 plugin
326
            if ( C4::Context->preference('ILLCheckAvailability') ) {
326
            if ( C4::Context->preference('ILLCheckAvailability') ) {
327
                my $availability = Koha::Illrequest::Workflow::Availability->new(
327
                my $availability = Koha::ILL::Request::Workflow::Availability->new(
328
                    {
328
                    {
329
                        name => 'ILL availability - z39.50',
329
                        name => 'ILL availability - z39.50',
330
                        %{$request->metadata}
330
                        %{$request->metadata}
Lines 554-559 sub get_ill_availability { Link Here
554
        }
554
        }
555
    }
555
    }
556
556
557
    my $availability = Koha::Illrequest::Workflow::Availability->new($id_types, 'staff');
557
    my $availability = Koha::ILL::Request::Workflow::Availability->new( $id_types, 'staff' );
558
    return $availability->get_services();
558
    return $availability->get_services();
559
}
559
}
(-)a/opac/opac-illrequests.pl (-4 / +4 lines)
Lines 32-39 use Koha::Illrequests; Link Here
32
use Koha::Illrequest;
32
use Koha::Illrequest;
33
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
use Koha::Illrequest::Workflow::Availability;
35
use Koha::ILL::Request::Workflow::Availability;
36
use Koha::Illrequest::Workflow::TypeDisclaimer;
36
use Koha::ILL::Request::Workflow::TypeDisclaimer;
37
37
38
my $query = CGI->new;
38
my $query = CGI->new;
39
39
Lines 121-129 if ( $op eq 'list' ) { Link Here
121
121
122
        # Before request creation operations - Preparation
122
        # Before request creation operations - Preparation
123
        my $availability =
123
        my $availability =
124
          Koha::Illrequest::Workflow::Availability->new( $params, 'opac' );
124
          Koha::ILL::Request::Workflow::Availability->new( $params, 'opac' );
125
        my $type_disclaimer =
125
        my $type_disclaimer =
126
          Koha::Illrequest::Workflow::TypeDisclaimer->new( $params, 'opac' );
126
          Koha::ILL::Request::Workflow::TypeDisclaimer->new( $params, 'opac' );
127
127
128
        # ILLCheckAvailability operation
128
        # ILLCheckAvailability operation
129
        if ($availability->show_availability($request)) {
129
        if ($availability->show_availability($request)) {
(-)a/t/db_dependent/Illrequest/Availability.t (-5 / +5 lines)
Lines 25-31 use Test::MockObject; Link Here
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
27
28
use Koha::Illrequest::Workflow::Availability;
28
use Koha::ILL::Request::Workflow::Availability;
29
use Koha::Database;
29
use Koha::Database;
30
30
31
my $schema = Koha::Database->new->schema;
31
my $schema = Koha::Database->new->schema;
Lines 33-39 $schema->storage->txn_begin; Link Here
33
33
34
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
35
35
36
use_ok('Koha::Illrequest::Workflow::Availability');
36
use_ok('Koha::ILL::Request::Workflow::Availability');
37
37
38
my $metadata = {
38
my $metadata = {
39
    title  => 'This is a title',
39
    title  => 'This is a title',
Lines 48-56 foreach my $key ( keys %{$metadata} ) { Link Here
48
}
48
}
49
49
50
my $availability =
50
my $availability =
51
  Koha::Illrequest::Workflow::Availability->new( $sorted, 'staff' );
51
  Koha::ILL::Request::Workflow::Availability->new( $sorted, 'staff' );
52
52
53
isa_ok( $availability, 'Koha::Illrequest::Workflow::Availability' );
53
isa_ok( $availability, 'Koha::ILL::Request::Workflow::Availability' );
54
54
55
is(
55
is(
56
    $availability->prep_metadata($sorted),
56
    $availability->prep_metadata($sorted),
Lines 85-91 t::lib::Mocks::mock_preference( 'ILLCheckAvailability', 1 ); Link Here
85
85
86
# Mock not empty availability services
86
# Mock not empty availability services
87
my $availability_module =
87
my $availability_module =
88
  Test::MockModule->new('Koha::Illrequest::Workflow::Availability');
88
  Test::MockModule->new('Koha::ILL::Request::Workflow::Availability');
89
$availability_module->mock( 'get_services', [ { name => 'service' } ] );
89
$availability_module->mock( 'get_services', [ { name => 'service' } ] );
90
90
91
my $req_1 = $builder->build_object(
91
my $req_1 = $builder->build_object(
(-)a/t/db_dependent/Illrequest/TypeDisclaimer.t (-6 / +5 lines)
Lines 25-31 use Test::MockObject; Link Here
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
27
28
use Koha::Illrequest::Workflow::TypeDisclaimer;
28
use Koha::ILL::Request::Workflow::TypeDisclaimer;
29
use Koha::Database;
29
use Koha::Database;
30
30
31
my $schema = Koha::Database->new->schema;
31
my $schema = Koha::Database->new->schema;
Lines 33-39 $schema->storage->txn_begin; Link Here
33
33
34
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
35
35
36
use_ok('Koha::Illrequest::Workflow::TypeDisclaimer');
36
use_ok('Koha::ILL::Request::Workflow::TypeDisclaimer');
37
37
38
my $metadata = {
38
my $metadata = {
39
    title  => 'This is a title',
39
    title  => 'This is a title',
Lines 48-56 foreach my $key ( keys %{$metadata} ) { Link Here
48
}
48
}
49
49
50
my $type_disclaimer =
50
my $type_disclaimer =
51
  Koha::Illrequest::Workflow::TypeDisclaimer->new( $sorted, 'staff' );
51
  Koha::ILL::Request::Workflow::TypeDisclaimer->new( $sorted, 'staff' );
52
52
53
isa_ok( $type_disclaimer, 'Koha::Illrequest::Workflow::TypeDisclaimer' );
53
isa_ok( $type_disclaimer, 'Koha::ILL::Request::Workflow::TypeDisclaimer' );
54
54
55
is(
55
is(
56
    $type_disclaimer->prep_metadata($sorted),
56
    $type_disclaimer->prep_metadata($sorted),
Lines 108-114 is( $type_disclaimer->show_type_disclaimer($request), Link Here
108
108
109
# Mock ILLModuleDisclaimerByType with invalid YAML
109
# Mock ILLModuleDisclaimerByType with invalid YAML
110
my $type_disclaimer_module =
110
my $type_disclaimer_module =
111
  Test::MockModule->new('Koha::Illrequest::Workflow::TypeDisclaimer');
111
  Test::MockModule->new('Koha::ILL::Request::Workflow::TypeDisclaimer');
112
$type_disclaimer_module->mock( '_get_type_disclaimer_sys_pref', {} );
112
$type_disclaimer_module->mock( '_get_type_disclaimer_sys_pref', {} );
113
113
114
is( $type_disclaimer->show_type_disclaimer($request),
114
is( $type_disclaimer->show_type_disclaimer($request),
115
- 

Return to bug 35581