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

(-)a/Koha/Illrequest.pm (-40 / +7 lines)
Lines 704-711 sub getLimits { Link Here
704
=head3 getPrefix
704
=head3 getPrefix
705
705
706
    my $prefix = $abstract->getPrefix( {
706
    my $prefix = $abstract->getPrefix( {
707
        brw_cat => $brw_cat,
707
        branch  => $branch_code
708
        branch  => $branch_code,
709
    } );
708
    } );
710
709
711
Return the ILL prefix as defined by our $params: either per borrower category,
710
Return the ILL prefix as defined by our $params: either per borrower category,
Lines 715-727 per branch or the default. Link Here
715
714
716
sub getPrefix {
715
sub getPrefix {
717
    my ( $self, $params ) = @_;
716
    my ( $self, $params ) = @_;
718
    my $brn_prefixes = $self->_config->getPrefixes('branch');
717
    my $brn_prefixes = $self->_config->getPrefixes();
719
    my $brw_prefixes = $self->_config->getPrefixes('brw_cat');
718
    return $brn_prefixes->{$params->{branch}} || ""; # "the empty prefix"
720
721
    return $brw_prefixes->{$params->{brw_cat}}
722
        || $brn_prefixes->{$params->{branch}}
723
        || $brw_prefixes->{default}
724
        || "";                  # "the empty prefix"
725
}
719
}
726
720
727
#### Illrequests Imports
721
#### Illrequests Imports
Lines 954-965 file. Link Here
954
948
955
sub id_prefix {
949
sub id_prefix {
956
    my ( $self ) = @_;
950
    my ( $self ) = @_;
957
    my $brw = $self->patron;
958
    my $brw_cat = "dummy";
959
    $brw_cat = $brw->categorycode
960
        unless ( 'HASH' eq ref($brw) && $brw->{deleted} );
961
    my $prefix = $self->getPrefix( {
951
    my $prefix = $self->getPrefix( {
962
        brw_cat => $brw_cat,
963
        branch  => $self->branchcode,
952
        branch  => $self->branchcode,
964
    } );
953
    } );
965
    $prefix .= "-" if ( $prefix );
954
    $prefix .= "-" if ( $prefix );
Lines 991-996 sub _censor { Link Here
991
Overloaded I<TO_JSON> method that takes care of inserting calculated values
980
Overloaded I<TO_JSON> method that takes care of inserting calculated values
992
into the unblessed representation of the object.
981
into the unblessed representation of the object.
993
982
983
TODO: This method does nothing and is not called anywhere. However, bug 74325
984
touches it, so keeping this for now until both this and bug 74325 are merged,
985
at which point we can sort it out and remove it completely
986
994
=cut
987
=cut
995
988
996
sub TO_JSON {
989
sub TO_JSON {
Lines 999-1030 sub TO_JSON { Link Here
999
    my $object = $self->SUPER::TO_JSON();
992
    my $object = $self->SUPER::TO_JSON();
1000
    $object->{id_prefix} = $self->id_prefix;
993
    $object->{id_prefix} = $self->id_prefix;
1001
994
1002
    if ( scalar (keys %$embed) ) {
1003
        # Augment the request response with patron details if appropriate
1004
        if ( $embed->{patron} ) {
1005
            my $patron = $self->patron;
1006
            $object->{patron} = {
1007
                firstname  => $patron->firstname,
1008
                surname    => $patron->surname,
1009
                cardnumber => $patron->cardnumber
1010
            };
1011
        }
1012
        # Augment the request response with metadata details if appropriate
1013
        if ( $embed->{metadata} ) {
1014
            $object->{metadata} = $self->metadata;
1015
        }
1016
        # Augment the request response with status details if appropriate
1017
        if ( $embed->{capabilities} ) {
1018
            $object->{capabilities} = $self->capabilities;
1019
        }
1020
        # Augment the request response with library details if appropriate
1021
        if ( $embed->{library} ) {
1022
            $object->{library} = Koha::Libraries->find(
1023
                $self->branchcode
1024
            )->TO_JSON;
1025
        }
1026
    }
1027
1028
    return $object;
995
    return $object;
1029
}
996
}
1030
997
(-)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 53-61 my ( $template, $patronnumber, $cookie ) = get_template_and_user( { Link Here
53
} );
53
} );
54
54
55
# Are we able to actually work?
55
# Are we able to actually work?
56
my $backends = Koha::Illrequest::Config->new->available_backends;
56
my $cfg = Koha::Illrequest::Config->new;
57
my $backends = $cfg->available_backends;
58
my $has_branch = $cfg->has_branch;
57
my $backends_available = ( scalar @{$backends} > 0 );
59
my $backends_available = ( scalar @{$backends} > 0 );
58
$template->param( backends_available => $backends_available );
60
$template->param(
61
    backends_available => $backends_available,
62
    has_branch         => $has_branch
63
);
59
64
60
if ( $backends_available ) {
65
if ( $backends_available ) {
61
    if ( $op eq 'illview' ) {
66
    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 301-307 Link Here
301
    <div id="bd">
301
    <div id="bd">
302
        <div id="yui-main">
302
        <div id="yui-main">
303
            <div id="interlibraryloans" class="yui-b">
303
            <div id="interlibraryloans" class="yui-b">
304
        [% IF !backends_available %]
304
        [% IF !backends_available || !has_branch %]
305
            <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>
305
            <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>
306
        [% ELSE %]
306
        [% ELSE %]
307
                [% INCLUDE 'ill-toolbar.inc' %]
307
                [% INCLUDE 'ill-toolbar.inc' %]
308
- 

Return to bug 20996