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

(-)a/Koha/Illrequest.pm (-44 / +7 lines)
Lines 717-724 sub getLimits { Link Here
717
=head3 getPrefix
717
=head3 getPrefix
718
718
719
    my $prefix = $abstract->getPrefix( {
719
    my $prefix = $abstract->getPrefix( {
720
        brw_cat => $brw_cat,
720
        branch  => $branch_code
721
        branch  => $branch_code,
722
    } );
721
    } );
723
722
724
Return the ILL prefix as defined by our $params: either per borrower category,
723
Return the ILL prefix as defined by our $params: either per borrower category,
Lines 728-740 per branch or the default. Link Here
728
727
729
sub getPrefix {
728
sub getPrefix {
730
    my ( $self, $params ) = @_;
729
    my ( $self, $params ) = @_;
731
    my $brn_prefixes = $self->_config->getPrefixes('branch');
730
    my $brn_prefixes = $self->_config->getPrefixes();
732
    my $brw_prefixes = $self->_config->getPrefixes('brw_cat');
731
    return $brn_prefixes->{$params->{branch}} || ""; # "the empty prefix"
733
734
    return $brw_prefixes->{$params->{brw_cat}}
735
        || $brn_prefixes->{$params->{branch}}
736
        || $brw_prefixes->{default}
737
        || "";                  # "the empty prefix"
738
}
732
}
739
733
740
=head3 get_type
734
=head3 get_type
Lines 982-993 file. Link Here
982
976
983
sub id_prefix {
977
sub id_prefix {
984
    my ( $self ) = @_;
978
    my ( $self ) = @_;
985
    my $brw = $self->patron;
986
    my $brw_cat = "dummy";
987
    $brw_cat = $brw->categorycode
988
        unless ( 'HASH' eq ref($brw) && $brw->{deleted} );
989
    my $prefix = $self->getPrefix( {
979
    my $prefix = $self->getPrefix( {
990
        brw_cat => $brw_cat,
991
        branch  => $self->branchcode,
980
        branch  => $self->branchcode,
992
    } );
981
    } );
993
    $prefix .= "-" if ( $prefix );
982
    $prefix .= "-" if ( $prefix );
Lines 1019-1024 sub _censor { Link Here
1019
Overloaded I<TO_JSON> method that takes care of inserting calculated values
1008
Overloaded I<TO_JSON> method that takes care of inserting calculated values
1020
into the unblessed representation of the object.
1009
into the unblessed representation of the object.
1021
1010
1011
TODO: This method does nothing and is not called anywhere. However, bug 74325
1012
touches it, so keeping this for now until both this and bug 74325 are merged,
1013
at which point we can sort it out and remove it completely
1014
1022
=cut
1015
=cut
1023
1016
1024
sub TO_JSON {
1017
sub TO_JSON {
Lines 1027-1062 sub TO_JSON { Link Here
1027
    my $object = $self->SUPER::TO_JSON();
1020
    my $object = $self->SUPER::TO_JSON();
1028
    $object->{id_prefix} = $self->id_prefix;
1021
    $object->{id_prefix} = $self->id_prefix;
1029
1022
1030
    if ( scalar (keys %$embed) ) {
1031
        # Augment the request response with patron details if appropriate
1032
        if ( $embed->{patron} ) {
1033
            my $patron = $self->patron;
1034
            $object->{patron} = {
1035
                firstname  => $patron->firstname,
1036
                surname    => $patron->surname,
1037
                cardnumber => $patron->cardnumber
1038
            };
1039
        }
1040
        # Augment the request response with metadata details if appropriate
1041
        if ( $embed->{metadata} ) {
1042
            $object->{metadata} = $self->metadata;
1043
        }
1044
        # Augment the request response with status details if appropriate
1045
        if ( $embed->{capabilities} ) {
1046
            $object->{capabilities} = $self->capabilities;
1047
        }
1048
        # Augment the request response with library details if appropriate
1049
        if ( $embed->{library} ) {
1050
            $object->{library} = Koha::Libraries->find(
1051
                $self->branchcode
1052
            )->TO_JSON;
1053
        }
1054
        # Augment the request response with the number of comments if appropriate
1055
        if ( $embed->{comments} ) {
1056
            $object->{comments} = $self->illcomments->count;
1057
        }
1058
    }
1059
1060
    return $object;
1023
    return $object;
1061
}
1024
}
1062
1025
(-)a/Koha/Illrequest/Config.pm (-7 / +15 lines)
Lines 117-122 sub available_backends { Link Here
117
    return \@backends;
117
    return \@backends;
118
}
118
}
119
119
120
=head has_branch
121
122
Return whether a 'branch' block is defined
123
124
=cut
125
126
sub has_branch {
127
    my ( $self ) = @_;
128
    return $self->{configuration}->{raw_config}->{branch};
129
}
130
120
=head3 partner_code
131
=head3 partner_code
121
132
122
    $partner_code = $config->partner_code($new_code);
133
    $partner_code = $config->partner_code($new_code);
Lines 150-167 sub limits { Link Here
150
161
151
=head3 getPrefixes
162
=head3 getPrefixes
152
163
153
    my $prefixes = $config->getPrefixes('brw_cat' | 'branch');
164
    my $prefixes = $config->getPrefixes();
154
165
155
Return the prefix for ILLs defined by our config.
166
Return the branch prefix for ILLs defined by our config.
156
167
157
=cut
168
=cut
158
169
159
sub getPrefixes {
170
sub getPrefixes {
160
    my ( $self, $type ) = @_;
171
    my ( $self ) = @_;
161
    die "Unexpected type." unless ( $type eq 'brw_cat' || $type eq 'branch' );
172
    return $self->{configuration}->{prefixes}->{branch};
162
    my $values = $self->{configuration}->{prefixes}->{$type};
163
    $values->{default} = $self->{configuration}->{prefixes}->{default};
164
    return $values;
165
}
173
}
166
174
167
=head3 getLimitRules
175
=head3 getLimitRules
(-)a/Koha/REST/V1/Illrequests.pm (-15 / +88 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Illrequests;
22
use Koha::Illrequests;
23
use Koha::Illrequestattributes;
24
use Koha::Libraries;
25
use Koha::Patrons;
23
use Koha::Libraries;
26
use Koha::Libraries;
24
27
25
=head1 NAME
28
=head1 NAME
Lines 38-71 sub list { Link Here
38
    my $c = shift->openapi->valid_input or return;
41
    my $c = shift->openapi->valid_input or return;
39
42
40
    my $args = $c->req->params->to_hash // {};
43
    my $args = $c->req->params->to_hash // {};
41
    my $filter;
42
    my $output = [];
43
44
44
    # Create a hash where all keys are embedded values
45
    # Create a hash where all keys are embedded values
45
    # Enables easy checking
46
    # Enables easy checking
46
    my %embed;
47
    my %embed;
48
    my $args_arr = (ref $args->{embed} eq 'ARRAY') ? $args->{embed} : [ $args->{embed} ];
47
    if (defined $args->{embed}) {
49
    if (defined $args->{embed}) {
48
        %embed = map { $_ => 1 }  @{$args->{embed}};
50
        %embed = map { $_ => 1 }  @{$args_arr};
49
        delete $args->{embed};
51
        delete $args->{embed};
50
    }
52
    }
51
53
52
    for my $filter_param ( keys %$args ) {
54
    my $requests = Koha::Illrequests->unblessed;
53
        my @values = split(/,/, $args->{$filter_param});
55
54
        $filter->{$filter_param} = \@values;
56
    # Identify patrons & branches that
57
    # we're going to need and get them
58
    my $to_fetch = {};
59
    $to_fetch->{patrons} = {} if $embed{patron};
60
    $to_fetch->{branches} = {} if $embed{library};
61
    $to_fetch->{capabilities} = {} if $embed{capabilities};
62
    foreach my $req(@{$requests}) {
63
        $to_fetch->{patrons}->{$req->{borrowernumber}} = 1 if $embed{patron};
64
        $to_fetch->{branches}->{$req->{branchcode}} = 1 if $embed{library};
65
        $to_fetch->{capabilities}->{$req->{backend}} = 1 if $embed{capabilities};
55
    }
66
    }
56
67
57
    my $requests = Koha::Illrequests->search($filter);
68
    # Fetch the patrons we need
69
    my $patron_arr = [];
70
    if ($embed{patron}) {
71
        my @patron_ids = keys %{$to_fetch->{patrons}};
72
        if (scalar @patron_ids > 0) {
73
            my $where = {
74
                borrowernumber => { -in => \@patron_ids }
75
            };
76
            $patron_arr = Koha::Patrons->search($where)->unblessed;
77
        }
78
    }
58
79
59
    if ( scalar (keys %embed) )
80
    # Fetch the branches we need
60
    {
81
    my $branch_arr = [];
61
        # Need to embed stuff
82
    if ($embed{library}) {
62
        my @results = map { $_->TO_JSON(\%embed) } $requests->as_list;
83
        my @branchcodes = keys %{$to_fetch->{branches}};
63
        return $c->render( status => 200, openapi => \@results );
84
        if (scalar @branchcodes > 0) {
85
            my $where = {
86
                branchcode => { -in => \@branchcodes }
87
            };
88
            $branch_arr = Koha::Libraries->search($where)->unblessed;
89
        }
64
    }
90
    }
65
    else
91
66
    {
92
    # Fetch the capabilities we need
67
        return $c->render( status => 200, openapi => $requests );
93
    if ($embed{capabilities}) {
94
        my @backends = keys %{$to_fetch->{capabilities}};
95
        if (scalar @backends > 0) {
96
            foreach my $bc(@backends) {
97
                my $backend = Koha::Illrequest->new->load_backend($bc);
98
                $to_fetch->{$bc} = $backend->capabilities;
99
            }
100
        }
68
    }
101
    }
102
103
104
    # Now we've got all associated users and branches,
105
    # we can augment the request objects
106
    foreach my $req(@{$requests}) {
107
        my $r = Koha::Illrequests->new->find($req->{illrequest_id});
108
        $req->{id_prefix} = $r->id_prefix;
109
        foreach my $p(@{$patron_arr}) {
110
            if ($p->{borrowernumber} == $req->{borrowernumber}) {
111
                $req->{patron} = {
112
                    firstname  => $p->{firstname},
113
                    surname    => $p->{surname},
114
                    cardnumber => $p->{cardnumber}
115
                };
116
                last;
117
            }
118
        }
119
        foreach my $b(@{$branch_arr}) {
120
            if ($b->{branchcode} eq $req->{branchcode}) {
121
                $req->{library} = $b;
122
                last;
123
            }
124
        }
125
        if ($embed{metadata}) {
126
            my $metadata = Koha::Illrequestattributes->search(
127
                { illrequest_id => $req->{illrequest_id} },
128
                { columns => [qw/type value/] }
129
            )->unblessed;
130
            my $meta_hash = {};
131
            foreach my $meta(@{$metadata}) {
132
                $meta_hash->{$meta->{type}} = $meta->{value};
133
            }
134
            $req->{metadata} = $meta_hash;
135
        }
136
        if ($embed{capabilities}) {
137
            $req->{capabilities} = $to_fetch->{$req->{backend}};
138
        }
139
    }
140
141
    return $c->render( status => 200, openapi => $requests );
69
}
142
}
70
143
71
1;
144
1;
(-)a/about.pl (+7 lines)
Lines 282-287 if ( C4::Context->preference('ILLModule') ) { Link Here
282
        $warnILLConfiguration = 1;
282
        $warnILLConfiguration = 1;
283
    }
283
    }
284
284
285
286
    if ( !$ill_config_from_file->{branch} ) {
287
        # branch not defined
288
        $template->param( ill_branch_not_defined => 1 );
289
        $warnILLConfiguration = 1;
290
    }
291
285
    $template->param( warnILLConfiguration => $warnILLConfiguration );
292
    $template->param( warnILLConfiguration => $warnILLConfiguration );
286
}
293
}
287
294
(-)a/ill/ill-requests.pl (-2 / +7 lines)
Lines 55-63 my ( $template, $patronnumber, $cookie ) = get_template_and_user( { Link Here
55
} );
55
} );
56
56
57
# Are we able to actually work?
57
# Are we able to actually work?
58
my $backends = Koha::Illrequest::Config->new->available_backends;
58
my $cfg = Koha::Illrequest::Config->new;
59
my $backends = $cfg->available_backends;
60
my $has_branch = $cfg->has_branch;
59
my $backends_available = ( scalar @{$backends} > 0 );
61
my $backends_available = ( scalar @{$backends} > 0 );
60
$template->param( backends_available => $backends_available );
62
$template->param(
63
    backends_available => $backends_available,
64
    has_branch         => $has_branch
65
);
61
66
62
if ( $backends_available ) {
67
if ( $backends_available ) {
63
    if ( $op eq 'illview' ) {
68
    if ( $op eq 'illview' ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt (+5 lines)
Lines 289-294 Link Here
289
                    The ILL module is enabled, but no 'partner_code' defined in koha-conf.xml. Falling back to the hardcoded 'ILLLIBS'.
289
                    The ILL module is enabled, but no 'partner_code' defined in koha-conf.xml. Falling back to the hardcoded 'ILLLIBS'.
290
                    </td></tr>
290
                    </td></tr>
291
                  [%END %]
291
                  [%END %]
292
                  [% IF ill_branch_not_defined %]
293
                    <tr><th scope="row"><b>Warning</b> </th><td>
294
                    The ILL module is enabled, but no 'branch' block is defined in koha-conf.xml. You must define this block before use.
295
                    </td></tr>
296
                  [%END %]
292
                  [% IF ill_partner_code_doesnt_exist %]
297
                  [% IF ill_partner_code_doesnt_exist %]
293
                    <tr><th scope="row"><b>Warning</b> </th><td>
298
                    <tr><th scope="row"><b>Warning</b> </th><td>
294
                    The ILL module is enabled, but the configured 'partner_code' ([% ill_partner_code_doesnt_exist | html %]) is not defined on the system.
299
                    The ILL module is enabled, but the configured 'partner_code' ([% ill_partner_code_doesnt_exist | html %]) is not defined on the system.
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-2 / +1 lines)
Lines 325-331 Link Here
325
    <div id="bd">
325
    <div id="bd">
326
        <div id="yui-main">
326
        <div id="yui-main">
327
            <div id="interlibraryloans" class="yui-b">
327
            <div id="interlibraryloans" class="yui-b">
328
        [% IF !backends_available %]
328
        [% IF !backends_available || !has_branch %]
329
            <div class="dialog message">ILL module configuration problem. Take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo">about page</a></div>
329
            <div class="dialog message">ILL module configuration problem. Take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo">about page</a></div>
330
        [% ELSE %]
330
        [% ELSE %]
331
                [% INCLUDE 'ill-toolbar.inc' %]
331
                [% INCLUDE 'ill-toolbar.inc' %]
332
- 

Return to bug 20996