Bug 15774: Add POD and license notices
[koha.git] / Koha / Object / Mixin / AdditionalFields.pm
blobe297058adf9e3d8fbca90d1496657302d528fb27
1 package Koha::Object::Mixin::AdditionalFields;
3 use Modern::Perl;
5 =head1 NAME
7 Koha::Object::Mixin::AdditionalFields
9 =head1 SYNOPSIS
11 package Koha::Foo;
13 use parent qw( Koha::Object Koha::Object::Mixin::AdditionalFields );
15 sub _type { 'Foo' }
18 package main;
20 use Koha::Foo;
22 Koha::Foos->find($id)->set_additional_fields(...);
24 =head1 API
26 =head2 Public methods
28 =head3 set_additional_fields
30 $foo->set_additional_fields([
32 id => 1,
33 value => 'foo',
36 id => 2,
37 value => 'bar',
39 ]);
41 =cut
43 sub set_additional_fields {
44 my ($self, $additional_fields) = @_;
46 my $rs = Koha::Database->new->schema->resultset('AdditionalFieldValue');
48 foreach my $additional_field (@$additional_fields) {
49 my $field_value = $rs->find_or_new({
50 field_id => $additional_field->{id},
51 record_id => $self->id,
52 });
53 my $value = $additional_field->{value};
54 if (defined $value) {
55 $field_value->set_columns({ value => $value })->update_or_insert;
56 } elsif ($field_value->in_storage) {
57 $field_value->delete;
62 =head3 additional_field_values
64 Returns additional field values
66 my @values = $foo->additional_field_values;
68 =cut
70 sub additional_field_values {
71 my ($self) = @_;
73 return $self->_result->additional_field_values;
76 =head1 AUTHOR
78 Koha Development Team <http://koha-community.org/>
80 =head1 COPYRIGHT AND LICENSE
82 Copyright 2018 BibLibre
84 This file is part of Koha.
86 Koha is free software; you can redistribute it and/or modify it under the
87 terms of the GNU General Public License as published by the Free Software
88 Foundation; either version 3 of the License, or (at your option) any later
89 version.
91 Koha is distributed in the hope that it will be useful, but WITHOUT ANY
92 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
93 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
95 You should have received a copy of the GNU General Public License along
96 with Koha; if not, see <http://www.gnu.org/licenses>.
98 =cut