From af13d2cc5fd343be70d7959556747b138ab8ecd9 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 17 Apr 2013 10:31:04 -0400 Subject: [PATCH] long-overdue : PatronNotInCollections Validator Signed-off-by: Bill Erickson --- .../lib/OpenILS/Application/Trigger/Validator.pm | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm index 6b5dc3c399..e7940ead1c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm @@ -6,6 +6,7 @@ use OpenSRF::Utils qw/:datetime/; use OpenSRF::Utils::Logger qw/:logger/; use OpenILS::Const qw/:const/; use OpenILS::Application::AppUtils; +use OpenILS::Utils::CStoreEditor qw/:funcs/; sub fourty_two { return 42 } sub NOOP_True { return 1 } sub NOOP_False { return 0 } @@ -161,4 +162,30 @@ sub PatronNotBarred { return !PatronBarred(@_); } +# core type "circ". +# Being "In Collections" means having the PATRON_IN_COLLECTIONS penalty +# applied to the user at or above the circ_lib of the target circ. +sub PatronNotInCollections { + my ($self, $env) = @_; + my $user = $env->{target}->usr; + my $org = $env->{target}->circ_lib; + + # beware environment fleshing + $user = $user->id if ref $user; + $org = $org->id if ref $org; + + my $existing = new_editor()->search_usr_standing_penalty({ + usr => $user, + org_unit => $U->get_org_ancestors($org, 1), + standing_penalty => 30, # PATRON_IN_COLLECTIONS + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ] + }); + + return @$existing ? 0 : 1; +} + + 1; -- 2.11.0