Browse Source
Signed-off-by: Lisette Scheer <lisetteslatah@gmail.com> Signed-off-by: Jesse Maseto <jesse@bywatersolution.com> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>18.11.x
3 changed files with 298 additions and 0 deletions
@ -0,0 +1,82 @@ |
|||
package Koha::CirculationRule; |
|||
|
|||
# Copyright Vaara-kirjastot 2015 |
|||
# |
|||
# This file is part of Koha. |
|||
# |
|||
# Koha is free software; you can redistribute it and/or modify it under the |
|||
# terms of the GNU General Public License as published by the Free Software |
|||
# Foundation; either version 3 of the License, or (at your option) any later |
|||
# version. |
|||
# |
|||
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
|||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License along |
|||
# with Koha; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
use Modern::Perl; |
|||
|
|||
use base qw(Koha::Object); |
|||
|
|||
use Koha::Libraries; |
|||
use Koha::Patron::Categories; |
|||
use Koha::ItemTypes; |
|||
|
|||
=head1 NAME |
|||
|
|||
Koha::Hold - Koha Hold object class |
|||
|
|||
=head1 API |
|||
|
|||
=head2 Class Methods |
|||
|
|||
=cut |
|||
|
|||
=head3 library |
|||
|
|||
=cut |
|||
|
|||
sub library { |
|||
my ($self) = @_; |
|||
|
|||
$self->{_library} ||= Koha::Libraries->find( $self->branchcode ); |
|||
|
|||
return $self->{_library}; |
|||
} |
|||
|
|||
=head3 patron_category |
|||
|
|||
=cut |
|||
|
|||
sub patron_category { |
|||
my ($self) = @_; |
|||
|
|||
$self->{_patron_category} ||= Koha::Patron::Categories->find( $self->categorycode ); |
|||
|
|||
return $self->{_patron_category}; |
|||
} |
|||
|
|||
=head3 item_type |
|||
|
|||
=cut |
|||
|
|||
sub item_type { |
|||
my ($self) = @_; |
|||
|
|||
$self->{_item_type} ||= Koha::ItemTypes->find( $self->itemtype ); |
|||
|
|||
return $self->{item_type}; |
|||
} |
|||
|
|||
=head3 _type |
|||
|
|||
=cut |
|||
|
|||
sub _type { |
|||
return 'CirculationRule'; |
|||
} |
|||
|
|||
1; |
@ -0,0 +1,171 @@ |
|||
package Koha::CirculationRules; |
|||
|
|||
# Copyright Vaara-kirjastot 2015 |
|||
# Copyright Koha Development Team 2016 |
|||
# |
|||
# This file is part of Koha. |
|||
# |
|||
# Koha is free software; you can redistribute it and/or modify it under the |
|||
# terms of the GNU General Public License as published by the Free Software |
|||
# Foundation; either version 3 of the License, or (at your option) any later |
|||
# version. |
|||
# |
|||
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
|||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License along |
|||
# with Koha; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
use Modern::Perl; |
|||
|
|||
use Carp qw(croak); |
|||
|
|||
use Koha::CirculationRule; |
|||
|
|||
use base qw(Koha::Objects); |
|||
|
|||
=head1 NAME |
|||
|
|||
Koha::IssuingRules - Koha IssuingRule Object set class |
|||
|
|||
=head1 API |
|||
|
|||
=head2 Class Methods |
|||
|
|||
=cut |
|||
|
|||
=head3 get_effective_rule |
|||
|
|||
=cut |
|||
|
|||
sub get_effective_rule { |
|||
my ( $self, $params ) = @_; |
|||
|
|||
my $rule_name = $params->{rule_name}; |
|||
my $categorycode = $params->{categorycode}; |
|||
my $itemtype = $params->{itemtype}; |
|||
my $branchcode = $params->{branchcode}; |
|||
|
|||
croak q{No rule name passed in!} unless $rule_name; |
|||
|
|||
my $search_params; |
|||
$search_params->{rule_name} = $rule_name; |
|||
|
|||
$search_params->{categorycode} = defined $categorycode ? { 'in' => [ $categorycode, '*' ] } : undef; |
|||
$search_params->{itemtype} = defined $itemtype ? { 'in' => [ $itemtype, '*' ] } : undef; |
|||
$search_params->{branchcode} = defined $branchcode ? { 'in' => [ $branchcode, '*' ] } : undef; |
|||
|
|||
my $rule = $self->search( |
|||
$search_params, |
|||
{ |
|||
order_by => { |
|||
-desc => [ 'branchcode', 'categorycode', 'itemtype' ] |
|||
}, |
|||
rows => 1, |
|||
} |
|||
)->single; |
|||
|
|||
return $rule; |
|||
} |
|||
|
|||
=head3 set_rule |
|||
|
|||
=cut |
|||
|
|||
sub set_rule { |
|||
my ( $self, $params ) = @_; |
|||
|
|||
croak q{set_rule requires the parameter 'branchcode'!} |
|||
unless exists $params->{branchcode}; |
|||
croak q{set_rule requires the parameter 'categorycode'!} |
|||
unless exists $params->{categorycode}; |
|||
croak q{set_rule requires the parameter 'itemtype'!} |
|||
unless exists $params->{itemtype}; |
|||
croak q{set_rule requires the parameter 'rule_name'!} |
|||
unless exists $params->{rule_name}; |
|||
croak q{set_rule requires the parameter 'rule_value'!} |
|||
unless exists $params->{rule_value}; |
|||
|
|||
my $branchcode = $params->{branchcode}; |
|||
my $categorycode = $params->{categorycode}; |
|||
my $itemtype = $params->{itemtype}; |
|||
my $rule_name = $params->{rule_name}; |
|||
my $rule_value = $params->{rule_value}; |
|||
|
|||
my $rule = $self->search( |
|||
{ |
|||
rule_name => $rule_name, |
|||
branchcode => $branchcode, |
|||
categorycode => $categorycode, |
|||
itemtype => $itemtype, |
|||
} |
|||
)->next(); |
|||
|
|||
if ($rule) { |
|||
if ( defined $rule_value ) { |
|||
$rule->rule_value($rule_value); |
|||
$rule->update(); |
|||
} |
|||
else { |
|||
$rule->delete(); |
|||
} |
|||
} |
|||
else { |
|||
if ( defined $rule_value ) { |
|||
$rule = Koha::CirculationRule->new( |
|||
{ |
|||
branchcode => $branchcode, |
|||
categorycode => $categorycode, |
|||
itemtype => $itemtype, |
|||
rule_name => $rule_name, |
|||
rule_value => $rule_value, |
|||
} |
|||
); |
|||
$rule->store(); |
|||
} |
|||
} |
|||
|
|||
return $rule; |
|||
} |
|||
|
|||
=head3 set_rules |
|||
|
|||
=cut |
|||
|
|||
sub set_rules { |
|||
my ( $self, $params ) = @_; |
|||
warn Data::Dumper::Dumper( $params ); |
|||
|
|||
my $branchcode = $params->{branchcode}; |
|||
my $categorycode = $params->{categorycode}; |
|||
my $itemtype = $params->{itemtype}; |
|||
my $rules = $params->{rules}; |
|||
|
|||
foreach my $rule (@$rules) { |
|||
Koha::CirculationRules->set_rule( |
|||
{ |
|||
branchcode => $branchcode, |
|||
categorycode => $categorycode, |
|||
itemtype => $itemtype, |
|||
rule_name => $rule->{rule_name}, |
|||
rule_value => $rule->{rule_value}, |
|||
} |
|||
); |
|||
} |
|||
} |
|||
|
|||
=head3 type |
|||
|
|||
=cut |
|||
|
|||
sub _type { |
|||
return 'CirculationRule'; |
|||
} |
|||
|
|||
sub object_class { |
|||
return 'Koha::CirculationRule'; |
|||
} |
|||
|
|||
1; |
@ -0,0 +1,45 @@ |
|||
package Koha::Template::Plugin::CirculationRules; |
|||
|
|||
# Copyright ByWater Solutions 2017 |
|||
|
|||
# This file is part of Koha. |
|||
# |
|||
# Koha is free software; you can redistribute it and/or modify it |
|||
# under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 3 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# Koha is distributed in the hope that it will be useful, but |
|||
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
|||
|
|||
use Modern::Perl; |
|||
|
|||
use base qw( Template::Plugin ); |
|||
|
|||
use Koha::CirculationRules; |
|||
|
|||
sub Get { |
|||
my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_; |
|||
|
|||
$branchcode = undef if $branchcode eq q{}; |
|||
$categorycode = undef if $categorycode eq q{}; |
|||
$itemtype = undef if $itemtype eq q{}; |
|||
|
|||
my $rule = Koha::CirculationRules->search( |
|||
{ |
|||
branchcode => $branchcode, |
|||
categorycode => $categorycode, |
|||
itemtype => $itemtype, |
|||
rule_name => $rule_name, |
|||
} |
|||
)->next(); |
|||
|
|||
return $rule->rule_value if $rule; |
|||
} |
|||
|
|||
1; |
Loading…
Reference in new issue