Bug 16148: Fix submit button text
[koha.git] / Koha / Patron / Category.pm
blob7b17c8c084577b383fbe9ebb0fb61f5897d516e0
1 package Koha::Patron::Category;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 use Modern::Perl;
20 use Carp;
22 use C4::Members::Messaging;
24 use Koha::Database;
26 use base qw(Koha::Object);
28 =head1 NAME
30 Koha::Patron;;Category - Koha Patron;;Category Object class
32 =head1 API
34 =head2 Class Methods
36 =cut
38 =head3 default_messaging
40 my $messaging = $category->default_messaging();
42 =cut
44 sub default_messaging {
45 my ( $self ) = @_;
46 my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
47 my @messaging;
48 foreach my $option (@$messaging_options) {
49 my $pref = C4::Members::Messaging::GetMessagingPreferences(
51 categorycode => $self->categorycode,
52 message_name => $option->{message_name}
55 next unless $pref->{transports};
56 my $brief_pref = {
57 message_attribute_id => $option->{message_attribute_id},
58 message_name => $option->{message_name},
59 $option->{'message_name'} => 1,
61 foreach my $transport ( keys %{ $pref->{transports} } ) {
62 push @{ $brief_pref->{transports} }, { transport => $transport };
64 push @messaging, $brief_pref;
66 return \@messaging;
69 =head3 branch_limitations
71 my $limitations = $category->branch_limitations();
73 $category->branch_limitations( \@branchcodes );
75 =cut
77 sub branch_limitations {
78 my ( $self, $branchcodes ) = @_;
80 if ($branchcodes) {
81 return $self->replace_branch_limitations($branchcodes);
83 else {
84 return $self->get_branch_limitations();
89 =head3 get_branch_limitations
91 my $limitations = $category->get_branch_limitations();
93 =cut
95 sub get_branch_limitations {
96 my ($self) = @_;
98 my @branchcodes =
99 $self->_catb_resultset->search( { categorycode => $self->categorycode } )
100 ->get_column('branchcode')->all();
102 return \@branchcodes;
105 =head3 add_branch_limitation
107 $category->add_branch_limitation( $branchcode );
109 =cut
111 sub add_branch_limitation {
112 my ( $self, $branchcode ) = @_;
114 croak("No branchcode passed in!") unless $branchcode;
116 my $limitation = $self->_catb_resultset->update_or_create(
117 { categorycode => $self->categorycode, branchcode => $branchcode } );
119 return $limitation ? 1 : undef;
122 =head3 del_branch_limitation
124 $category->del_branch_limitation( $branchcode );
126 =cut
128 sub del_branch_limitation {
129 my ( $self, $branchcode ) = @_;
131 croak("No branchcode passed in!") unless $branchcode;
133 my $limitation =
134 $self->_catb_resultset->find(
135 { categorycode => $self->categorycode, branchcode => $branchcode } );
137 unless ($limitation) {
138 my $categorycode = $self->categorycode;
139 carp(
140 "No branch limit for branch $branchcode found for categorycode $categorycode to delete!"
142 return;
145 return $limitation->delete();
148 =head3 replace_branch_limitations
150 $category->replace_branch_limitations( \@branchcodes );
152 =cut
154 sub replace_branch_limitations {
155 my ( $self, $branchcodes ) = @_;
157 $self->_catb_resultset->search( { categorycode => $self->categorycode } )->delete;
159 my @return_values =
160 map { $self->add_branch_limitation($_) } @$branchcodes;
162 return \@return_values;
165 =head3 Koha::Objects->_catb_resultset
167 Returns the internal resultset or creates it if undefined
169 =cut
171 sub _catb_resultset {
172 my ($self) = @_;
174 $self->{_catb_resultset} ||=
175 Koha::Database->new->schema->resultset('CategoriesBranch');
177 return $self->{_catb_resultset};
180 =head3 type
182 =cut
184 sub _type {
185 return 'Category';