OpeningHoursSpecification and cache fixes
authorDan Scott <dscott@laurentian.ca>
Fri, 1 Nov 2013 22:43:45 +0000 (18:43 -0400)
committerDan Scott <dscott@laurentian.ca>
Fri, 1 Nov 2013 22:57:32 +0000 (18:57 -0400)
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm
Open-ILS/src/templates/opac/library.tt2

index cbda48f..d0b17a6 100644 (file)
@@ -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;
index 089d31c..b3b6390 100644 (file)
         END;
     -%]
 
-    [%- IF ctx.hours_schema; %]
+    [%- IF ctx.hours; %]
     <h2>[% l('Opening hours') %]</h2>
-    <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification">
-        <time><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Monday" />[%
-            l('Monday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_0_open.substr(0, 5) _ '</span>',
-             '<span property="closes">' _ ctx.hours.dow_0_close _ '</span>') -%]
-        </time>
-        <time><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Tuesday" />[%
-            l('Tuesday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_1_open.substr(0, 5) _ '</span>',
-             '<span property="closes">' _ ctx.hours.dow_1_close _ '</span>') -%]
-        </time>
-        <time><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Wednesday" />[%
-            l('Wednesday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_2_open.substr(0, 5) _ '</span>',
-             '<span property="closes">' _ ctx.hours.dow_2_close _ '</span>') -%]
-        </time>
-        <time><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Thursday" />[%
-            l('Thursday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_3_open.substr(0, 5) _ '</span>',
-             '<span property="closes">' _ ctx.hours.dow_3_close _ '</span>') -%]
-        </time>
-        <time><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Friday" />[%
-            l('Friday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_4_open.substr(0, 5) _ '</span>',
-             '<span property="closes">' _ ctx.hours.dow_4_close _ '</span>') -%]
-        </time>
-        <time><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Saturday" />[%
-            l('Saturday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_5_open.substr(0, 5) _ '</span>',
-             '<span property="closes">' _ ctx.hours.dow_5_close _ '</span>') -%]
-        </time>
-        <time><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Sunday" />[%
-            l('Sunday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_6_open.substr(0, 5) _ '</span>',
-             '<span property="closes">' _ ctx.hours.dow_6_close _ '</span>') -%]
-        </time>
+    <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Monday" />[%
+        l('Monday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_0_open.substr(0, 5) _ '</span>',
+         '<span property="closes">' _ ctx.hours.dow_0_close.substr(0, 5) _ '</span>') -%]
+    </div>
+    <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Tuesday" />[%
+        l('Tuesday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_1_open.substr(0, 5) _ '</span>',
+         '<span property="closes">' _ ctx.hours.dow_1_close.substr(0, 5) _ '</span>') -%]
+    </div>
+    <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Wednesday" />[%
+        l('Wednesday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_2_open.substr(0, 5) _ '</span>',
+         '<span property="closes">' _ ctx.hours.dow_2_close.substr(0, 5) _ '</span>') -%]
+    </div>
+    <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Thursday" />[%
+        l('Thursday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_3_open.substr(0, 5) _ '</span>',
+         '<span property="closes">' _ ctx.hours.dow_3_close.substr(0, 5) _ '</span>') -%]
+    </div>
+    <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Friday" />[%
+        l('Friday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_4_open.substr(0, 5) _ '</span>',
+         '<span property="closes">' _ ctx.hours.dow_4_close.substr(0, 5) _ '</span>') -%]
+    </div>
+    <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Saturday" />[%
+        l('Saturday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_5_open.substr(0, 5) _ '</span>',
+         '<span property="closes">' _ ctx.hours.dow_5_close.substr(0, 5) _ '</span>') -%]
+    </div>
+    <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Sunday" />[%
+        l('Sunday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_6_open.substr(0, 5) _ '</span>',
+         '<span property="closes">' _ ctx.hours.dow_6_close.substr(0, 5) _ '</span>') -%]
     </div>
     [% END; -%]