return $U->get_copy_price(new_editor(xact=>1), $copy_id);
},
+ get_org_unit => sub {
+ my $org_id = shift;
+ return $org_id if ref $org_id;
+ return new_editor()->get_actor_org_unit($org_id);
+ },
+
# given a copy, returns the title and author in a hash
get_copy_bib_basics => sub {
my $copy_id = shift;
return $U->ou_ancestor_setting_value($org_id, $setting);
},
+ get_user_setting => sub {
+ my ($user_id, $setting) = @_;
+ my $val = new_editor()->search_actor_user_setting(
+ {usr => $user_id, name => $setting})->[0];
+ return undef unless $val;
+ return OpenSRF::Utils::JSON->JSON2perl($val->value);
+ },
+
# This basically greps/maps out ths isbn string values, but also promotes the first isbn-13 to the
# front of the line (so that the EDI translator takes it as primary) if there is one.
get_li_isbns => sub {
my $unapi = new_editor()->json_query($query);
return undef unless @$unapi;
return $_TT_helpers->{xml_doc}->($unapi->[0]->{'unapi.bre'});
+ },
+
+ # escapes quotes in csv string values
+ escape_csv => sub {
+ my $string = shift;
+ $string =~ s/"/""/og;
+ return $string;
}
};
--- /dev/null
+package OpenILS::Application::Trigger::Reactor::NotifyCSV;
+use base "OpenILS::Application::Trigger::Reactor";
+use strict; use warnings;
+
+sub ABOUT {
+ return q|
+Creates a CSV representation of patron actions for the purposes of notifying
+the patron via external notification mechanisms.
+
+Event Environment Requirements
+
+* patron object with card
+* org unit
+
+Required Event Parameters
+
+notify_media (e.g. phone)
+notify_type (e.g. overdue)
+notify_level (e.g. "1" -- first overdue)
+
+The set of options for each event parameter is dependent on the 3rd-party
+processing the CSV file. Using iTiva as the reference implementation, event
+parameter values options include:
+
+notify_media : 'V' (voice), 'T' (text)
+notify_level : '1' (1st notice), '2' (2nd notice...) , '3'
+notify_type :
+ 'FINES',
+ 'OVERDUE',
+ 'PREOVERDUE',
+ 'PRERESERVE',
+ 'RECALL',
+ 'RESERVE',
+ 'RESERVECANCEL',
+ 'RESERVEEXPIRE',
+ 'SUSPEND'
+|;
+}
+
+sub handler {
+ my ($self, $env) = @_;
+ return 1 if $self->run_TT($env);
+ return 0;
+}
+
+1;
--- /dev/null
+[%
+ USE date;
+ core_type = event.event_def.hook.core_type;
+
+ SET target = [target] UNLESS event.event_def.group_field;
+ notice_org_unit = helpers.get_org_unit(event.event_def.owner);
+
+ FOR target_obj IN target;
+
+ # Mangle the data into a consistent shape
+
+ circ = '';
+ hold = '';
+ copy = '';
+ user = '';
+ title = '';
+ org_unit = '';
+ due_date = '';
+
+ IF core_type == 'circ';
+ # e.g. overdue circ
+ circ = target_obj;
+ user = circ.usr;
+ copy = circ.target_copy;
+ org_unit = circ.circ_lib;
+ due_date = date.format(
+ helpers.format_date(circ.due_date), '%d/%m/%Y');
+
+ ELSIF core_type == 'ahr':
+ # e.g. hold ready for pickup
+ hold = target_obj;
+ user = hold.usr;
+ copy = hold.current_copy;
+ org_unit = hold.pickup_lib;
+
+ ELSIF core_type == 'ausp';
+ # e.g. max fines
+ user = target_obj.usr;
+ org_unit = target_obj.org_unit;
+
+ ELSIF core_type == 'au':
+ # e.g. barred
+ user = target_obj;
+ org_unit = user.home_ou;
+ END;
+
+ user_locale = helpers.get_user_locale(user.id));
+ user_lang = user_locale | replace('-.*', ''); # ISO 639-1 language
+ user_phone = helpers.get_user_setting(
+ user.id, 'opac.default_phone') || user.day_phone;
+
+ IF copy;
+ bib_data = helpers.get_copy_bib_basics(copy.id);
+ title = bib_data.title;
+ END;
+
+ # Print the data for each target object as CSV
+%]
+[%- '"' _ helpers.escape_csv(params.notify_media) _ '",' -%]
+[%- '"' _ helpers.escape_csv(user_lang) _ '",' -%]
+[%- '"' _ helpers.escape_csv(params.notify_type) _ '",' -%]
+[%- '"' _ helpers.escape_csv(params.notify_level) _ '",' -%]
+[%- '"' _ helpers.escape_csv(user.card.barcode) _ '",' -%]
+[%- '"' _ helpers.escape_csv(user.prefix) _ '",' -%]
+[%- '"' _ helpers.escape_csv(user.first_given_name) _ '",' -%]
+[%- '"' _ helpers.escape_csv(user.family_name) _ '",' -%]
+[%- '"' _ helpers.escape_csv(user_phone) _ '",' -%]
+[%- '"' _ helpers.escape_csv(user.email) _ '",' -%]
+[%- '"' _ helpers.escape_csv(notice_org_unit.shortname) _ '",' -%]
+[%- '"' _ helpers.escape_csv(org_unit.shortname) _ '",' -%]
+[%- '"' _ helpers.escape_csv(org_name.name) _ '",' -%]
+[%- '"' _ helpers.escape_csv(copy.barcode) _ '",' -%]
+[%- '"' _ helpers.escape_csv(due_date) _ '",' -%]
+[%- '"' _ helpers.escape_csv(title) _ '",' -%]
+[%- '"' _ helpers.escape_csv(event.id) _ '"' -%]
+[% END %]