From: Dan Scott Date: Fri, 1 Nov 2013 22:43:45 +0000 (-0400) Subject: OpeningHoursSpecification and cache fixes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=dd8a9675e3e2145883f8986cf3622e6f1ef5b1e4;p=working%2FEvergreen.git OpeningHoursSpecification and cache fixes Signed-off-by: Dan Scott --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm index cbda48f43d..d0b17a6898 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm @@ -35,7 +35,7 @@ sub load_library { $self->timelog("got basic lib info"); - # Get mailing address + # Get mailing address from the cache $library_cache ||= OpenSRF::Utils::Cache->new('global'); my $address_cache_key = "TPAC_aou_address_cache_$lib_id"; my $address = OpenSRF::Utils::JSON->JSON2perl($library_cache->get_cache($address_cache_key)); @@ -43,6 +43,7 @@ sub load_library { if ($address) { $ctx->{mailing_address} = $address; } elsif (!$address && $aou->mailing_address) { + # We didn't get cached hours, so hit the database my $session = OpenSRF::AppSession->create("open-ils.actor"); $ctx->{mailing_address} = $session->request('open-ils.actor.org_unit.address.retrieve', @@ -54,22 +55,18 @@ sub load_library { my $hours_cache_key = "TPAC_aouhoo_cache_$lib_id"; my $hours = OpenSRF::Utils::JSON->JSON2perl($library_cache->get_cache($hours_cache_key)); + # If we don't have cached hours, try the database if (!$hours) { $hours = $self->editor->retrieve_actor_org_unit_hours_of_operation($lib_id); - if ($hours->dow_0_open) { + # If we got hours from the database, cache them + if ($hours) { $library_cache->put_cache($hours_cache_key, OpenSRF::Utils::JSON->perl2JSON($hours), 360); } } + + # After all that, if we have hours, pass them to the context object if ($hours) { $ctx->{hours} = $hours; - # Generate naive schema.org format - $ctx->{hours_schema} = "Mo " . substr($hours->dow_0_open, 0, 5) . "-" . substr($hours->dow_0_close, 0, 5) . - ",Tu " . substr($hours->dow_1_open, 0, 5) . "-" . substr($hours->dow_1_close, 0, 5) . - ",We " . substr($hours->dow_2_open, 0, 5) . "-" . substr($hours->dow_2_close, 0, 5) . - ",Th " . substr($hours->dow_3_open, 0, 5) . "-" . substr($hours->dow_3_close, 0, 5) . - ",Fr " . substr($hours->dow_4_open, 0, 5) . "-" . substr($hours->dow_4_close, 0, 5) . - ",Sa " . substr($hours->dow_5_open, 0, 5) . "-" . substr($hours->dow_5_close, 0, 5) . - ",Su " . substr($hours->dow_6_open, 0, 5) . "-" . substr($hours->dow_6_close, 0, 5); } return Apache2::Const::OK; diff --git a/Open-ILS/src/templates/opac/library.tt2 b/Open-ILS/src/templates/opac/library.tt2 index 089d31c0ce..b3b63909aa 100644 --- a/Open-ILS/src/templates/opac/library.tt2 +++ b/Open-ILS/src/templates/opac/library.tt2 @@ -14,37 +14,35 @@ END; -%] - [%- IF ctx.hours_schema; %] + [%- IF ctx.hours; %]

[% l('Opening hours') %]

-
- - - - - - - +
[% + l('Monday: [_1]-[_2]', '' _ ctx.hours.dow_0_open.substr(0, 5) _ '', + '' _ ctx.hours.dow_0_close.substr(0, 5) _ '') -%] +
+
[% + l('Tuesday: [_1]-[_2]', '' _ ctx.hours.dow_1_open.substr(0, 5) _ '', + '' _ ctx.hours.dow_1_close.substr(0, 5) _ '') -%] +
+
[% + l('Wednesday: [_1]-[_2]', '' _ ctx.hours.dow_2_open.substr(0, 5) _ '', + '' _ ctx.hours.dow_2_close.substr(0, 5) _ '') -%] +
+
[% + l('Thursday: [_1]-[_2]', '' _ ctx.hours.dow_3_open.substr(0, 5) _ '', + '' _ ctx.hours.dow_3_close.substr(0, 5) _ '') -%] +
+
[% + l('Friday: [_1]-[_2]', '' _ ctx.hours.dow_4_open.substr(0, 5) _ '', + '' _ ctx.hours.dow_4_close.substr(0, 5) _ '') -%] +
+
[% + l('Saturday: [_1]-[_2]', '' _ ctx.hours.dow_5_open.substr(0, 5) _ '', + '' _ ctx.hours.dow_5_close.substr(0, 5) _ '') -%] +
+
[% + l('Sunday: [_1]-[_2]', '' _ ctx.hours.dow_6_open.substr(0, 5) _ '', + '' _ ctx.hours.dow_6_close.substr(0, 5) _ '') -%]
[% END; -%]