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

(-)a/Koha/AuthorisedValue.pm (-111 / +13 lines)
Lines 23-29 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use base qw(Koha::Object);
26
use base qw(Koha::Object Koha::Object::Limit::Library);
27
27
28
=head1 NAME
28
=head1 NAME
29
29
Lines 31-136 Koha::AuthorisedValue - Koha Authorised value Object class Link Here
31
31
32
=head1 API
32
=head1 API
33
33
34
=head2 Class Methods
34
=head2 Class methods
35
35
36
=cut
36
=cut
37
37
38
=head3 branch_limitations
39
40
my $limitations = $av->branch_limitations();
41
42
$av->branch_limitations( \@branchcodes );
43
44
=cut
45
46
sub branch_limitations {
47
    my ( $self, $branchcodes ) = @_;
48
49
    if ($branchcodes) {
50
        return $self->replace_branch_limitations($branchcodes);
51
    }
52
    else {
53
        return $self->get_branch_limitations();
54
    }
55
56
}
57
58
=head3 get_branch_limitations
59
60
my $limitations = $av->get_branch_limitations();
61
62
=cut
63
64
sub get_branch_limitations {
65
    my ($self) = @_;
66
67
    my @branchcodes =
68
      $self->_avb_resultset->search( { av_id => $self->id() } )
69
      ->get_column('branchcode')->all();
70
71
    return \@branchcodes;
72
}
73
74
=head3 add_branch_limitation
75
76
$av->add_branch_limitation( $branchcode );
77
78
=cut
79
80
sub add_branch_limitation {
81
    my ( $self, $branchcode ) = @_;
82
83
    croak("No branchcode passed in!") unless $branchcode;
84
85
    my $limitation = $self->_avb_resultset->update_or_create(
86
        { av_id => $self->id(), branchcode => $branchcode } );
87
88
    return $limitation ? 1 : undef;
89
}
90
91
=head3 del_branch_limitation
92
93
$av->del_branch_limitation( $branchcode );
94
95
=cut
96
97
sub del_branch_limitation {
98
    my ( $self, $branchcode ) = @_;
99
100
    croak("No branchcode passed in!") unless $branchcode;
101
102
    my $limitation =
103
      $self->_avb_resultset->find(
104
        { av_id => $self->id(), branchcode => $branchcode } );
105
106
    unless ($limitation) {
107
        my $id = $self->id();
108
        carp(
109
"No branch limit for branch $branchcode found for av_id $id to delete!"
110
        );
111
        return;
112
    }
113
114
    return $limitation->delete();
115
}
116
117
=head3 replace_branch_limitations
118
119
$av->replace_branch_limitations( \@branchcodes );
120
121
=cut
122
123
sub replace_branch_limitations {
124
    my ( $self, $branchcodes ) = @_;
125
126
    $self->_avb_resultset->search( { av_id => $self->id() } )->delete();
127
128
    my @return_values =
129
      map { $self->add_branch_limitation($_) } @$branchcodes;
130
131
    return \@return_values;
132
}
133
134
=head3 opac_description
38
=head3 opac_description
135
39
136
my $description = $av->opac_description();
40
my $description = $av->opac_description();
Lines 143-169 sub opac_description { Link Here
143
    return $self->lib_opac() || $self->lib();
47
    return $self->lib_opac() || $self->lib();
144
}
48
}
145
49
146
=head3 _avb_resultset
50
=head2 Internal methods
147
51
148
Returns the internal resultset or creates it if undefined
52
=head3 _type
149
53
150
=cut
54
=cut
151
55
152
sub _avb_resultset {
56
sub _type {
153
    my ($self) = @_;
57
    return 'AuthorisedValue';
154
155
    $self->{_avb_resultset} ||=
156
      Koha::Database->new()->schema()->resultset('AuthorisedValuesBranch');
157
158
    $self->{_avb_resultset};
159
}
58
}
160
59
161
=head3 type
60
=head3 _library_limits
162
61
163
=cut
62
=cut
164
63
165
sub _type {
64
sub _library_limits {
166
    return 'AuthorisedValue';
65
    return {
66
        class   => 'AuthorisedValuesBranch',
67
        id      => 'av_id',
68
        library => 'branchcode'
69
    };
167
}
70
}
168
71
169
=head1 AUTHOR
72
=head1 AUTHOR
170
- 

Return to bug 23272