Lines 43-93
Koha::Object::Mixin::AdditionalFields
Link Here
|
43 |
=cut |
43 |
=cut |
44 |
|
44 |
|
45 |
sub set_additional_fields { |
45 |
sub set_additional_fields { |
46 |
my ($self, $additional_fields) = @_; |
46 |
my ( $self, $additional_fields ) = @_; |
47 |
|
47 |
|
48 |
$self->additional_field_values->delete; |
48 |
$self->additional_field_values->delete; |
49 |
|
49 |
|
|
|
50 |
my $table = $self->_result->table; |
51 |
|
50 |
my $biblionumber; |
52 |
my $biblionumber; |
51 |
my $record; |
53 |
my $record; |
52 |
my $record_updated; |
54 |
my $record_updated; |
53 |
if ($self->_result->has_column('biblionumber')) { |
55 |
if ( $self->_result->has_column('biblionumber') ) { |
54 |
$biblionumber = $self->biblionumber; |
56 |
$biblionumber = $self->biblionumber; |
55 |
} |
57 |
} |
56 |
|
58 |
|
57 |
foreach my $additional_field (@$additional_fields) { |
59 |
foreach my $additional_field (@$additional_fields) { |
58 |
my $field = Koha::AdditionalFields->find($additional_field->{id}); |
60 |
my $field = Koha::AdditionalFields->find( $additional_field->{id} ); |
59 |
my $value = $additional_field->{value}; |
61 |
my $value = $additional_field->{value}; |
60 |
|
62 |
|
61 |
if ($biblionumber and $field->marcfield) { |
63 |
if ( $biblionumber and $field->marcfield ) { |
62 |
require Koha::Biblios; |
64 |
require Koha::Biblios; |
63 |
$record //= Koha::Biblios->find($biblionumber)->metadata->record; |
65 |
$record //= Koha::Biblios->find($biblionumber)->metadata->record; |
64 |
|
66 |
|
65 |
my ($tag, $subfield) = split /\$/, $field->marcfield; |
67 |
my ( $tag, $subfield ) = split /\$/, $field->marcfield; |
66 |
my $marc_field = $record->field($tag); |
68 |
my $marc_field = $record->field($tag); |
67 |
if ($field->marcfield_mode eq 'get') { |
69 |
if ( $field->marcfield_mode eq 'get' ) { |
68 |
$value = $marc_field ? $marc_field->subfield($subfield) : ''; |
70 |
$value = $marc_field ? $marc_field->subfield($subfield) : ''; |
69 |
} elsif ($field->marcfield_mode eq 'set') { |
71 |
} elsif ( $field->marcfield_mode eq 'set' ) { |
70 |
if ($marc_field) { |
72 |
if ($marc_field) { |
71 |
$marc_field->update($subfield => $value); |
73 |
$marc_field->update( $subfield => $value ); |
72 |
} else { |
74 |
} else { |
73 |
$marc_field = MARC::Field->new($tag, '', '', $subfield => $value); |
75 |
$marc_field = MARC::Field->new( $tag, '', '', $subfield => $value ); |
74 |
$record->append_fields($marc_field); |
76 |
$record->append_fields($marc_field); |
75 |
} |
77 |
} |
76 |
$record_updated = 1; |
78 |
$record_updated = 1; |
77 |
} |
79 |
} |
78 |
} |
80 |
} |
79 |
|
81 |
|
80 |
if (defined $value) { |
82 |
if ( defined $value ) { |
81 |
my $field_value = Koha::AdditionalFieldValue->new({ |
83 |
my $field_value = Koha::AdditionalFieldValue->new( |
82 |
field_id => $additional_field->{id}, |
84 |
{ |
83 |
record_id => $self->id, |
85 |
field_id => $additional_field->{id}, |
84 |
value => $value, |
86 |
record_table => $table, |
85 |
})->store; |
87 |
record_id => $self->id, |
|
|
88 |
value => $value, |
89 |
} |
90 |
)->store; |
86 |
} |
91 |
} |
87 |
} |
92 |
} |
88 |
|
93 |
|
89 |
if ($record_updated) { |
94 |
if ($record_updated) { |
90 |
C4::Biblio::ModBiblio($record, $biblionumber); |
95 |
C4::Biblio::ModBiblio( $record, $biblionumber ); |
91 |
} |
96 |
} |
92 |
} |
97 |
} |
93 |
|
98 |
|
Lines 222-228
sub additional_field_values {
Link Here
|
222 |
my ($self) = @_; |
227 |
my ($self) = @_; |
223 |
|
228 |
|
224 |
my $afv_rs = $self->_result->additional_field_values; |
229 |
my $afv_rs = $self->_result->additional_field_values; |
225 |
return Koha::AdditionalFieldValues->_new_from_dbic( $afv_rs ); |
230 |
return Koha::AdditionalFieldValues->_new_from_dbic($afv_rs); |
226 |
} |
231 |
} |
227 |
|
232 |
|
228 |
=head1 AUTHOR |
233 |
=head1 AUTHOR |
229 |
- |
|
|