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

(-)a/Koha/Illrequest.pm (-13 / +84 lines)
Lines 202-212 sub status_alias { Link Here
202
    my $current_status_alias = $self->SUPER::status_alias;
202
    my $current_status_alias = $self->SUPER::status_alias;
203
203
204
    if ($new_status_alias) {
204
    if ($new_status_alias) {
205
        # $new_status_alias may be one of two things, it may be a simple string
206
        # thereby just a drop in replacement for the native status_alias
207
        # method, but it may also be a hashref, as per:
208
        #
209
        # { status => '<new_status>', additional => {<arbitrary_hashref} }
210
        #
211
        # The purpose of 'additional' is to allow additional data to be
212
        # sent for logging when the status change is logged, in addition to
213
        # the new status. I'm not 100% happy with this solution, but since
214
        # we implcitly log when $request->status_alias(123) is called, I'm not
215
        # sure how else we can achieve it without explicitly calling logging
216
        # each time a status is changed, which would be grim
217
        #
205
        # Keep a record of the previous status before we change it,
218
        # Keep a record of the previous status before we change it,
206
        # we might need it
219
        # we might need it
207
        $self->{previous_status} = $current_status_alias ?
220
        $self->{previous_status} = $current_status_alias ?
208
            $current_status_alias :
221
            $current_status_alias :
209
            scalar $self->status;
222
            scalar $self->status;
223
        my $actual_status_alias;
224
        my $additional;
225
        if (ref $new_status_alias eq 'HASH') {
226
            $actual_status_alias = $new_status_alias->{status};
227
            $additional = $new_status_alias->{additional}
228
                if exists $new_status_alias->{additional};
229
        } else {
230
            $actual_status_alias = $new_status_alias;
231
        }
210
        # This is hackery to enable us to undefine
232
        # This is hackery to enable us to undefine
211
        # status_alias, since we need to have an overloaded
233
        # status_alias, since we need to have an overloaded
212
        # status_alias method to get us around the problem described
234
        # status_alias method to get us around the problem described
Lines 214-227 sub status_alias { Link Here
214
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
236
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
215
        # We need a way of accepting implied undef, so we can nullify
237
        # We need a way of accepting implied undef, so we can nullify
216
        # the status_alias column, when called from $self->status
238
        # the status_alias column, when called from $self->status
217
        my $val = $new_status_alias eq "-1" ? undef : $new_status_alias;
239
        my $val = $actual_status_alias eq "-1" ? undef : $actual_status_alias;
218
        my $ret = $self->SUPER::status_alias($val);
240
        my $ret = $self->SUPER::status_alias($val);
219
        my $val_to_log = $val ? $new_status_alias : scalar $self->status;
241
        my $val_to_log = $val ? $actual_status_alias : scalar $self->status;
220
        if ($ret) {
242
        if ($ret) {
221
            my $logger = Koha::Illrequest::Logger->new;
243
            my $logger = Koha::Illrequest::Logger->new;
222
            $logger->log_status_change({
244
            $logger->log_status_change({
223
                request => $self,
245
                request => $self,
224
                value   => $val_to_log
246
                value   => {
247
                    status => $val_to_log,
248
                    additional => $additional
249
                }
225
            });
250
            });
226
        } else {
251
        } else {
227
            delete $self->{previous_status};
252
            delete $self->{previous_status};
Lines 259-275 and sends a notice if appropriate Link Here
259
284
260
sub status {
285
sub status {
261
    my ( $self, $new_status) = @_;
286
    my ( $self, $new_status) = @_;
262
263
    my $current_status = $self->SUPER::status;
287
    my $current_status = $self->SUPER::status;
264
    my $current_status_alias = $self->SUPER::status_alias;
288
    my $current_status_alias = $self->SUPER::status_alias;
265
289
266
    if ($new_status) {
290
    if ($new_status) {
291
        # $new_status may be one of two things, it may be a simple string
292
        # thereby just a drop in replacement for the native status method,
293
        # but it may also be a hashref, as per:
294
        #
295
        # { status => '<new_status>', additional => {<arbitrary_hashref} }
296
        #
297
        # The purpose of 'additional' is to allow additional data to be
298
        # sent for logging when the status change is logged, in addition to
299
        # the new status. I'm not 100% happy with this solution, but since
300
        # we implcitly log when $request->status('XYZ') is called, I'm not
301
        # sure how else we can achieve it without explicitly calling logging
302
        # each time a status is changed, which would be grim
303
        #
267
        # Keep a record of the previous status before we change it,
304
        # Keep a record of the previous status before we change it,
268
        # we might need it
305
        # we might need it
269
        $self->{previous_status} = $current_status_alias ?
306
        $self->{previous_status} = $current_status_alias ?
270
            $current_status_alias :
307
            $current_status_alias :
271
            $current_status;
308
            $current_status;
272
        my $ret = $self->SUPER::status($new_status)->store;
309
        my $actual_status;
310
        my $additional;
311
        if (ref $new_status eq 'HASH') {
312
            $actual_status = $new_status->{status};
313
            $additional = $new_status->{additional}
314
                if exists $new_status->{additional};
315
        } else {
316
            $actual_status = $new_status;
317
        }
318
        my $ret = $self->SUPER::status($actual_status)->store;
273
        if ($current_status_alias) {
319
        if ($current_status_alias) {
274
            # This is hackery to enable us to undefine
320
            # This is hackery to enable us to undefine
275
            # status_alias, since we need to have an overloaded
321
            # status_alias, since we need to have an overloaded
Lines 278-289 sub status { Link Here
278
            # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
324
            # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
279
            # We need a way of passing implied undef to nullify status_alias
325
            # We need a way of passing implied undef to nullify status_alias
280
            # so we pass -1, which is special cased in the overloaded setter
326
            # so we pass -1, which is special cased in the overloaded setter
281
            $self->status_alias("-1");
327
            $self->status_alias({
328
                status     => "-1",
329
                additional => $additional
330
            });
282
        } else {
331
        } else {
283
            my $logger = Koha::Illrequest::Logger->new;
332
            my $logger = Koha::Illrequest::Logger->new;
284
            $logger->log_status_change({
333
            $logger->log_status_change({
285
                request => $self,
334
                request => $self,
286
                value   => $new_status
335
                value   => {
336
                    status     => $actual_status,
337
                    additional => $additional
338
                }
287
            });
339
            });
288
        }
340
        }
289
        delete $self->{previous_status};
341
        delete $self->{previous_status};
Lines 445-456 sub _core_status_graph { Link Here
445
            ui_method_icon => 'fa-check',
497
            ui_method_icon => 'fa-check',
446
        },
498
        },
447
        GENREQ => {
499
        GENREQ => {
448
            prev_actions   => [ 'NEW', 'REQREV' ],
500
            prev_actions   => [ 'NEW', 'REQREV', 'GENREQ' ],
449
            id             => 'GENREQ',
501
            id             => 'GENREQ',
450
            name           => 'Requested from partners',
502
            name           => 'Requested from partners',
451
            ui_method_name => 'Place request with partners',
503
            ui_method_name => 'Place request with partners',
452
            method         => 'generic_confirm',
504
            method         => 'generic_confirm',
453
            next_actions   => [ 'COMP', 'CHK' ],
505
            next_actions   => [ 'COMP', 'CHK', 'GENREQ' ],
454
            ui_method_icon => 'fa-send-o',
506
            ui_method_icon => 'fa-send-o',
455
        },
507
        },
456
        REQREV => {
508
        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 1654-1669 sub store { Link Here
1654
    my $partners_string = $illRequest->requested_partners;
1715
    my $partners_string = $illRequest->requested_partners;
1655
1716
1656
Return the string representing the email addresses of the partners to
1717
Return the string representing the email addresses of the partners to
1657
whom a request has been sent
1718
whom a request has been sent or, alternatively, the full (unblessed)
1719
patron objects in an arrayref
1658
1720
1659
=cut
1721
=cut
1660
1722
1661
sub requested_partners {
1723
sub requested_partners {
1662
    my ( $self ) = @_;
1724
    my ( $self, $full ) = @_;
1663
    return $self->_backend_capability(
1725
    my $email = $self->_backend_capability(
1664
        'get_requested_partners',
1726
        'get_requested_partners',
1665
        { request => $self }
1727
        { request => $self }
1666
    );
1728
    );
1729
    return $email if (!$full);
1730
1731
    # The string may contain multiple addressed delimited by '; '
1732
    my @email_split = split(/; /, $email);
1733
    # Get the appropriate patron objects
1734
    return Koha::Patrons->search({
1735
        email => { -in => \@email_split },
1736
        categorycode => $self->_config->partner_code
1737
    })->unblessed;
1667
}
1738
}
1668
1739
1669
=head3 TO_JSON
1740
=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 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
                                    <span>There are no recorded logs for this request</span>
732
                                    <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