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

(-)a/Koha/Illrequest.pm (-13 / +84 lines)
Lines 196-206 sub status_alias { Link Here
196
    my $current_status_alias = $self->SUPER::status_alias;
196
    my $current_status_alias = $self->SUPER::status_alias;
197
197
198
    if ($new_status_alias) {
198
    if ($new_status_alias) {
199
        # $new_status_alias may be one of two things, it may be a simple string
200
        # thereby just a drop in replacement for the native status_alias
201
        # method, but it may also be a hashref, as per:
202
        #
203
        # { status => '<new_status>', additional => {<arbitrary_hashref} }
204
        #
205
        # The purpose of 'additional' is to allow additional data to be
206
        # sent for logging when the status change is logged, in addition to
207
        # the new status. I'm not 100% happy with this solution, but since
208
        # we implcitly log when $request->status_alias(123) is called, I'm not
209
        # sure how else we can achieve it without explicitly calling logging
210
        # each time a status is changed, which would be grim
211
        #
199
        # Keep a record of the previous status before we change it,
212
        # Keep a record of the previous status before we change it,
200
        # we might need it
213
        # we might need it
201
        $self->{previous_status} = $current_status_alias ?
214
        $self->{previous_status} = $current_status_alias ?
202
            $current_status_alias :
215
            $current_status_alias :
203
            scalar $self->status;
216
            scalar $self->status;
217
        my $actual_status_alias;
218
        my $additional;
219
        if (ref $new_status_alias eq 'HASH') {
220
            $actual_status_alias = $new_status_alias->{status};
221
            $additional = $new_status_alias->{additional}
222
                if exists $new_status_alias->{additional};
223
        } else {
224
            $actual_status_alias = $new_status_alias;
225
        }
204
        # This is hackery to enable us to undefine
226
        # This is hackery to enable us to undefine
205
        # status_alias, since we need to have an overloaded
227
        # status_alias, since we need to have an overloaded
206
        # status_alias method to get us around the problem described
228
        # status_alias method to get us around the problem described
Lines 208-221 sub status_alias { Link Here
208
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
230
        # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
209
        # We need a way of accepting implied undef, so we can nullify
231
        # We need a way of accepting implied undef, so we can nullify
210
        # the status_alias column, when called from $self->status
232
        # the status_alias column, when called from $self->status
211
        my $val = $new_status_alias eq "-1" ? undef : $new_status_alias;
233
        my $val = $actual_status_alias eq "-1" ? undef : $actual_status_alias;
212
        my $ret = $self->SUPER::status_alias($val);
234
        my $ret = $self->SUPER::status_alias($val);
213
        my $val_to_log = $val ? $new_status_alias : scalar $self->status;
235
        my $val_to_log = $val ? $actual_status_alias : scalar $self->status;
214
        if ($ret) {
236
        if ($ret) {
215
            my $logger = Koha::Illrequest::Logger->new;
237
            my $logger = Koha::Illrequest::Logger->new;
216
            $logger->log_status_change({
238
            $logger->log_status_change({
217
                request => $self,
239
                request => $self,
218
                value   => $val_to_log
240
                value   => {
241
                    status => $val_to_log,
242
                    additional => $additional
243
                }
219
            });
244
            });
220
        } else {
245
        } else {
221
            delete $self->{previous_status};
246
            delete $self->{previous_status};
Lines 248-264 also nullifies status_alias and records the fact that the status has changed Link Here
248
273
249
sub status {
274
sub status {
250
    my ( $self, $new_status) = @_;
275
    my ( $self, $new_status) = @_;
251
252
    my $current_status = $self->SUPER::status;
276
    my $current_status = $self->SUPER::status;
253
    my $current_status_alias = $self->SUPER::status_alias;
277
    my $current_status_alias = $self->SUPER::status_alias;
254
278
255
    if ($new_status) {
279
    if ($new_status) {
280
        # $new_status may be one of two things, it may be a simple string
281
        # thereby just a drop in replacement for the native status method,
282
        # but it may also be a hashref, as per:
283
        #
284
        # { status => '<new_status>', additional => {<arbitrary_hashref} }
285
        #
286
        # The purpose of 'additional' is to allow additional data to be
287
        # sent for logging when the status change is logged, in addition to
288
        # the new status. I'm not 100% happy with this solution, but since
289
        # we implcitly log when $request->status('XYZ') is called, I'm not
290
        # sure how else we can achieve it without explicitly calling logging
291
        # each time a status is changed, which would be grim
292
        #
256
        # Keep a record of the previous status before we change it,
293
        # Keep a record of the previous status before we change it,
257
        # we might need it
294
        # we might need it
258
        $self->{previous_status} = $current_status_alias ?
295
        $self->{previous_status} = $current_status_alias ?
259
            $current_status_alias :
296
            $current_status_alias :
260
            $current_status;
297
            $current_status;
261
        my $ret = $self->SUPER::status($new_status)->store;
298
        my $actual_status;
299
        my $additional;
300
        if (ref $new_status eq 'HASH') {
301
            $actual_status = $new_status->{status};
302
            $additional = $new_status->{additional}
303
                if exists $new_status->{additional};
304
        } else {
305
            $actual_status = $new_status;
306
        }
307
        my $ret = $self->SUPER::status($actual_status)->store;
262
        if ($current_status_alias) {
308
        if ($current_status_alias) {
263
            # This is hackery to enable us to undefine
309
            # This is hackery to enable us to undefine
264
            # status_alias, since we need to have an overloaded
310
            # status_alias, since we need to have an overloaded
Lines 267-278 sub status { Link Here
267
            # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
313
            # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20581#c156
268
            # We need a way of passing implied undef to nullify status_alias
314
            # We need a way of passing implied undef to nullify status_alias
269
            # so we pass -1, which is special cased in the overloaded setter
315
            # so we pass -1, which is special cased in the overloaded setter
270
            $self->status_alias("-1");
316
            $self->status_alias({
317
                status     => "-1",
318
                additional => $additional
319
            });
271
        } else {
320
        } else {
272
            my $logger = Koha::Illrequest::Logger->new;
321
            my $logger = Koha::Illrequest::Logger->new;
273
            $logger->log_status_change({
322
            $logger->log_status_change({
274
                request => $self,
323
                request => $self,
275
                value   => $new_status
324
                value   => {
325
                    status     => $actual_status,
326
                    additional => $additional
327
                }
276
            });
328
            });
277
        }
329
        }
278
        delete $self->{previous_status};
330
        delete $self->{previous_status};
Lines 430-441 sub _core_status_graph { Link Here
430
            ui_method_icon => 'fa-check',
482
            ui_method_icon => 'fa-check',
431
        },
483
        },
432
        GENREQ => {
484
        GENREQ => {
433
            prev_actions   => [ 'NEW', 'REQREV' ],
485
            prev_actions   => [ 'NEW', 'REQREV', 'GENREQ' ],
434
            id             => 'GENREQ',
486
            id             => 'GENREQ',
435
            name           => 'Requested from partners',
487
            name           => 'Requested from partners',
436
            ui_method_name => 'Place request with partners',
488
            ui_method_name => 'Place request with partners',
437
            method         => 'generic_confirm',
489
            method         => 'generic_confirm',
438
            next_actions   => [ 'COMP' ],
490
            next_actions   => [ 'COMP', 'GENREQ' ],
439
            ui_method_icon => 'fa-send-o',
491
            ui_method_icon => 'fa-send-o',
440
        },
492
        },
441
        REQREV => {
493
        REQREV => {
Lines 1118-1124 EOF Link Here
1118
        # Send it
1170
        # Send it
1119
        my $result = sendmail(%mail);
1171
        my $result = sendmail(%mail);
1120
        if ( $result ) {
1172
        if ( $result ) {
1121
            $self->status("GENREQ")->store;
1173
            # This request may previously have been sent to partners
1174
            # so we want to check who
1175
            my $previous_partners = $self->requested_partners;
1176
            $self->status({
1177
                status => "GENREQ",
1178
                additional => {
1179
                    partner_email_now => $to,
1180
                    partner_email_previous => $previous_partners
1181
                }
1182
            })->store;
1122
            $self->_backend_capability(
1183
            $self->_backend_capability(
1123
                'set_requested_partners',
1184
                'set_requested_partners',
1124
                {
1185
                {
Lines 1217-1232 sub store { Link Here
1217
    my $partners_string = $illRequest->requested_partners;
1278
    my $partners_string = $illRequest->requested_partners;
1218
1279
1219
Return the string representing the email addresses of the partners to
1280
Return the string representing the email addresses of the partners to
1220
whom a request has been sent
1281
whom a request has been sent or, alternatively, the full (unblessed)
1282
patron objects in an arrayref
1221
1283
1222
=cut
1284
=cut
1223
1285
1224
sub requested_partners {
1286
sub requested_partners {
1225
    my ( $self ) = @_;
1287
    my ( $self, $full ) = @_;
1226
    return $self->_backend_capability(
1288
    my $email = $self->_backend_capability(
1227
        'get_requested_partners',
1289
        'get_requested_partners',
1228
        { request => $self }
1290
        { request => $self }
1229
    );
1291
    );
1292
    return $email if (!$full);
1293
1294
    # The string may contain multiple addressed delimited by '; '
1295
    my @email_split = split(/; /, $email);
1296
    # Get the appropriate patron objects
1297
    return Koha::Patrons->search({
1298
        email => { -in => \@email_split },
1299
        categorycode => $self->_config->partner_code
1300
    })->unblessed;
1230
}
1301
}
1231
1302
1232
=head3 TO_JSON
1303
=head3 TO_JSON
(-)a/Koha/Illrequest/Logger.pm (-5 / +55 lines)
Lines 26-31 use C4::Context; Link Here
26
use C4::Templates;
26
use C4::Templates;
27
use C4::Log qw( logaction );
27
use C4::Log qw( logaction );
28
use Koha::ActionLogs;
28
use Koha::ActionLogs;
29
use Koha::Patron;
29
30
30
=head1 NAME
31
=head1 NAME
31
32
Lines 115-133 sub log_status_change { Link Here
115
    my ( $self, $params ) = @_;
116
    my ( $self, $params ) = @_;
116
117
117
    if (defined $params->{request} && defined $params->{value}) {
118
    if (defined $params->{request} && defined $params->{value}) {
119
120
		my $infos = {
121
			log_origin    => 'core',
122
			status_before => $params->{request}->{previous_status},
123
			status_after  => $params->{value}->{status}
124
		};
125
126
		if (
127
			defined $params->{value}->{additional} &&
128
			$params->{value}->{additional}
129
		) {
130
			$infos->{additional} = $params->{value}->{additional};
131
		}
132
118
        $self->log_something({
133
        $self->log_something({
119
            modulename   => 'ILL',
134
            modulename   => 'ILL',
120
            actionname   => 'STATUS_CHANGE',
135
            actionname   => 'STATUS_CHANGE',
121
            objectnumber => $params->{request}->id,
136
            objectnumber => $params->{request}->id,
122
            infos        => to_json({
137
            infos        => to_json($infos)
123
                log_origin    => 'core',
124
                status_before => $params->{request}->{previous_status},
125
                status_after  => $params->{value}
126
            })
127
        });
138
        });
128
    }
139
    }
129
}
140
}
130
141
142
=head3 logged_requested_partners
143
144
    Koha::Illrequest::Logger->logged_requested_partners($log);
145
146
Receive an request's log and return a hashref of all
147
patron objects associated with it, keyed on email
148
address. This enables us to display full information about them
149
and link to their patron page
150
151
=cut
152
153
sub _logged_requested_partners {
154
    my ( $params ) = @_;
155
	my @to = ();
156
	my @potential = ('partner_email_previous', 'partner_email_now');
157
	foreach my $partner(@potential) {
158
		my @addresses = split(/; /, $params->{info}->{additional}->{$partner});
159
		push @to, @addresses if scalar @addresses > 0;
160
	}
161
	my $to_return = {};
162
	if (scalar @to > 0) {
163
		my $patrons = Koha::Patrons->search({
164
			email => { -in => \@to },
165
			categorycode => $params->{request}->_config->partner_code
166
		})->unblessed;
167
		foreach my $patron(@{$patrons}) {
168
			$to_return->{$patron->{email}} = $patron;
169
		}
170
		return $to_return;
171
	} else {
172
		return {};
173
	}
174
}
175
131
=head3 log_something
176
=head3 log_something
132
177
133
    Koha::IllRequest::Logger->log_something({
178
    Koha::IllRequest::Logger->log_something({
Lines 218-223 sub get_request_logs { Link Here
218
    foreach my $log(@{$logs}) {
263
    foreach my $log(@{$logs}) {
219
        $log->{aliases} = $alias_hash;
264
        $log->{aliases} = $alias_hash;
220
        $log->{info} = from_json($log->{info});
265
        $log->{info} = from_json($log->{info});
266
		my $full_partners = _logged_requested_partners({
267
			info => $log->{info},
268
			request => $request
269
		});
270
		$log->{requested_partners} = $full_partners if keys %{$full_partners};
221
        $log->{template} = $self->get_log_template({
271
        $log->{template} = $self->get_log_template({
222
            request => $request,
272
            request => $request,
223
            origin => $log->{info}->{log_origin},
273
            origin => $log->{info}->{log_origin},
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-3 / +7 lines)
Lines 363-370 Link Here
363
                                            [% request.statusalias.lib | html %]
363
                                            [% request.statusalias.lib | html %]
364
                                        [% ELSE %]
364
                                        [% ELSE %]
365
                                            [% request.capabilities.$req_status.name | html%]
365
                                            [% request.capabilities.$req_status.name | html%]
366
                                            [% IF request.requested_partners.length > 0 %]
366
                                            [% IF request.status == 'GENREQ' && request.requested_partners.length > 0 %]
367
                                                ([% request.requested_partners | html %])
367
                                            :
368
                                                [% FOREACH partner IN request.requested_partners(1) %]
369
                                                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% partner.borrowernumber %]">[% partner.email %] ([% partner.cardnumber %])</a>
370
                                                    [% IF loop.index() < loop.size() - 1 %];[% END %]
371
                                                [% END %]
368
                                            [% END %]
372
                                            [% END %]
369
                                        [% END %]
373
                                        [% END %]
370
                                    </li>
374
                                    </li>
Lines 448-454 Link Here
448
                                [% IF request.logs.size > 0 %]
452
                                [% IF request.logs.size > 0 %]
449
                                    [% FOREACH log IN request.logs %]
453
                                    [% FOREACH log IN request.logs %]
450
                                        [% tpl = log.template %]
454
                                        [% tpl = log.template %]
451
                                        [% INCLUDE $tpl log=log %]
455
                                        [% INCLUDE $tpl log=log request=request %]
452
                                    [% END %]
456
                                    [% END %]
453
                                [% ELSE %]
457
                                [% ELSE %]
454
                                    There are no recorded logs for this request
458
                                    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