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

(-)a/Koha/Illrequest.pm (-12 / +84 lines)
Lines 229-239 sub status_alias { Link Here
229
    my $current_status_alias = $self->SUPER::status_alias;
229
    my $current_status_alias = $self->SUPER::status_alias;
230
230
231
    if ($new_status_alias) {
231
    if ($new_status_alias) {
232
        # $new_status_alias may be one of two things, it may be a simple string
233
        # thereby just a drop in replacement for the native status_alias
234
        # method, but it may also be a hashref, as per:
235
        #
236
        # { status => '<new_status>', additional => {<arbitrary_hashref} }
237
        #
238
        # The purpose of 'additional' is to allow additional data to be
239
        # sent for logging when the status change is logged, in addition to
240
        # the new status. I'm not 100% happy with this solution, but since
241
        # we implcitly log when $request->status_alias(123) is called, I'm not
242
        # sure how else we can achieve it without explicitly calling logging
243
        # each time a status is changed, which would be grim
244
        #
232
        # Keep a record of the previous status before we change it,
245
        # Keep a record of the previous status before we change it,
233
        # we might need it
246
        # we might need it
234
        $self->{previous_status} = $current_status_alias ?
247
        $self->{previous_status} = $current_status_alias ?
235
            $current_status_alias :
248
            $current_status_alias :
236
            scalar $self->status;
249
            scalar $self->status;
250
        my $actual_status_alias;
251
        my $additional;
252
        if (ref $new_status_alias eq 'HASH') {
253
            $actual_status_alias = $new_status_alias->{status};
254
            $additional = $new_status_alias->{additional}
255
                if exists $new_status_alias->{additional};
256
        } else {
257
            $actual_status_alias = $new_status_alias;
258
        }
237
        # This is hackery to enable us to undefine
259
        # This is hackery to enable us to undefine
238
        # status_alias, since we need to have an overloaded
260
        # status_alias, since we need to have an overloaded
239
        # status_alias method to get us around the problem described
261
        # status_alias method to get us around the problem described
Lines 241-254 sub status_alias { Link Here
241
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
263
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
242
        # We need a way of accepting implied undef, so we can nullify
264
        # We need a way of accepting implied undef, so we can nullify
243
        # the status_alias column, when called from $self->status
265
        # the status_alias column, when called from $self->status
244
        my $val = $new_status_alias eq "-1" ? undef : $new_status_alias;
266
        my $val = $actual_status_alias eq "-1" ? undef : $actual_status_alias;
245
        my $ret = $self->SUPER::status_alias($val);
267
        my $ret = $self->SUPER::status_alias($val);
246
        my $val_to_log = $val ? $new_status_alias : scalar $self->status;
268
        my $val_to_log = $val ? $actual_status_alias : scalar $self->status;
247
        if ($ret) {
269
        if ($ret) {
248
            my $logger = Koha::Illrequest::Logger->new;
270
            my $logger = Koha::Illrequest::Logger->new;
249
            $logger->log_status_change({
271
            $logger->log_status_change({
250
                request => $self,
272
                request => $self,
251
                value   => $val_to_log
273
                value   => {
274
                    status => $val_to_log,
275
                    additional => $additional
276
                }
252
            });
277
            });
253
        } else {
278
        } else {
254
            delete $self->{previous_status};
279
            delete $self->{previous_status};
Lines 286-302 and sends a notice if appropriate Link Here
286
311
287
sub status {
312
sub status {
288
    my ( $self, $new_status) = @_;
313
    my ( $self, $new_status) = @_;
289
290
    my $current_status = $self->SUPER::status;
314
    my $current_status = $self->SUPER::status;
291
    my $current_status_alias = $self->SUPER::status_alias;
315
    my $current_status_alias = $self->SUPER::status_alias;
292
316
293
    if ($new_status) {
317
    if ($new_status) {
318
        # $new_status may be one of two things, it may be a simple string
319
        # thereby just a drop in replacement for the native status method,
320
        # but it may also be a hashref, as per:
321
        #
322
        # { status => '<new_status>', additional => {<arbitrary_hashref} }
323
        #
324
        # The purpose of 'additional' is to allow additional data to be
325
        # sent for logging when the status change is logged, in addition to
326
        # the new status. I'm not 100% happy with this solution, but since
327
        # we implcitly log when $request->status('XYZ') is called, I'm not
328
        # sure how else we can achieve it without explicitly calling logging
329
        # each time a status is changed, which would be grim
330
        #
294
        # Keep a record of the previous status before we change it,
331
        # Keep a record of the previous status before we change it,
295
        # we might need it
332
        # we might need it
296
        $self->{previous_status} = $current_status_alias ?
333
        $self->{previous_status} = $current_status_alias ?
297
            $current_status_alias :
334
            $current_status_alias :
298
            $current_status;
335
            $current_status;
299
        my $ret = $self->SUPER::status($new_status)->store;
336
        my $actual_status;
337
        my $additional;
338
        if (ref $new_status eq 'HASH') {
339
            $actual_status = $new_status->{status};
340
            $additional = $new_status->{additional}
341
                if exists $new_status->{additional};
342
        } else {
343
            $actual_status = $new_status;
344
        }
345
        my $ret = $self->SUPER::status($actual_status)->store;
300
        if ($current_status_alias) {
346
        if ($current_status_alias) {
301
            # This is hackery to enable us to undefine
347
            # This is hackery to enable us to undefine
302
            # status_alias, since we need to have an overloaded
348
            # status_alias, since we need to have an overloaded
Lines 305-316 sub status { Link Here
305
            # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
351
            # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
306
            # We need a way of passing implied undef to nullify status_alias
352
            # We need a way of passing implied undef to nullify status_alias
307
            # so we pass -1, which is special cased in the overloaded setter
353
            # so we pass -1, which is special cased in the overloaded setter
308
            $self->status_alias("-1");
354
            $self->status_alias({
355
                status     => "-1",
356
                additional => $additional
357
            });
309
        } else {
358
        } else {
310
            my $logger = Koha::Illrequest::Logger->new;
359
            my $logger = Koha::Illrequest::Logger->new;
311
            $logger->log_status_change({
360
            $logger->log_status_change({
312
                request => $self,
361
                request => $self,
313
                value   => $new_status
362
                value   => {
363
                    status     => $actual_status,
364
                    additional => $additional
365
                }
314
            });
366
            });
315
        }
367
        }
316
        delete $self->{previous_status};
368
        delete $self->{previous_status};
Lines 473-484 sub _core_status_graph { Link Here
473
            ui_method_icon => 'fa-check',
525
            ui_method_icon => 'fa-check',
474
        },
526
        },
475
        GENREQ => {
527
        GENREQ => {
476
            prev_actions   => [ 'NEW', 'REQREV' ],
528
            prev_actions   => [ 'NEW', 'REQREV', 'GENREQ' ],
477
            id             => 'GENREQ',
529
            id             => 'GENREQ',
478
            name           => 'Requested from partners',
530
            name           => 'Requested from partners',
479
            ui_method_name => 'Place request with partners',
531
            ui_method_name => 'Place request with partners',
480
            method         => 'generic_confirm',
532
            method         => 'generic_confirm',
481
            next_actions   => [ 'COMP', 'CHK' ],
533
            next_actions   => [ 'COMP', 'CHK', 'GENREQ' ],
482
            ui_method_icon => 'fa-send-o',
534
            ui_method_icon => 'fa-send-o',
483
        },
535
        },
484
        REQREV => {
536
        REQREV => {
Lines 1440-1445 sub generic_confirm { Link Here
1440
                };
1492
                };
1441
                my $result = C4::Letters::EnqueueLetter($params);
1493
                my $result = C4::Letters::EnqueueLetter($params);
1442
                if ( $result ) {
1494
                if ( $result ) {
1495
                    # This request may previously have been sent to partners
1496
                    # so we want to check who
1497
                    my $previous_partners = $self->requested_partners;
1498
                    $self->status({
1499
                        status => "GENREQ",
1500
                        additional => {
1501
                            partner_email_now => $to,
1502
                            partner_email_previous => $previous_partners
1503
                        }
1504
                    })->store;
1443
                    push @queued, $patron->email;
1505
                    push @queued, $patron->email;
1444
                }
1506
                }
1445
            }
1507
            }
Lines 1799-1814 sub store { Link Here
1799
    my $partners_string = $illRequest->requested_partners;
1861
    my $partners_string = $illRequest->requested_partners;
1800
1862
1801
Return the string representing the email addresses of the partners to
1863
Return the string representing the email addresses of the partners to
1802
whom a request has been sent
1864
whom a request has been sent or, alternatively, the full (unblessed)
1865
patron objects in an arrayref
1803
1866
1804
=cut
1867
=cut
1805
1868
1806
sub requested_partners {
1869
sub requested_partners {
1807
    my ( $self ) = @_;
1870
    my ( $self, $full ) = @_;
1808
    return $self->_backend_capability(
1871
    my $email = $self->_backend_capability(
1809
        'get_requested_partners',
1872
        'get_requested_partners',
1810
        { request => $self }
1873
        { request => $self }
1811
    );
1874
    );
1875
    return $email if (!$full);
1876
1877
    # The string may contain multiple addressed delimited by '; '
1878
    my @email_split = split(/; /, $email);
1879
    # Get the appropriate patron objects
1880
    return Koha::Patrons->search({
1881
        email => { -in => \@email_split },
1882
        categorycode => $self->_config->partner_code
1883
    })->unblessed;
1812
}
1884
}
1813
1885
1814
=head3 TO_JSON
1886
=head3 TO_JSON
(-)a/Koha/Illrequest/Logger.pm (-5 / +60 lines)
Lines 26-31 use C4::Templates; Link Here
26
use C4::Log qw( logaction );
26
use C4::Log qw( logaction );
27
use Koha::ActionLogs;
27
use Koha::ActionLogs;
28
use Koha::Notice::Template;
28
use Koha::Notice::Template;
29
use Koha::Patron;
29
30
30
=head1 NAME
31
=head1 NAME
31
32
Lines 145-163 sub log_status_change { Link Here
145
    my ( $self, $params ) = @_;
146
    my ( $self, $params ) = @_;
146
147
147
    if (defined $params->{request} && defined $params->{value}) {
148
    if (defined $params->{request} && defined $params->{value}) {
149
150
        my $infos = {
151
            log_origin    => 'core',
152
            status_before => $params->{request}->{previous_status},
153
            status_after  => $params->{value}->{status}
154
        };
155
156
        if (
157
            defined $params->{value}->{additional} &&
158
            $params->{value}->{additional}
159
        ) {
160
            $infos->{additional} = $params->{value}->{additional};
161
        }
162
148
        $self->log_something({
163
        $self->log_something({
149
            modulename   => 'ILL',
164
            modulename   => 'ILL',
150
            actionname   => 'STATUS_CHANGE',
165
            actionname   => 'STATUS_CHANGE',
151
            objectnumber => $params->{request}->id,
166
            objectnumber => $params->{request}->id,
152
            infos        => to_json({
167
            infos        => to_json($infos)
153
                log_origin    => 'core',
154
                status_before => $params->{request}->{previous_status},
155
                status_after  => $params->{value}
156
            })
157
        });
168
        });
158
    }
169
    }
159
}
170
}
160
171
172
=head3 logged_requested_partners
173
174
    Koha::Illrequest::Logger->logged_requested_partners($log);
175
176
Receive an request's log and return a hashref of all
177
patron objects associated with it, keyed on email
178
address. This enables us to display full information about them
179
and link to their patron page
180
181
=cut
182
183
sub _logged_requested_partners {
184
    my ( $params ) = @_;
185
    my @to = ();
186
    my @potential = ('partner_email_previous', 'partner_email_now');
187
    foreach my $partner(@potential) {
188
        if ($params->{info}->{additional}->{$partner}) {
189
            my @addresses = split(
190
                /; /,
191
                $params->{info}->{additional}->{$partner}
192
            );
193
            push @to, @addresses if scalar @addresses > 0;
194
        }
195
    }
196
    my $to_return = {};
197
    if (scalar @to > 0) {
198
        my $patrons = Koha::Patrons->search({
199
            email => { -in => \@to },
200
            categorycode => $params->{request}->_config->partner_code
201
        })->unblessed;
202
        foreach my $patron(@{$patrons}) {
203
            $to_return->{$patron->{email}} = $patron;
204
        }
205
        return $to_return;
206
    } else {
207
        return {};
208
    }
209
}
210
161
=head3 log_something
211
=head3 log_something
162
212
163
    Koha::IllRequest::Logger->log_something({
213
    Koha::IllRequest::Logger->log_something({
Lines 261-266 sub get_request_logs { Link Here
261
        $log->{notice_types} = $notice_hash;
311
        $log->{notice_types} = $notice_hash;
262
        $log->{aliases} = $alias_hash;
312
        $log->{aliases} = $alias_hash;
263
        $log->{info} = from_json($log->{info});
313
        $log->{info} = from_json($log->{info});
314
        my $full_partners = _logged_requested_partners({
315
            info => $log->{info},
316
            request => $request
317
        });
318
        $log->{requested_partners} = $full_partners if keys %{$full_partners};
264
        $log->{template} = $self->get_log_template({
319
        $log->{template} = $self->get_log_template({
265
            request => $request,
320
            request => $request,
266
            origin => $log->{info}->{log_origin},
321
            origin => $log->{info}->{log_origin},
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-3 / +7 lines)
Lines 642-649 Link Here
642
                                            [% request.statusalias.lib | html %]
642
                                            [% request.statusalias.lib | html %]
643
                                        [% ELSE %]
643
                                        [% ELSE %]
644
                                            [% request.capabilities.$req_status.name | html%]
644
                                            [% request.capabilities.$req_status.name | html%]
645
                                            [% IF request.requested_partners.length > 0 %]
645
                                            [% IF request.status == 'GENREQ' && request.requested_partners.length > 0 %]
646
                                                ([% request.requested_partners | html %])
646
                                            :
647
                                                [% FOREACH partner IN request.requested_partners(1) %]
648
                                                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% partner.borrowernumber %]">[% partner.email %] ([% partner.cardnumber %])</a>
649
                                                    [% IF loop.index() < loop.size() - 1 %];[% END %]
650
                                                [% END %]
647
                                            [% END %]
651
                                            [% END %]
648
                                        [% END %]
652
                                        [% END %]
649
                                    </li>
653
                                    </li>
Lines 727-733 Link Here
727
                                [% IF request.logs.size > 0 %]
731
                                [% IF request.logs.size > 0 %]
728
                                    [% FOREACH log IN request.logs %]
732
                                    [% FOREACH log IN request.logs %]
729
                                        [% tpl = log.template %]
733
                                        [% tpl = log.template %]
730
                                        [% INCLUDE $tpl log=log %]
734
                                        [% INCLUDE $tpl log=log request=request %]
731
                                    [% END %]
735
                                    [% END %]
732
                                [% ELSE %]
736
                                [% ELSE %]
733
                                    <span>There are no recorded logs for this request</span>
737
                                    <span>There are no recorded logs for this request</span>
(-)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