View | Details | Raw Unified | Return to bug 23830
Collapse All | Expand All

(-)a/Koha/AuthorisedValues.pm (-28 / +1 lines)
Lines 27-33 use Koha::AuthorisedValue; Link Here
27
use Koha::MarcSubfieldStructures;
27
use Koha::MarcSubfieldStructures;
28
use Koha::Cache::Memory::Lite;
28
use Koha::Cache::Memory::Lite;
29
29
30
use base qw(Koha::Objects);
30
use base qw(Koha::Objects Koha::Objects::Limit::Library);
31
31
32
=head1 NAME
32
=head1 NAME
33
33
Lines 39-71 Koha::AuthorisedValues - Koha Authorised value Object set class Link Here
39
39
40
=cut
40
=cut
41
41
42
=head3 Koha::AuthorisedValues->search();
43
44
my @objects = Koha::AuthorisedValues->search($params);
45
46
=cut
47
48
sub search {
49
    my ( $self, $params, $attributes ) = @_;
50
51
    my $branchcode = $params->{branchcode};
52
    delete( $params->{branchcode} );
53
54
    my $or =
55
      $branchcode
56
      ? {
57
        '-or' => [
58
            'authorised_values_branches.branchcode' => undef,
59
            'authorised_values_branches.branchcode' => $branchcode,
60
        ]
61
      }
62
      : {};
63
    my $join = $branchcode ? { join => 'authorised_values_branches' } : {};
64
    $attributes //= {};
65
    $attributes = { %$attributes, %$join };
66
    return $self->SUPER::search( { %$params, %$or, }, $attributes );
67
}
68
69
sub search_by_marc_field {
42
sub search_by_marc_field {
70
    my ( $self, $params ) = @_;
43
    my ( $self, $params ) = @_;
71
    my $frameworkcode = $params->{frameworkcode} || '';
44
    my $frameworkcode = $params->{frameworkcode} || '';
(-)a/t/db_dependent/AuthorisedValues.t (-4 / +3 lines)
Lines 119-132 my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode}; Link Here
119
119
120
$av1->add_library_limit( $branchcode1 );
120
$av1->add_library_limit( $branchcode1 );
121
121
122
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode1 } );
122
@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $branchcode1 );
123
is( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" );
123
is( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" );
124
124
125
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
125
@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $branchcode2 );
126
is( @authorised_values, 2, "Search including value with a branch limit ( branch *cannot* use the limited value ) gives correct number of results" );
126
is( @authorised_values, 2, "Search including value with a branch limit ( branch *cannot* use the limited value ) gives correct number of results" );
127
127
128
$av1->del_library_limit( $branchcode1 );
128
$av1->del_library_limit( $branchcode1 );
129
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
129
@authorised_values = Koha::AuthorisedValues->search_with_library_limits( { category => 'av_for_testing' }, {}, $branchcode2 );
130
is( @authorised_values, 3, "Branch limitation deleted successfully" );
130
is( @authorised_values, 3, "Branch limitation deleted successfully" );
131
131
132
$av1->add_library_limit( $branchcode1 );
132
$av1->add_library_limit( $branchcode1 );
133
- 

Return to bug 23830