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
;
27 use base
qw(Koha::Object);
31 Koha::Patron;;Category - Koha Patron;;Category Object class
39 =head3 effective_BlockExpiredPatronOpacActions
41 my $BlockExpiredPatronOpacActions = $category->effective_BlockExpiredPatronOpacActions
43 Return the effective BlockExpiredPatronOpacActions value.
47 sub effective_BlockExpiredPatronOpacActions
{
49 return C4
::Context
->preference('BlockExpiredPatronOpacActions') if $self->BlockExpiredPatronOpacActions == -1;
50 return $self->BlockExpiredPatronOpacActions
60 $self->dateofbirthrequired(undef)
61 if not defined $self->dateofbirthrequired
62 or $self->dateofbirthrequired eq '';
64 $self->upperagelimit(undef)
65 if not defined $self->upperagelimit
66 or $self->upperagelimit eq '';
68 $self->checkprevcheckout('inherit')
69 unless defined $self->checkprevcheckout;
71 return $self->SUPER::store
;
74 =head3 default_messaging
76 my $messaging = $category->default_messaging();
80 sub default_messaging
{
82 my $messaging_options = C4
::Members
::Messaging
::GetMessagingOptions
();
84 foreach my $option (@
$messaging_options) {
85 my $pref = C4
::Members
::Messaging
::GetMessagingPreferences
(
87 categorycode
=> $self->categorycode,
88 message_name
=> $option->{message_name
}
91 next unless $pref->{transports
};
93 message_attribute_id
=> $option->{message_attribute_id
},
94 message_name
=> $option->{message_name
},
95 $option->{'message_name'} => 1,
97 foreach my $transport ( keys %{ $pref->{transports
} } ) {
98 push @
{ $brief_pref->{transports
} }, { transport
=> $transport };
100 push @messaging, $brief_pref;
105 =head3 branch_limitations
107 my $limitations = $category->branch_limitations();
109 $category->branch_limitations( \@branchcodes );
113 sub branch_limitations
{
114 my ( $self, $branchcodes ) = @_;
117 return $self->replace_branch_limitations($branchcodes);
120 return $self->get_branch_limitations();
125 =head3 get_branch_limitations
127 my $limitations = $category->get_branch_limitations();
131 sub get_branch_limitations
{
135 $self->_catb_resultset->search( { categorycode
=> $self->categorycode } )
136 ->get_column('branchcode')->all();
138 return \
@branchcodes;
141 =head3 add_branch_limitation
143 $category->add_branch_limitation( $branchcode );
147 sub add_branch_limitation
{
148 my ( $self, $branchcode ) = @_;
150 croak
("No branchcode passed in!") unless $branchcode;
152 my $limitation = $self->_catb_resultset->update_or_create(
153 { categorycode
=> $self->categorycode, branchcode
=> $branchcode } );
155 return $limitation ?
1 : undef;
158 =head3 del_branch_limitation
160 $category->del_branch_limitation( $branchcode );
164 sub del_branch_limitation
{
165 my ( $self, $branchcode ) = @_;
167 croak
("No branchcode passed in!") unless $branchcode;
170 $self->_catb_resultset->find(
171 { categorycode
=> $self->categorycode, branchcode
=> $branchcode } );
173 unless ($limitation) {
174 my $categorycode = $self->categorycode;
176 "No branch limit for branch $branchcode found for categorycode $categorycode to delete!"
181 return $limitation->delete();
184 =head3 replace_branch_limitations
186 $category->replace_branch_limitations( \@branchcodes );
190 sub replace_branch_limitations
{
191 my ( $self, $branchcodes ) = @_;
193 $self->_catb_resultset->search( { categorycode
=> $self->categorycode } )->delete;
196 map { $self->add_branch_limitation($_) } @
$branchcodes;
198 return \
@return_values;
201 =head3 Koha::Objects->_catb_resultset
203 Returns the internal resultset or creates it if undefined
207 sub _catb_resultset
{
210 $self->{_catb_resultset
} ||=
211 Koha
::Database
->new->schema->resultset('CategoriesBranch');
213 return $self->{_catb_resultset
};
216 sub get_expiry_date
{
217 my ($self, $date ) = @_;
218 if ( $self->enrolmentperiod ) {
219 $date ||= dt_from_string
;
220 $date = dt_from_string
( $date ) unless ref $date;
221 return $date->add( months
=> $self->enrolmentperiod, end_of_month
=> 'limit' );
223 return $self->enrolmentperioddate;