Line 0
Link Here
|
|
|
1 |
package Koha::Anonymized::Transaction; |
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 3 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Carp; |
21 |
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); |
22 |
|
23 |
use Koha::Database; |
24 |
|
25 |
use base qw(Koha::Object); |
26 |
|
27 |
=head1 NAME |
28 |
|
29 |
Koha::Anonymized::Transaction - Koha Anonymized::Transaction Object class |
30 |
|
31 |
=head1 API |
32 |
|
33 |
=head2 Class methods |
34 |
|
35 |
=head3 new |
36 |
|
37 |
=cut |
38 |
|
39 |
sub get_hash { |
40 |
my ( $class, $borrowernumber) = @_; |
41 |
return bcrypt($borrowernumber, C4::Context->config('key')); |
42 |
} |
43 |
|
44 |
|
45 |
sub new_from_statistic { |
46 |
my ( $class, $statistic ) = @_; |
47 |
|
48 |
my $values = { |
49 |
hashed_borrowernumber => $class->get_hash($statistic->borrowernumber), |
50 |
}; |
51 |
|
52 |
my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || ''; |
53 |
|
54 |
if ( grep { $_ eq 'branchcode' } @fields_to_copy ) { |
55 |
$values->{branchcode} = $statistic->branch; |
56 |
} |
57 |
if ( grep { $_ eq 'holdingbranch' } @fields_to_copy ) { |
58 |
$values->{holdingbranch} = $statistic->item->holdingbranch; |
59 |
} |
60 |
if ( grep { $_ eq 'transaction_type' } @fields_to_copy ) { |
61 |
$values->{transaction_type} = $statistic->type; |
62 |
} |
63 |
if ( grep { $_ eq 'itemcallnumber' } @fields_to_copy ) { |
64 |
$values->{itemcallnumber} = $statistic->item->itemcallnumber; |
65 |
} |
66 |
|
67 |
|
68 |
@fields_to_copy = grep { |
69 |
$_ ne 'branchcode' |
70 |
&& $_ ne 'holdingbranch' |
71 |
&& $_ ne 'transaction_type' |
72 |
&& $_ ne 'itemcallnumber' |
73 |
} @fields_to_copy; |
74 |
|
75 |
$values = { |
76 |
%$values, |
77 |
map { $_ => $statistic->$_ } @fields_to_copy}; |
78 |
|
79 |
return $class->SUPER::new($values); |
80 |
} |
81 |
|
82 |
=head2 Internal methods |
83 |
|
84 |
=head3 _type |
85 |
|
86 |
=cut |
87 |
|
88 |
sub _type { |
89 |
return 'AnonymizedTransaction'; |
90 |
} |
91 |
|
92 |
1; |