Add library hours and mailing address to schema.org output
authorDan Scott <dscott@laurentian.ca>
Sat, 26 Oct 2013 23:24:02 +0000 (19:24 -0400)
committerDan Scott <dscott@laurentian.ca>
Fri, 1 Nov 2013 20:31:13 +0000 (16:31 -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 9853432..18094dd 100644 (file)
@@ -19,17 +19,13 @@ sub load_library {
     $self->timelog("load_library() began");
 
     my $lib_id = $ctx->{page_args}->[0];
-
-    $self->apache->log->warn("got library $lib_id!");
     $lib_id = $self->_resolve_org_id_or_shortname($lib_id);
-    $self->apache->log->warn("now got library $lib_id!");
 
     return Apache2::Const::HTTP_BAD_REQUEST 
         unless $lib_id;
 
     my $aou = $ctx->{get_aou}->($lib_id);
     my $sname = $aou->parent_ou;
-    $self->apache->log->warn("now got library $sname");
 
     $ctx->{library} = $aou;
     if ($aou->parent_ou) {
@@ -38,6 +34,28 @@ sub load_library {
 
     $self->timelog("got basic lib info");
 
+    # Get mailing address
+    if ($aou->mailing_address) {
+        my $session = OpenSRF::AppSession->create("open-ils.actor");
+        $ctx->{mailing_address} =
+            $session->request('open-ils.actor.org_unit.address.retrieve',
+            $aou->mailing_address)->gather(1);
+    }
+
+    # Get current hours of operation
+    my $hours = $self->editor->retrieve_actor_org_unit_hours_of_operation($lib_id);
+    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 a7a6a4f..7321457 100644 (file)
@@ -7,6 +7,19 @@
     <div id="content-wrapper" class="content-wrapper-library-page" vocab="http://schema.org/" typeof="Library">
     <h1 property="name">[% ctx.library.name %]</h1>
 
+    [%- IF ctx.hours_schema; %]
+    <h2>[% l('Opening hours') %]</h2>
+    <time class="opening-hours" property="openingHours" datetime="[% ctx.hours_schema %]">
+        <div>[% l('Monday: [_1]-[_2]', ctx.hours.dow_0_open.substr(0, 5), ctx.hours.dow_0_close) %]</div>
+        <div>[% l('Tuesday: [_1]-[_2]', ctx.hours.dow_1_open.substr(0, 5), ctx.hours.dow_1_close) %]</div>
+        <div>[% l('Wednesday: [_1]-[_2]', ctx.hours.dow_2_open.substr(0, 5), ctx.hours.dow_2_close) %]</div>
+        <div>[% l('Thursday: [_1]-[_2]', ctx.hours.dow_3_open.substr(0, 5), ctx.hours.dow_3_close) %]</div>
+        <div>[% l('Friday: [_1]-[_2]', ctx.hours.dow_4_open.substr(0, 5), ctx.hours.dow_4_close) %]</div>
+        <div>[% l('Saturday: [_1]-[_2]', ctx.hours.dow_5_open.substr(0, 5), ctx.hours.dow_5_close) %]</div>
+        <div>[% l('Sunday: [_1]-[_2]', ctx.hours.dow_6_open.substr(0, 5), ctx.hours.dow_6_close) %]</div>
+    </time>
+    [% END; -%]
+
     [%- IF (ctx.library.email OR ctx.library.phone); %]
     <h2 id="contact-info">[% l('Contact information') %]</h2>
     [%- IF ctx.library.email; %]
     [% END; %]
     [% END; %]
 
-    <h2>[% l('Opening hours') %]</h2>
-    <div>Pull in from actor.hours_of_operation</div>
-
-    <div id="addresses">
     [%- IF ctx.library.mailing_address; %]
-    <div id="mailing" property="location address" typeof="PostalAddess">
-        <h3 property="contactType">[% l('Mailing address') %]</h3>
-        [%# Pull in actor.org_address properties here %]
-        <span property="streetAddress">ctx.library.mailing_address.street1<br />
-            IF we have it - ctx.library.mailing_address.street2
-        </span><br />
-        <span property="addressLocality">ctx.library.mailing_address.city</span><br />
-        <span property="addressRegion">ctx.library.mailing_address.state</span><br />
-        <span property="addressCountry" typeof="Country">ctx.library.mailing_address.country</span><br />
-        <span property="postalCode">ctx.library.mailing_address.post_code</span><br />
+    <div id="addresses">
+        <div id="mailing" property="location address" typeof="PostalAddress">
+            <h3 property="contactType">[% l('Mailing address') %]</h3>
+            <span property="streetAddress">[% ctx.mailing_address.street1 %]
+            [%- IF ctx.mailing_address.street2; "<br />"; ctx.mailing_address.street2; END; %]
+            </span><br />
+            <span property="addressLocality">[% ctx.mailing_address.city %]</span><br />
+            <span property="addressRegion">[% ctx.mailing_address.state %]</span><br />
+            <span property="addressCountry">[% ctx.mailing_address.country %]</span><br />
+            <span property="postalCode">[% ctx.mailing_address.post_code %]</span><br />
+        </div>
     </div>
     [%- END; %]
-    </div>
 
     [%- IF ctx.library.parent_ou; %]
     <h2>Branch relationship</h2>