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

(-)a/Koha/Illrequest.pm (-13 / +84 lines)
Lines 205-215 sub status_alias { Link Here
205
    my $current_status_alias = $self->SUPER::status_alias;
205
    my $current_status_alias = $self->SUPER::status_alias;
206
206
207
    if ($new_status_alias) {
207
    if ($new_status_alias) {
208
        # $new_status_alias may be one of two things, it may be a simple string
209
        # thereby just a drop in replacement for the native status_alias
210
        # method, but it may also be a hashref, as per:
211
        #
212
        # { status => '<new_status>', additional => {<arbitrary_hashref} }
213
        #
214
        # The purpose of 'additional' is to allow additional data to be
215
        # sent for logging when the status change is logged, in addition to
216
        # the new status. I'm not 100% happy with this solution, but since
217
        # we implcitly log when $request->status_alias(123) is called, I'm not
218
        # sure how else we can achieve it without explicitly calling logging
219
        # each time a status is changed, which would be grim
220
        #
208
        # Keep a record of the previous status before we change it,
221
        # Keep a record of the previous status before we change it,
209
        # we might need it
222
        # we might need it
210
        $self->{previous_status} = $current_status_alias ?
223
        $self->{previous_status} = $current_status_alias ?
211
            $current_status_alias :
224
            $current_status_alias :
212
            scalar $self->status;
225
            scalar $self->status;
226
        my $actual_status_alias;
227
        my $additional;
228
        if (ref $new_status_alias eq 'HASH') {
229
            $actual_status_alias = $new_status_alias->{status};
230
            $additional = $new_status_alias->{additional}
231
                if exists $new_status_alias->{additional};
232
        } else {
233
            $actual_status_alias = $new_status_alias;
234
        }
213
        # This is hackery to enable us to undefine
235
        # This is hackery to enable us to undefine
214
        # status_alias, since we need to have an overloaded
236
        # status_alias, since we need to have an overloaded
215
        # status_alias method to get us around the problem described
237
        # status_alias method to get us around the problem described
Lines 217-230 sub status_alias { Link Here
217
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
239
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
218
        # We need a way of accepting implied undef, so we can nullify
240
        # We need a way of accepting implied undef, so we can nullify
219
        # the status_alias column, when called from $self->status
241
        # the status_alias column, when called from $self->status
220
        my $val = $new_status_alias eq "-1" ? undef : $new_status_alias;
242
        my $val = $actual_status_alias eq "-1" ? undef : $actual_status_alias;
221
        my $ret = $self->SUPER::status_alias($val);
243
        my $ret = $self->SUPER::status_alias($val);
222
        my $val_to_log = $val ? $new_status_alias : scalar $self->status;
244
        my $val_to_log = $val ? $actual_status_alias : scalar $self->status;
223
        if ($ret) {
245
        if ($ret) {
224
            my $logger = Koha::Illrequest::Logger->new;
246
            my $logger = Koha::Illrequest::Logger->new;
225
            $logger->log_status_change({
247
            $logger->log_status_change({
226
                request => $self,
248
                request => $self,
227
                value   => $val_to_log
249
                value   => {
250
                    status => $val_to_log,
251
                    additional => $additional
252
                }
228
            });
253
            });
229
        } else {
254
        } else {
230
            delete $self->{previous_status};
255
            delete $self->{previous_status};
Lines 262-278 and sends a notice if appropriate Link Here
262
287
263
sub status {
288
sub status {
264
    my ( $self, $new_status) = @_;
289
    my ( $self, $new_status) = @_;
265
266
    my $current_status = $self->SUPER::status;
290
    my $current_status = $self->SUPER::status;
267
    my $current_status_alias = $self->SUPER::status_alias;
291
    my $current_status_alias = $self->SUPER::status_alias;
268
292
269
    if ($new_status) {
293
    if ($new_status) {
294
        # $new_status may be one of two things, it may be a simple string
295
        # thereby just a drop in replacement for the native status method,
296
        # but it may also be a hashref, as per:
297
        #
298
        # { status => '<new_status>', additional => {<arbitrary_hashref} }
299
        #
300
        # The purpose of 'additional' is to allow additional data to be
301
        # sent for logging when the status change is logged, in addition to
302
        # the new status. I'm not 100% happy with this solution, but since
303
        # we implcitly log when $request->status('XYZ') is called, I'm not
304
        # sure how else we can achieve it without explicitly calling logging
305
        # each time a status is changed, which would be grim
306
        #
270
        # Keep a record of the previous status before we change it,
307
        # Keep a record of the previous status before we change it,
271
        # we might need it
308
        # we might need it
272
        $self->{previous_status} = $current_status_alias ?
309
        $self->{previous_status} = $current_status_alias ?
273
            $current_status_alias :
310
            $current_status_alias :
274
            $current_status;
311
            $current_status;
275
        my $ret = $self->SUPER::status($new_status)->store;
312
        my $actual_status;
313
        my $additional;
314
        if (ref $new_status eq 'HASH') {
315
            $actual_status = $new_status->{status};
316
            $additional = $new_status->{additional}
317
                if exists $new_status->{additional};
318
        } else {
319
            $actual_status = $new_status;
320
        }
321
        my $ret = $self->SUPER::status($actual_status)->store;
276
        if ($current_status_alias) {
322
        if ($current_status_alias) {
277
            # This is hackery to enable us to undefine
323
            # This is hackery to enable us to undefine
278
            # status_alias, since we need to have an overloaded
324
            # status_alias, since we need to have an overloaded
Lines 281-292 sub status { Link Here
281
            # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
327
            # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
282
            # We need a way of passing implied undef to nullify status_alias
328
            # We need a way of passing implied undef to nullify status_alias
283
            # so we pass -1, which is special cased in the overloaded setter
329
            # so we pass -1, which is special cased in the overloaded setter
284
            $self->status_alias("-1");
330
            $self->status_alias({
331
                status     => "-1",
332
                additional => $additional
333
            });
285
        } else {
334
        } else {
286
            my $logger = Koha::Illrequest::Logger->new;
335
            my $logger = Koha::Illrequest::Logger->new;
287
            $logger->log_status_change({
336
            $logger->log_status_change({
288
                request => $self,
337
                request => $self,
289
                value   => $new_status
338
                value   => {
339
                    status     => $actual_status,
340
                    additional => $additional
341
                }
290
            });
342
            });
291
        }
343
        }
292
        delete $self->{previous_status};
344
        delete $self->{previous_status};
Lines 448-459 sub _core_status_graph { Link Here
448
            ui_method_icon => 'fa-check',
500
            ui_method_icon => 'fa-check',
449
        },
501
        },
450
        GENREQ => {
502
        GENREQ => {
451
            prev_actions   => [ 'NEW', 'REQREV' ],
503
            prev_actions   => [ 'NEW', 'REQREV', 'GENREQ' ],
452
            id             => 'GENREQ',
504
            id             => 'GENREQ',
453
            name           => 'Requested from partners',
505
            name           => 'Requested from partners',
454
            ui_method_name => 'Place request with partners',
506
            ui_method_name => 'Place request with partners',
455
            method         => 'generic_confirm',
507
            method         => 'generic_confirm',
456
            next_actions   => [ 'COMP', 'CHK' ],
508
            next_actions   => [ 'COMP', 'CHK', 'GENREQ' ],
457
            ui_method_icon => 'fa-send-o',
509
            ui_method_icon => 'fa-send-o',
458
        },
510
        },
459
        REQREV => {
511
        REQREV => {
Lines 1363-1369 sub generic_confirm { Link Here
1363
        if ($letter) {
1415
        if ($letter) {
1364
            my $result = C4::Letters::EnqueueLetter($params);
1416
            my $result = C4::Letters::EnqueueLetter($params);
1365
            if ( $result ) {
1417
            if ( $result ) {
1366
                $self->status("GENREQ")->store;
1418
                # This request may previously have been sent to partners
1419
                # so we want to check who
1420
                my $previous_partners = $self->requested_partners;
1421
                $self->status({
1422
                    status => "GENREQ",
1423
                    additional => {
1424
                        partner_email_now => $to,
1425
                        partner_email_previous => $previous_partners
1426
                    }
1427
                })->store;
1367
                $self->_backend_capability(
1428
                $self->_backend_capability(
1368
                    'set_requested_partners',
1429
                    'set_requested_partners',
1369
                    {
1430
                    {
Lines 1653-1668 sub store { Link Here
1653
    my $partners_string = $illRequest->requested_partners;
1714
    my $partners_string = $illRequest->requested_partners;
1654
1715
1655
Return the string representing the email addresses of the partners to
1716
Return the string representing the email addresses of the partners to
1656
whom a request has been sent
1717
whom a request has been sent or, alternatively, the full (unblessed)
1718
patron objects in an arrayref
1657
1719
1658
=cut
1720
=cut
1659
1721
1660
sub requested_partners {
1722
sub requested_partners {
1661
    my ( $self ) = @_;
1723
    my ( $self, $full ) = @_;
1662
    return $self->_backend_capability(
1724
    my $email = $self->_backend_capability(
1663
        'get_requested_partners',
1725
        'get_requested_partners',
1664
        { request => $self }
1726
        { request => $self }
1665
    );
1727
    );
1728
    return $email if (!$full);
1729
1730
    # The string may contain multiple addressed delimited by '; '
1731
    my @email_split = split(/; /, $email);
1732
    # Get the appropriate patron objects
1733
    return Koha::Patrons->search({
1734
        email => { -in => \@email_split },
1735
        categorycode => $self->_config->partner_code
1736
    })->unblessed;
1666
}
1737
}
1667
1738
1668
=head3 TO_JSON
1739
=head3 TO_JSON
(-)a/Koha/Illrequest/Logger.pm (-5 / +60 lines)
Lines 27-32 use C4::Templates; Link Here
27
use C4::Log qw( logaction );
27
use C4::Log qw( logaction );
28
use Koha::ActionLogs;
28
use Koha::ActionLogs;
29
use Koha::Notice::Template;
29
use Koha::Notice::Template;
30
use Koha::Patron;
30
31
31
=head1 NAME
32
=head1 NAME
32
33
Lines 146-164 sub log_status_change { Link Here
146
    my ( $self, $params ) = @_;
147
    my ( $self, $params ) = @_;
147
148
148
    if (defined $params->{request} && defined $params->{value}) {
149
    if (defined $params->{request} && defined $params->{value}) {
150
151
        my $infos = {
152
            log_origin    => 'core',
153
            status_before => $params->{request}->{previous_status},
154
            status_after  => $params->{value}->{status}
155
        };
156
157
        if (
158
            defined $params->{value}->{additional} &&
159
            $params->{value}->{additional}
160
        ) {
161
            $infos->{additional} = $params->{value}->{additional};
162
        }
163
149
        $self->log_something({
164
        $self->log_something({
150
            modulename   => 'ILL',
165
            modulename   => 'ILL',
151
            actionname   => 'STATUS_CHANGE',
166
            actionname   => 'STATUS_CHANGE',
152
            objectnumber => $params->{request}->id,
167
            objectnumber => $params->{request}->id,
153
            infos        => to_json({
168
            infos        => to_json($infos)
154
                log_origin    => 'core',
155
                status_before => $params->{request}->{previous_status},
156
                status_after  => $params->{value}
157
            })
158
        });
169
        });
159
    }
170
    }
160
}
171
}
161
172
173
=head3 logged_requested_partners
174
175
    Koha::Illrequest::Logger->logged_requested_partners($log);
176
177
Receive an request's log and return a hashref of all
178
patron objects associated with it, keyed on email
179
address. This enables us to display full information about them
180
and link to their patron page
181
182
=cut
183
184
sub _logged_requested_partners {
185
    my ( $params ) = @_;
186
    my @to = ();
187
    my @potential = ('partner_email_previous', 'partner_email_now');
188
    foreach my $partner(@potential) {
189
        if ($params->{info}->{additional}->{$partner}) {
190
            my @addresses = split(
191
                /; /,
192
                $params->{info}->{additional}->{$partner}
193
            );
194
            push @to, @addresses if scalar @addresses > 0;
195
        }
196
    }
197
    my $to_return = {};
198
    if (scalar @to > 0) {
199
        my $patrons = Koha::Patrons->search({
200
            email => { -in => \@to },
201
            categorycode => $params->{request}->_config->partner_code
202
        })->unblessed;
203
        foreach my $patron(@{$patrons}) {
204
            $to_return->{$patron->{email}} = $patron;
205
        }
206
        return $to_return;
207
    } else {
208
        return {};
209
    }
210
}
211
162
=head3 log_something
212
=head3 log_something
163
213
164
    Koha::IllRequest::Logger->log_something({
214
    Koha::IllRequest::Logger->log_something({
Lines 258-263 sub get_request_logs { Link Here
258
        $log->{notice_types} = $notice_hash;
308
        $log->{notice_types} = $notice_hash;
259
        $log->{aliases} = $alias_hash;
309
        $log->{aliases} = $alias_hash;
260
        $log->{info} = from_json($log->{info});
310
        $log->{info} = from_json($log->{info});
311
        my $full_partners = _logged_requested_partners({
312
            info => $log->{info},
313
            request => $request
314
        });
315
        $log->{requested_partners} = $full_partners if keys %{$full_partners};
261
        $log->{template} = $self->get_log_template({
316
        $log->{template} = $self->get_log_template({
262
            request => $request,
317
            request => $request,
263
            origin => $log->{info}->{log_origin},
318
            origin => $log->{info}->{log_origin},
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-3 / +7 lines)
Lines 637-644 Link Here
637
                                            [% request.statusalias.lib | html %]
637
                                            [% request.statusalias.lib | html %]
638
                                        [% ELSE %]
638
                                        [% ELSE %]
639
                                            [% request.capabilities.$req_status.name | html%]
639
                                            [% request.capabilities.$req_status.name | html%]
640
                                            [% IF request.requested_partners.length > 0 %]
640
                                            [% IF request.status == 'GENREQ' && request.requested_partners.length > 0 %]
641
                                                ([% request.requested_partners | html %])
641
                                            :
642
                                                [% FOREACH partner IN request.requested_partners(1) %]
643
                                                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% partner.borrowernumber %]">[% partner.email %] ([% partner.cardnumber %])</a>
644
                                                    [% IF loop.index() < loop.size() - 1 %];[% END %]
645
                                                [% END %]
642
                                            [% END %]
646
                                            [% END %]
643
                                        [% END %]
647
                                        [% END %]
644
                                    </li>
648
                                    </li>
Lines 722-728 Link Here
722
                                [% IF request.logs.size > 0 %]
726
                                [% IF request.logs.size > 0 %]
723
                                    [% FOREACH log IN request.logs %]
727
                                    [% FOREACH log IN request.logs %]
724
                                        [% tpl = log.template %]
728
                                        [% tpl = log.template %]
725
                                        [% INCLUDE $tpl log=log %]
729
                                        [% INCLUDE $tpl log=log request=request %]
726
                                    [% END %]
730
                                    [% END %]
727
                                [% ELSE %]
731
                                [% ELSE %]
728
                                    There are no recorded logs for this request
732
                                    There are no recorded logs for this request
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/log/status_change.tt (-1 / +16 lines)
Lines 5-12 Link Here
5
[% before = log.info.status_before %]
5
[% before = log.info.status_before %]
6
[% display_before = log.aliases.$before ? log.aliases.$before.lib : request.capabilities.$before.name %]
6
[% display_before = log.aliases.$before ? log.aliases.$before.lib : request.capabilities.$before.name %]
7
from &quot;[% display_before | html %]&quot;
7
from &quot;[% display_before | html %]&quot;
8
[% IF before == "GENREQ" && log.info.additional.partner_email_previous %]
9
     (
10
     [% FOREACH add IN log.info.additional.partner_email_previous.split('; ') %]
11
         [% borrowernumber = log.requested_partners.$add.borrowernumber %]
12
         <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber | html %]">[% add | url %]</a>
13
     [% END %]
14
     )
15
[% END %]
8
[% END %]
16
[% END %]
9
[% after = log.info.status_after %]
17
[% after = log.info.status_after %]
10
[% display_after = log.aliases.$after ? log.aliases.$after.lib : request.capabilities.$after.name %]
18
[% display_after = log.aliases.$after ? log.aliases.$after.lib : request.capabilities.$after.name %]
11
to &quot;[% display_after | html %]&quot;
19
to &quot;[% display_after | html %]&quot;
20
[% IF after == "GENREQ" && log.info.additional.partner_email_now %]
21
    (
22
    [% FOREACH add IN log.info.additional.partner_email_now.split('; ') %]
23
        [% borrowernumber = log.requested_partners.$add.borrowernumber %]
24
        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber | html %]">[% add | url %]</a>
25
    [% END %]
26
    )
27
[% END %]
12
</p>
28
</p>
13
- 

Return to bug 22531