Bugzilla – Attachment 70989 Details for
Bug 18887
Introduce new table 'circulation_rules', use for 'max_holds' rules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18887 - Add Koha::CirculationRule(s)
Bug-18887---Add-KohaCirculationRules.patch (text/plain), 8.67 KB, created by
Jesse Weaver
on 2018-01-26 21:38:47 UTC
(
hide
)
Description:
Bug 18887 - Add Koha::CirculationRule(s)
Filename:
MIME Type:
Creator:
Jesse Weaver
Created:
2018-01-26 21:38:47 UTC
Size:
8.67 KB
patch
obsolete
>From 371195a0276bd4e4cdcf8ec229ca98a31b013ede Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Mon, 6 Mar 2017 18:20:03 +0000 >Subject: [PATCH] Bug 18887 - Add Koha::CirculationRule(s) > >--- > Koha/CirculationRule.pm | 82 +++++++++++++++ > Koha/CirculationRules.pm | 171 +++++++++++++++++++++++++++++++ > Koha/Template/Plugin/CirculationRules.pm | 45 ++++++++ > 3 files changed, 298 insertions(+) > create mode 100644 Koha/CirculationRule.pm > create mode 100644 Koha/CirculationRules.pm > create mode 100644 Koha/Template/Plugin/CirculationRules.pm > >diff --git a/Koha/CirculationRule.pm b/Koha/CirculationRule.pm >new file mode 100644 >index 0000000000..918385c0ca >--- /dev/null >+++ b/Koha/CirculationRule.pm >@@ -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; >diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm >new file mode 100644 >index 0000000000..8004e95196 >--- /dev/null >+++ b/Koha/CirculationRules.pm >@@ -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; >diff --git a/Koha/Template/Plugin/CirculationRules.pm b/Koha/Template/Plugin/CirculationRules.pm >new file mode 100644 >index 0000000000..cc1e9127af >--- /dev/null >+++ b/Koha/Template/Plugin/CirculationRules.pm >@@ -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; >-- >2.15.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18887
:
65233
|
65234
|
65235
|
65236
|
65237
|
67620
|
70986
|
70987
|
70988
|
70989
|
70990
|
70991
|
71031
|
71042
|
72218
|
72219
|
72220
|
72221
|
72222
|
72223
|
72224
|
77080
|
77081
|
77082
|
77083
|
77084
|
77085
|
77086
|
77087
|
77207
|
77208
|
77209
|
77210
|
77211
|
77212
|
77213
|
77214
|
77215
|
77218
|
77238
|
77649
|
77650
|
77651
|
77652
|
77653
|
77654
|
77655
|
77656
|
77657
|
77658
|
77659
|
78346
|
78347
|
78348
|
78349
|
78350
|
78351
|
78352
|
78353
|
78354
|
78355
|
78356
|
78674
|
78675
|
78676
|
78677
|
78678
|
78679
|
78680
|
78681
|
78682
|
78683
|
78684
|
78743
|
78744
|
78745
|
78746
|
78747
|
78748
|
78749
|
78750
|
78751
|
78752
|
78753
|
78879
|
79119
|
79626
|
79627
|
79628
|
79629
|
79630
|
79631
|
79632
|
79633
|
79634
|
79635
|
79636
|
79637
|
79638
|
79639
|
79640
|
79641
|
79761
|
79762
|
79763
|
79764
|
79765
|
79766
|
79767
|
79768
|
79769
|
79770
|
79771
|
79772
|
79773
|
79774
|
79775
|
79776
|
79778
|
79891