|
Lines 47-69
sub new_from_statistic {
Link Here
|
| 47 |
|
47 |
|
| 48 |
my @t_fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || ''; |
48 |
my @t_fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || ''; |
| 49 |
|
49 |
|
|
|
50 |
my $statistic_item = $statistic->item; |
| 51 |
|
| 52 |
# These fields are treated separately as the column names do not match |
| 50 |
if ( grep { $_ eq 'transaction_branchcode' } @t_fields_to_copy ) { |
53 |
if ( grep { $_ eq 'transaction_branchcode' } @t_fields_to_copy ) { |
| 51 |
$values->{transaction_branchcode} = $statistic->branch; |
54 |
$values->{transaction_branchcode} = $statistic->branch; |
| 52 |
} |
55 |
} |
| 53 |
if ( grep { $_ eq 'holdingbranch' } @t_fields_to_copy ) { |
|
|
| 54 |
$values->{holdingbranch} = $statistic->item->holdingbranch; |
| 55 |
} |
| 56 |
if ( grep { $_ eq 'homebranch' } @t_fields_to_copy ) { |
| 57 |
$values->{homebranch} = $statistic->item->homebranch; |
| 58 |
} |
| 59 |
if ( grep { $_ eq 'transaction_type' } @t_fields_to_copy ) { |
56 |
if ( grep { $_ eq 'transaction_type' } @t_fields_to_copy ) { |
| 60 |
$values->{transaction_type} = $statistic->type; |
57 |
$values->{transaction_type} = $statistic->type; |
| 61 |
} |
58 |
} |
| 62 |
if ( grep { $_ eq 'itemcallnumber' } @t_fields_to_copy ) { |
|
|
| 63 |
$values->{itemcallnumber} = $statistic->item->itemcallnumber; |
| 64 |
} |
| 65 |
|
59 |
|
|
|
60 |
# These fields are not captured in the statistic so must be pulled from the item |
| 61 |
if ($statistic_item) { |
| 62 |
if ( grep { $_ eq 'homebranch' } @t_fields_to_copy ) { |
| 63 |
$values->{homebranch} = $statistic_item->homebranch; |
| 64 |
} |
| 65 |
if ( grep { $_ eq 'holdingbranch' } @t_fields_to_copy ) { |
| 66 |
$values->{holdingbranch} = $statistic->item->holdingbranch; |
| 67 |
} |
| 68 |
if ( grep { $_ eq 'itemcallnumber' } @t_fields_to_copy ) { |
| 69 |
$values->{itemcallnumber} = $statistic_item->itemcallnumber; |
| 70 |
} |
| 71 |
} |
| 66 |
|
72 |
|
|
|
73 |
# Remove fields we have already handled from the list |
| 67 |
@t_fields_to_copy = grep { |
74 |
@t_fields_to_copy = grep { |
| 68 |
$_ ne 'transaction_branchcode' |
75 |
$_ ne 'transaction_branchcode' |
| 69 |
&& $_ ne 'holdingbranch' |
76 |
&& $_ ne 'holdingbranch' |
|
Lines 72-99
sub new_from_statistic {
Link Here
|
| 72 |
&& $_ ne 'itemcallnumber' |
79 |
&& $_ ne 'itemcallnumber' |
| 73 |
} @t_fields_to_copy; |
80 |
} @t_fields_to_copy; |
| 74 |
|
81 |
|
|
|
82 |
# Populate the remaining columns |
| 75 |
$values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy }; |
83 |
$values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy }; |
| 76 |
|
84 |
|
| 77 |
my $patron = Koha::Patrons->find($statistic->borrowernumber); |
85 |
my $patron = Koha::Patrons->find($statistic->borrowernumber); |
| 78 |
my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || ''; |
86 |
if( $patron ){ |
| 79 |
$values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy }; |
87 |
my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || ''; |
|
|
88 |
$values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy }; |
| 80 |
|
89 |
|
| 81 |
$values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?) |
90 |
$values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?) |
| 82 |
$values->{categorycode} = $patron->categorycode; |
91 |
$values->{categorycode} = $patron->categorycode; |
| 83 |
|
92 |
|
| 84 |
$values->{has_cardnumber} = $patron->cardnumber ? 1 : 0; |
93 |
$values->{has_cardnumber} = $patron->cardnumber ? 1 : 0; |
|
|
94 |
} |
| 85 |
|
95 |
|
| 86 |
my $self = $class->SUPER::new($values); |
96 |
my $self = $class->SUPER::new($values); |
| 87 |
|
97 |
|
| 88 |
my $extended_attributes = $patron->extended_attributes->unblessed; |
98 |
if( $patron ){ |
| 89 |
for my $attribute (@$extended_attributes) { |
99 |
my $extended_attributes = $patron->extended_attributes->unblessed; |
| 90 |
next unless Koha::Patron::Attribute::Types->find( |
100 |
for my $attribute (@$extended_attributes) { |
| 91 |
$attribute->{code} )->keep_for_pseudonymization; |
101 |
next unless Koha::Patron::Attribute::Types->find( |
|
|
102 |
$attribute->{code} )->keep_for_pseudonymization; |
| 92 |
|
103 |
|
| 93 |
delete $attribute->{id}; |
104 |
delete $attribute->{id}; |
| 94 |
delete $attribute->{borrowernumber}; |
105 |
delete $attribute->{borrowernumber}; |
| 95 |
|
106 |
|
| 96 |
$self->_result->create_related('pseudonymized_borrower_attributes', $attribute); |
107 |
$self->_result->create_related('pseudonymized_borrower_attributes', $attribute); |
|
|
108 |
} |
| 97 |
} |
109 |
} |
| 98 |
|
110 |
|
| 99 |
return $self; |
111 |
return $self; |