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
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.
26 use base
qw(Koha::Object);
30 Koha::AuthorisedValue - Koha Authorised value Object class
38 =head3 branch_limitations
40 my $limitations = $av->branch_limitations();
42 $av->branch_limitations( \@branchcodes );
46 sub branch_limitations
{
47 my ( $self, $branchcodes ) = @_;
50 return $self->replace_branch_limitations($branchcodes);
53 return $self->get_branch_limitations();
58 =head3 get_branch_limitations
60 my $limitations = $av->get_branch_limitations();
64 sub get_branch_limitations
{
68 $self->_avb_resultset->search( { av_id
=> $self->id() } )
69 ->get_column('branchcode')->all();
74 =head3 add_branch_limitation
76 $av->add_branch_limitation( $branchcode );
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 );
97 sub del_branch_limitation
{
98 my ( $self, $branchcode ) = @_;
100 croak
("No branchcode passed in!") unless $branchcode;
103 $self->_avb_resultset->find(
104 { av_id
=> $self->id(), branchcode
=> $branchcode } );
106 unless ($limitation) {
107 my $id = $self->id();
109 "No branch limit for branch $branchcode found for av_id $id to delete!"
114 return $limitation->delete();
117 =head3 replace_branch_limitations
119 $av->replace_branch_limitations( \@branchcodes );
123 sub replace_branch_limitations
{
124 my ( $self, $branchcodes ) = @_;
126 $self->_avb_resultset->search( { av_id
=> $self->id() } )->delete();
129 map { $self->add_branch_limitation($_) } @
$branchcodes;
131 return \
@return_values;
134 =head3 opac_description
136 my $description = $av->opac_description();
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
155 $self->{_avb_resultset
} ||=
156 Koha
::Database
->new()->schema()->resultset('AuthorisedValuesBranch');
158 $self->{_avb_resultset
};
166 return 'AuthorisedValue';
171 Kyle M Hall <kyle@bywatersolutions.com>