Bugzilla – Attachment 36097 Details for
Bug 13742
Object accessor for overduerules- and overduerules_transport_types-tables.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13742 - Object accessor for overduerules- and overduerules_transport_types-tables.
Bug-13742---Object-accessor-for-overduerules--and-.patch (text/plain), 7.89 KB, created by
Olli-Antti Kivilahti
on 2015-02-20 16:39:01 UTC
(
hide
)
Description:
Bug 13742 - Object accessor for overduerules- and overduerules_transport_types-tables.
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2015-02-20 16:39:01 UTC
Size:
7.89 KB
patch
obsolete
>From 7bca226e7301e5dcb9b811f47533be90f0de1bc9 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Fri, 20 Feb 2015 18:34:45 +0200 >Subject: [PATCH] Bug 13742 - Object accessor for overduerules- and > overduerules_transport_types-tables. > >Adds a Koha::Cache:able OverdueRulesMap-object to present a nicer interface for >using overduerules. >Easily extendable to move a lot of scripting from overduerules.pl with proper >setters. > >Unit test included. >--- > C4/Overdues/OverdueRulesMap.pm | 163 ++++++++++++++++++++++++++++++++++++++++ > t/db_dependent/Overdues.t | 28 +++++-- > 2 files changed, 186 insertions(+), 5 deletions(-) > create mode 100644 C4/Overdues/OverdueRulesMap.pm > >diff --git a/C4/Overdues/OverdueRulesMap.pm b/C4/Overdues/OverdueRulesMap.pm >new file mode 100644 >index 0000000..eb03d6e >--- /dev/null >+++ b/C4/Overdues/OverdueRulesMap.pm >@@ -0,0 +1,163 @@ >+package C4::Overdues::OverdueRulesMap; >+ >+# Copyright 2015 Vaara-kirjastot >+# >+# 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 2 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 C4::Context qw(dbh); >+ >+ >+use vars qw($VERSION @ISA @EXPORT); >+ >+BEGIN { >+ # set the version for version checking >+ $VERSION = 3.19.01; >+ require Exporter; >+ @ISA = qw(Exporter); >+ push @EXPORT, qw( >+ &new >+ &getRulesForBranch >+ ); >+} >+ >+=head new >+ >+ my $orm = C4::Overdues::OverdueRulesMap->new(); >+ >+Finds a OverdueRulesMap from Koha::Cache or instantiates a new one. >+ >+OverdueRulesMap (orm) is a map-representation of the overduerules- and >+overduerules_transport_types-tables. >+The cache entry is valid for 300 seconds. >+ >+See getRulesForBranch() for structural representation. >+=cut >+ >+sub new { >+ my ($class) = @_; >+ >+ my $cache = Koha::Cache->get_instance(); >+ my $orm = $cache->get_from_cache('overdueRulesMap'); >+ unless ($orm) { >+ $orm = _getOverdueActionsMap(); >+ bless $orm, $class; >+ $cache->set_in_cache('overdueRulesMap', $orm, {expiry => 300}); >+ } >+ return $orm if ref $orm eq 'C4::Overdues::OverdueRulesMap'; >+ return undef; >+} >+ >+=head getRulesForBranch >+ >+ my $overduerules = $orm->getRulesForBranch('CPL'); >+ >+Finds the overduerules and message_transport_types for the given branch. >+If the branch has even one overduerule defined for a borrower category, >+ will use that and skip checking for any defaults even for the missing >+ borrower categories. >+If the branch has no overduerules defined, will use the default rules. >+ >+@RETURNS Hash, of overduerules for the given branch. The HASH looks like this: >+ { >+ STAFF => { #Borrower Categories >+ 1 => { #Letter numbers >+ delay => 12, >+ letter => 'ODUE1', >+ debarred => undef ||Â 1, >+ message_transport_types => { print => 1, >+ sms => 1, >+ ... >+ } >+ }, >+ 2 => {..}, >+ ... >+ }, >+ PATRON => {...}, >+ ... >+ } >+=cut >+ >+sub getRulesForBranch { >+ my ($self, $branchCode) = @_; >+ >+ return $self->{$branchCode} if $self->{$branchCode}; >+ return $self->{''}; >+} >+ >+sub _getOverdueActionsMap { >+ >+ my $map = {}; >+ my $overduerules = _getOverduerules(); >+ my $overduerules_transport_types = _getOverduerules_transport_types(); >+ >+ #Make a map out of the overduerules-table. >+ foreach my $o (@$overduerules) { >+ $map->{ $o->{branchcode} }-> >+ { $o->{categorycode} }-> >+ { 1 } >+ = >+ { delay => $o->{delay1}, >+ letter => $o->{letter1}, >+ debarred => $o->{debarred1}, >+ }; >+ >+ $map->{ $o->{branchcode} }-> >+ { $o->{categorycode} }-> >+ { 2 } >+ = >+ { delay => $o->{delay2}, >+ letter => $o->{letter2}, >+ debarred => $o->{debarred2}, >+ }; >+ >+ $map->{ $o->{branchcode} }-> >+ { $o->{categorycode} }-> >+ { 3 } >+ = >+ { delay => $o->{delay3}, >+ letter => $o->{letter3}, >+ debarred => $o->{debarred3}, >+ }; >+ } >+ >+ #Merge a map of the overduerules_transport_types >+ foreach my $ott (@$overduerules_transport_types) { >+ $map->{ $ott->{branchcode} }-> >+ { $ott->{categorycode} }-> >+ { $ott->{letternumber} }-> >+ { 'message_transport_types' }-> >+ { $ott->{message_transport_type} } = 1; >+ } >+ return $map; >+} >+ >+sub _getOverduerules { >+ my $dbh = C4::Context->dbh(); >+ my $sth = $dbh->prepare("SELECT * FROM overduerules"); >+ $sth->execute(); >+ my $overduerules = $sth->fetchall_arrayref({}); >+ return $overduerules; >+} >+sub _getOverduerules_transport_types { >+ my $dbh = C4::Context->dbh(); >+ my $sth = $dbh->prepare("SELECT * FROM overduerules_transport_types"); >+ $sth->execute(); >+ my $overduerules_transport_types = $sth->fetchall_arrayref({}); >+ return $overduerules_transport_types; >+} >+1; #Satisfy the compiler >\ No newline at end of file >diff --git a/t/db_dependent/Overdues.t b/t/db_dependent/Overdues.t >index 4fc8402..39fc7a3 100644 >--- a/t/db_dependent/Overdues.t >+++ b/t/db_dependent/Overdues.t >@@ -5,6 +5,7 @@ use Test::More tests => 16; > > use C4::Context; > use C4::Branch; >+use C4::Overdues::OverdueRulesMap; > use_ok('C4::Overdues'); > can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes'); > can_ok('C4::Overdues', 'GetBranchcodesWithOverdueRules'); >@@ -24,11 +25,11 @@ $dbh->do(q| > |); > > $dbh->do(q| >- INSERT INTO overduerules ( branchcode, categorycode ) VALUES >- ('CPL', 'PT'), >- ('CPL', 'YA'), >- ('', 'PT'), >- ('', 'YA') >+ INSERT INTO overduerules ( branchcode, categorycode, delay1, letter1, debarred1, delay2, letter2, debarred2, delay3, letter3, debarred3 ) VALUES >+ ('CPL', 'PT', 15, 'CPLODUE1', 0, 30, 'ODUE2', 0, 45, 'ODUECLAIM', 1), >+ ('CPL', 'YA', 17, 'CPLODUE1', 0, 33, 'ODUE2', 0, 49, 'ODUECLAIM', 1), >+ ('', 'PT', 21, 'ODUE1', 0, 42, 'ODUE2', 0, 70, 'ODUECLAIM', 1), >+ ('', 'YA', 23, 'ODUE1', 0, 46, 'ODUE2', 0, 78, 'ODUECLAIM', 0) > |); > > $dbh->do(q| >@@ -46,6 +47,23 @@ $dbh->do(q| > ('', 'YA', 2, 'sms') > |); > >+ >+my $orm = C4::Overdues::OverdueRulesMap->new(); >+my $overdueRules = $orm->getRulesForBranch('CPL'); >+is( $overdueRules->{PT}->{1}->{letter} , 'CPLODUE1' , "OverdueRulesMap: Fetch 'letter' for deviant rules branch"); >+ >+$overdueRules = $orm->getRulesForBranch('LAP'); #Non-existent branch! >+is( $overdueRules->{PT}->{2}->{delay} , 42 , "OverdueRulesMap: Fetch 'delay' for default rules branch"); >+ >+$overdueRules = $orm->getRulesForBranch(''); >+is( $overdueRules->{YA}->{3}->{debarred} , 0 , "OverdueRulesMap: Fetch 'debarred' for default rules branch"); >+ >+$overdueRules = $orm->getRulesForBranch('CPL'); >+is( $overdueRules->{YA}->{3}->{message_transport_types}->{print} , 1 , "OverdueRulesMap: Fetch 'message_transport_type' for deviant rules branch"); >+ >+$overdueRules = $orm->getRulesForBranch('CPL'); >+ok( (not($overdueRules->{YA}->{2}->{message_transport_types}->{sms})) , "OverdueRulesMap: Fetch 'message_transport_type' for deviant rules branch cannot use default rules"); >+ > my $mtts; > > $mtts = C4::Overdues::GetOverdueMessageTransportTypes('CPL', 'PT'); >-- >1.7.9.5
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 13742
:
36097
|
36103