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
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.
22 use C4
::Members
::Messaging
;
26 use base
qw(Koha::Object);
30 Koha::Patron;;Category - Koha Patron;;Category Object class
38 =head3 default_messaging
40 my $messaging = $category->default_messaging();
44 sub default_messaging
{
46 my $messaging_options = C4
::Members
::Messaging
::GetMessagingOptions
();
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
};
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;
69 =head3 branch_limitations
71 my $limitations = $category->branch_limitations();
73 $category->branch_limitations( \@branchcodes );
77 sub branch_limitations
{
78 my ( $self, $branchcodes ) = @_;
81 return $self->replace_branch_limitations($branchcodes);
84 return $self->get_branch_limitations();
89 =head3 get_branch_limitations
91 my $limitations = $category->get_branch_limitations();
95 sub get_branch_limitations
{
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 );
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 );
128 sub del_branch_limitation
{
129 my ( $self, $branchcode ) = @_;
131 croak
("No branchcode passed in!") unless $branchcode;
134 $self->_catb_resultset->find(
135 { categorycode
=> $self->categorycode, branchcode
=> $branchcode } );
137 unless ($limitation) {
138 my $categorycode = $self->categorycode;
140 "No branch limit for branch $branchcode found for categorycode $categorycode to delete!"
145 return $limitation->delete();
148 =head3 replace_branch_limitations
150 $category->replace_branch_limitations( \@branchcodes );
154 sub replace_branch_limitations
{
155 my ( $self, $branchcodes ) = @_;
157 $self->_catb_resultset->search( { categorycode
=> $self->categorycode } )->delete;
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
171 sub _catb_resultset
{
174 $self->{_catb_resultset
} ||=
175 Koha
::Database
->new->schema->resultset('CategoriesBranch');
177 return $self->{_catb_resultset
};