Marcel de Rooy
b4c66d5cc4
This patch does the following: [1] Move some POD lines from Cache to Caches. [2] Correct C4::Plugins to Koha::Plugins in POD line of Koha::Plugins [3] POD Koha/AuthorisedValue.pm: lib_opac moved to opac_description [4] The POD in Koha/Patron.pm uses head2 and head3 inconsistently. Ran s/^=head2/=head3/ on those lines (7 substitutions on 7 lines) [5] Correct a copied POD line from reports/issues_stats.pl in reports/reserve_stats.pl. [6] Correct a test description in t/db_dependent/Koha/Authorities.t. You should never delete the library :) [7] Correct typo shouild in a comment of rebuild_zebra.pl Test plan: [1] Read the patch. Does it make sense? [2] Run perldoc Koha/Cache.pm and Koha/Caches.pm [3] Run t/db_dependent/Koha/Authorities.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: David Cook <dcook@prosentient.com.au> Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
175 lines
3.4 KiB
Perl
175 lines
3.4 KiB
Perl
package Koha::AuthorisedValue;
|
|
|
|
# Copyright ByWater Solutions 2014
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it under the
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
# Foundation; either version 3 of the License, or (at your option) any later
|
|
# version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with Koha; if not, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
use Modern::Perl;
|
|
|
|
use Carp;
|
|
|
|
use Koha::Database;
|
|
|
|
use base qw(Koha::Object);
|
|
|
|
=head1 NAME
|
|
|
|
Koha::AuthorisedValue - Koha Authorised value Object class
|
|
|
|
=head1 API
|
|
|
|
=head2 Class Methods
|
|
|
|
=cut
|
|
|
|
=head3 branch_limitations
|
|
|
|
my $limitations = $av->branch_limitations();
|
|
|
|
$av->branch_limitations( \@branchcodes );
|
|
|
|
=cut
|
|
|
|
sub branch_limitations {
|
|
my ( $self, $branchcodes ) = @_;
|
|
|
|
if ($branchcodes) {
|
|
return $self->replace_branch_limitations($branchcodes);
|
|
}
|
|
else {
|
|
return $self->get_branch_limitations();
|
|
}
|
|
|
|
}
|
|
|
|
=head3 get_branch_limitations
|
|
|
|
my $limitations = $av->get_branch_limitations();
|
|
|
|
=cut
|
|
|
|
sub get_branch_limitations {
|
|
my ($self) = @_;
|
|
|
|
my @branchcodes =
|
|
$self->_avb_resultset->search( { av_id => $self->id() } )
|
|
->get_column('branchcode')->all();
|
|
|
|
return \@branchcodes;
|
|
}
|
|
|
|
=head3 add_branch_limitation
|
|
|
|
$av->add_branch_limitation( $branchcode );
|
|
|
|
=cut
|
|
|
|
sub add_branch_limitation {
|
|
my ( $self, $branchcode ) = @_;
|
|
|
|
croak("No branchcode passed in!") unless $branchcode;
|
|
|
|
my $limitation = $self->_avb_resultset->update_or_create(
|
|
{ av_id => $self->id(), branchcode => $branchcode } );
|
|
|
|
return $limitation ? 1 : undef;
|
|
}
|
|
|
|
=head3 del_branch_limitation
|
|
|
|
$av->del_branch_limitation( $branchcode );
|
|
|
|
=cut
|
|
|
|
sub del_branch_limitation {
|
|
my ( $self, $branchcode ) = @_;
|
|
|
|
croak("No branchcode passed in!") unless $branchcode;
|
|
|
|
my $limitation =
|
|
$self->_avb_resultset->find(
|
|
{ av_id => $self->id(), branchcode => $branchcode } );
|
|
|
|
unless ($limitation) {
|
|
my $id = $self->id();
|
|
carp(
|
|
"No branch limit for branch $branchcode found for av_id $id to delete!"
|
|
);
|
|
return;
|
|
}
|
|
|
|
return $limitation->delete();
|
|
}
|
|
|
|
=head3 replace_branch_limitations
|
|
|
|
$av->replace_branch_limitations( \@branchcodes );
|
|
|
|
=cut
|
|
|
|
sub replace_branch_limitations {
|
|
my ( $self, $branchcodes ) = @_;
|
|
|
|
$self->_avb_resultset->search( { av_id => $self->id() } )->delete();
|
|
|
|
my @return_values =
|
|
map { $self->add_branch_limitation($_) } @$branchcodes;
|
|
|
|
return \@return_values;
|
|
}
|
|
|
|
=head3 opac_description
|
|
|
|
my $description = $av->opac_description();
|
|
|
|
=cut
|
|
|
|
sub opac_description {
|
|
my ( $self, $value ) = @_;
|
|
|
|
return $self->lib_opac() || $self->lib();
|
|
}
|
|
|
|
=head3 _avb_resultset
|
|
|
|
Returns the internal resultset or creates it if undefined
|
|
|
|
=cut
|
|
|
|
sub _avb_resultset {
|
|
my ($self) = @_;
|
|
|
|
$self->{_avb_resultset} ||=
|
|
Koha::Database->new()->schema()->resultset('AuthorisedValuesBranch');
|
|
|
|
$self->{_avb_resultset};
|
|
}
|
|
|
|
=head3 type
|
|
|
|
=cut
|
|
|
|
sub _type {
|
|
return 'AuthorisedValue';
|
|
}
|
|
|
|
=head1 AUTHOR
|
|
|
|
Kyle M Hall <kyle@bywatersolutions.com>
|
|
|
|
=cut
|
|
|
|
1;
|