1 package OpenILS::Application::Trigger::Reactor::ApplyPatronPenalty;
2 use base 'OpenILS::Application::Trigger::Reactor';
3 use strict; use warnings;
5 use OpenILS::Const qw/:const/;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenSRF::Utils::Logger qw/$logger/;
8 use OpenILS::Utils::CStoreEditor q/:funcs/;
9 use OpenILS::Application::AppUtils;
10 my $U = "OpenILS::Application::AppUtils";
16 Applies a standing penalty to a patron. If there is a template, the template is
17 used as the value for the note
19 Required named (with labels) environment variables:
20 "user" -- User object fleshed into the environment
21 "context_org" -- Org unit object fleshed into the environment
23 Note: Using named env variables with a grouped event definition where the
24 env vars may be different depending on the target produces undefined behavior.
25 Don't use this reactor if more than one User or Org Unit object may be
26 referenced accross the set of target objects.
35 my $pname = $$env{params}{standing_penalty};
36 my $user = $$env{environment}{user};
37 my $context_org = $$env{environment}{context_org};
39 unless($pname and ref $user and ref $context_org) {
40 $logger->error("ApplyPatronPenalty: missing parameters");
44 my $e = new_editor(xact => 1);
46 my $ptype = $e->search_config_standing_penalty({name => $pname})->[0];
49 $logger->error("ApplyPatronPenalty: invalid penalty name '$pname'");
54 $context_org = (defined $ptype->org_depth) ?
55 $U->org_unit_ancestor_at_depth($context_org->id, $ptype->org_depth) :
59 my $penalty = Fieldmapper::actor::usr_standing_penalty->new;
60 $penalty->usr($user->id);
61 $penalty->org_unit($context_org);
62 $penalty->standing_penalty($ptype->id);
63 $penalty->note($self->run_TT($env));
65 unless($e->create_actor_user_standing_penalty($penalty)) {