use Koha::MarcSubfieldStructures;
use Koha::Cache::Memory::Lite;
-use base qw(Koha::Objects);
+use base qw(Koha::Objects Koha::Objects::Limit::Library);
=head1 NAME
=cut
-=head3 Koha::AuthorisedValues->search();
-
-my @objects = Koha::AuthorisedValues->search($params);
-
-=cut
-
-sub search {
- my ( $self, $params, $attributes ) = @_;
-
- my $branchcode = $params->{branchcode};
- delete( $params->{branchcode} );
-
- my $or =
- $branchcode
- ? {
- '-or' => [
- 'authorised_values_branches.branchcode' => undef,
- 'authorised_values_branches.branchcode' => $branchcode,
- ]
- }
- : {};
- my $join = $branchcode ? { join => 'authorised_values_branches' } : {};
- $attributes //= {};
- $attributes = { %$attributes, %$join };
- return $self->SUPER::search( { %$params, %$or, }, $attributes );
-}
-
sub search_by_marc_field {
my ( $self, $params ) = @_;
my $frameworkcode = $params->{frameworkcode} || '';
$av1->add_library_limit( $branchcode1 );
-@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode1 } );
+@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $branchcode1 );
is( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" );
-@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
+@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $branchcode2 );
is( @authorised_values, 2, "Search including value with a branch limit ( branch *cannot* use the limited value ) gives correct number of results" );
$av1->del_library_limit( $branchcode1 );
-@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
+@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $branchcode2 );
is( @authorised_values, 3, "Branch limitation deleted successfully" );
$av1->add_library_limit( $branchcode1 );