1 package OpenILS::WWW::EGCatLoader;
2 use strict; use warnings;
3 use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST);
4 use OpenSRF::Utils::JSON;
5 use OpenSRF::Utils::Logger qw/$logger/;
7 use DateTime::Format::ISO8601;
8 use OpenILS::Utils::CStoreEditor qw/:funcs/;
9 use OpenILS::Utils::Fieldmapper;
10 use OpenILS::Application::AppUtils;
11 my $U = 'OpenILS::Application::AppUtils';
15 # library : aou object
21 $ctx->{page} = 'library';
23 $self->timelog("load_library() began");
25 my $lib_id = $ctx->{page_args}->[0];
26 $lib_id = $self->_resolve_org_id_or_shortname($lib_id);
28 return Apache2::Const::HTTP_BAD_REQUEST unless $lib_id;
30 my $aou = $ctx->{get_aou}->($lib_id);
31 my $sname = $aou->parent_ou;
33 $ctx->{library} = $aou;
34 if ($aou->parent_ou) {
35 $ctx->{parent} = $ctx->{get_aou}->($aou->parent_ou);
38 $self->timelog("got basic lib info");
40 # Get mailing address from the cache
41 $library_cache ||= OpenSRF::Utils::Cache->new('global');
42 my $address_cache_key = "TPAC_aou_address_cache_$lib_id";
43 my $address = OpenSRF::Utils::JSON->JSON2perl($library_cache->get_cache($address_cache_key));
46 $ctx->{mailing_address} = $address;
47 } elsif (!$address && $aou->mailing_address) {
48 # We didn't get cached hours, so hit the database
49 my $session = OpenSRF::AppSession->create("open-ils.actor");
50 $ctx->{mailing_address} =
51 $session->request('open-ils.actor.org_unit.address.retrieve',
52 $aou->mailing_address)->gather(1);
53 $library_cache->put_cache($address_cache_key, OpenSRF::Utils::JSON->perl2JSON($ctx->{mailing_address}), 360);
56 # Get current hours of operation
57 my $hours_cache_key = "TPAC_aouhoo_cache_$lib_id";
58 my $hours = OpenSRF::Utils::JSON->JSON2perl($library_cache->get_cache($hours_cache_key));
60 # If we don't have cached hours, try the database
62 $hours = $self->editor->retrieve_actor_org_unit_hours_of_operation($lib_id);
63 # If we got hours from the database, cache them
65 $library_cache->put_cache($hours_cache_key, OpenSRF::Utils::JSON->perl2JSON($hours), 360);
69 # After all that, if we have hours, pass them to the context object
71 $ctx->{hours} = $hours;
74 # Get upcoming closed dates
75 my $dt = DateTime->now(time_zone => 'local');
76 my $start = $dt->year .'-'. $dt->month .'-'. $dt->day;
78 my $dates = $self->editor->search_actor_org_unit_closed_date([
79 {close_end => { ">=" => $start },
82 {order_by => {aoucd => 'close_start'},
87 $ctx->{closed_dates} = $dates;
89 return Apache2::Const::OK;