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
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use List::MoreUtils qw( any );
22 use C4::Members::Messaging;
25 use Koha::DateUtils qw( dt_from_string );
27 use base qw(Koha::Object Koha::Object::Limit::Library);
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 sub get_expiry_date {
106 my ($self, $date ) = @_;
107 if ( $self->enrolmentperiod ) {
108 $date ||= dt_from_string;
109 $date = dt_from_string( $date ) unless ref $date;
110 return $date->add( months => $self->enrolmentperiod, end_of_month => 'limit' );
112 return $self->enrolmentperioddate;
116 =head3 effective_reset_password
118 Returns if patrons in this category can reset their password. If set in $self->reset_password
119 or, if undef, falls back to the OpacResetPassword system preference.
123 sub effective_reset_password {
126 return $self->reset_password // C4::Context->preference('OpacResetPassword');
129 =head3 effective_change_password
131 Returns if patrons in this category can change their password. If set in $self->change_password
132 or, if undef, falls back to the OpacPasswordChange system preference.
136 sub effective_change_password {
139 return $self->change_password // C4::Context->preference('OpacPasswordChange');
142 =head3 effective_min_password_length
144 $category->effective_min_password_length()
146 Retrieve category's password length if set, or minPasswordLength otherwise
150 sub effective_min_password_length {
153 return $self->min_password_length // C4::Context->preference('minPasswordLength');
156 =head3 effective_require_strong_password
158 $category->effective_require_strong_password()
160 Retrieve category's password strength if set, or RequireStrongPassword otherwise
164 sub effective_require_strong_password {
167 return $self->require_strong_password // C4::Context->preference('RequireStrongPassword');
170 =head3 override_hidden_items
172 if ( $patron->category->override_hidden_items ) {
176 Returns a boolean that if patrons of this category are exempt from the OPACHiddenItems policies
178 TODO: Remove on bug 22547
182 sub override_hidden_items {
184 return any { $_ eq $self->categorycode }
185 split( /\|/, C4::Context->preference('OpacHiddenItemsExceptions') );
188 =head2 Internal methods
190 =head3 _library_limits
192 configure library limits
196 sub _library_limits {
198 class => "CategoriesBranch",
199 id => "categorycode",
200 library => "branchcode",