Bug 16749: Update debian docs for koha-translate
[koha.git] / Koha / AuthorisedValue.pm
blob898b630279a9f2c4bb56931f6953039c1c6d80dd
1 package Koha::AuthorisedValue;
3 # Copyright ByWater Solutions 2014
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
22 use Carp;
24 use Koha::Database;
26 use base qw(Koha::Object);
28 =head1 NAME
30 Koha::AuthorisedValue - Koha Authorised value Object class
32 =head1 API
34 =head2 Class Methods
36 =cut
38 =head3 branch_limitations
40 my $limitations = $av->branch_limitations();
42 $av->branch_limitations( \@branchcodes );
44 =cut
46 sub branch_limitations {
47 my ( $self, $branchcodes ) = @_;
49 if ($branchcodes) {
50 return $self->replace_branch_limitations($branchcodes);
52 else {
53 return $self->get_branch_limitations();
58 =head3 get_branch_limitations
60 my $limitations = $av->get_branch_limitations();
62 =cut
64 sub get_branch_limitations {
65 my ($self) = @_;
67 my @branchcodes =
68 $self->_avb_resultset->search( { av_id => $self->id() } )
69 ->get_column('branchcode')->all();
71 return \@branchcodes;
74 =head3 add_branch_limitation
76 $av->add_branch_limitation( $branchcode );
78 =cut
80 sub add_branch_limitation {
81 my ( $self, $branchcode ) = @_;
83 croak("No branchcode passed in!") unless $branchcode;
85 my $limitation = $self->_avb_resultset->update_or_create(
86 { av_id => $self->id(), branchcode => $branchcode } );
88 return $limitation ? 1 : undef;
91 =head3 del_branch_limitation
93 $av->del_branch_limitation( $branchcode );
95 =cut
97 sub del_branch_limitation {
98 my ( $self, $branchcode ) = @_;
100 croak("No branchcode passed in!") unless $branchcode;
102 my $limitation =
103 $self->_avb_resultset->find(
104 { av_id => $self->id(), branchcode => $branchcode } );
106 unless ($limitation) {
107 my $id = $self->id();
108 carp(
109 "No branch limit for branch $branchcode found for av_id $id to delete!"
111 return;
114 return $limitation->delete();
117 =head3 replace_branch_limitations
119 $av->replace_branch_limitations( \@branchcodes );
121 =cut
123 sub replace_branch_limitations {
124 my ( $self, $branchcodes ) = @_;
126 $self->_avb_resultset->search( { av_id => $self->id() } )->delete();
128 my @return_values =
129 map { $self->add_branch_limitation($_) } @$branchcodes;
131 return \@return_values;
134 =head3 opac_description
136 my $description = $av->opac_description();
138 =cut
140 sub opac_description {
141 my ( $self, $value ) = @_;
143 return $self->lib_opac() || $self->lib();
146 =head3 _avb_resultset
148 Returns the internal resultset or creates it if undefined
150 =cut
152 sub _avb_resultset {
153 my ($self) = @_;
155 $self->{_avb_resultset} ||=
156 Koha::Database->new()->schema()->resultset('AuthorisedValuesBranch');
158 $self->{_avb_resultset};
161 =head3 type
163 =cut
165 sub _type {
166 return 'AuthorisedValue';
169 =head1 AUTHOR
171 Kyle M Hall <kyle@bywatersolutions.com>
173 =cut