From 92c77d5ffe133198f612afcc8bcd16f74af69d19 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Sat, 26 Oct 2013 17:32:22 -0400 Subject: [PATCH] First inklings of schema.org support for library pages Adds a TPAC page where the information for a given library can be publicly exposed; in addition, that information is marked up with schema.org structured data so that, for example, a search engine can offer up the hours of operation and contact information for a given branch right on the search results page. We give the content-wrapper a main-content for indentation, to be consistent with other pages in the TPAC. We also add the cargo-cult common-full-pad div for a bottom margin. Signed-off-by: Dan Scott Signed-off-by: Dan Wells --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 2 + .../lib/OpenILS/WWW/EGCatLoader/Library.pm | 62 ++++++++++++++++++++++ Open-ILS/src/templates/opac/library.tt2 | 57 ++++++++++++++++++++ .../src/templates/opac/parts/library/hours.tt2 | 57 ++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm create mode 100644 Open-ILS/src/templates/opac/library.tt2 create mode 100644 Open-ILS/src/templates/opac/parts/library/hours.tt2 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 0af9399168..e5ceb0f242 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -20,6 +20,7 @@ use Time::HiRes; use OpenILS::WWW::EGCatLoader::Util; use OpenILS::WWW::EGCatLoader::Account; use OpenILS::WWW::EGCatLoader::Browse; +use OpenILS::WWW::EGCatLoader::Library; use OpenILS::WWW::EGCatLoader::Search; use OpenILS::WWW::EGCatLoader::Record; use OpenILS::WWW::EGCatLoader::Container; @@ -121,6 +122,7 @@ sub load { return $self->load_simple("advanced") if $path =~ m:opac/(advanced|numeric|expert):; + return $self->load_library if $path =~ m|opac/library|; return $self->load_rresults if $path =~ m|opac/results|; return $self->load_print_record if $path =~ m|opac/record/print|; return $self->load_record if $path =~ m|opac/record/\d|; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm new file mode 100644 index 0000000000..18094dd3be --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm @@ -0,0 +1,62 @@ +package OpenILS::WWW::EGCatLoader; +use strict; use warnings; +use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST); +use OpenSRF::Utils::Logger qw/$logger/; +use OpenILS::Utils::CStoreEditor qw/:funcs/; +use OpenILS::Utils::Fieldmapper; +use OpenILS::Application::AppUtils; +my $U = 'OpenILS::Application::AppUtils'; + +# context additions: +# library : aou object +# parent: aou object +sub load_library { + my $self = shift; + my %kwargs = @_; + my $ctx = $self->ctx; + $ctx->{page} = 'library'; + + $self->timelog("load_library() began"); + + my $lib_id = $ctx->{page_args}->[0]; + $lib_id = $self->_resolve_org_id_or_shortname($lib_id); + + return Apache2::Const::HTTP_BAD_REQUEST + unless $lib_id; + + my $aou = $ctx->{get_aou}->($lib_id); + my $sname = $aou->parent_ou; + + $ctx->{library} = $aou; + if ($aou->parent_ou) { + $ctx->{parent} = $ctx->{get_aou}->($aou->parent_ou); + } + + $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; +} + +1; diff --git a/Open-ILS/src/templates/opac/library.tt2 b/Open-ILS/src/templates/opac/library.tt2 new file mode 100644 index 0000000000..0a33e2df87 --- /dev/null +++ b/Open-ILS/src/templates/opac/library.tt2 @@ -0,0 +1,57 @@ +[%- PROCESS "opac/parts/header.tt2"; + WRAPPER "opac/parts/base.tt2"; + INCLUDE "opac/parts/topnav.tt2"; + ctx.page_title = l("Library details: [_1]", ctx.library.name); +-%] + [%- INCLUDE "opac/parts/searchbar.tt2" %] +
+
+

[% ctx.library.name | html %]

+ + [%- + lib_url = ctx.get_org_setting(ctx.library.id, 'lib.info_url'); + IF lib_url; + ''; + END; + -%] + + [%- IF ctx.hours; %] + [%- INCLUDE "opac/parts/library/hours.tt2"; %] + [% END; -%] + + [%- IF (ctx.library.email OR ctx.library.phone); %] +

[% l('Contact information') %]

+ [%- IF ctx.library.email; %] +
[% l('Email address: ') %][% ctx.library.email | html %]
+ [%- END; %] + [%- IF ctx.library.phone; %] +
[% l('Telephone: ') %][% ctx.library.phone | html %]
+ [% END; %] + [% END; %] + + [%- IF ctx.library.mailing_address; %] +
+
+

[% l('Mailing address') %]

+ [% ctx.mailing_address.street1 | html %] + [%- IF ctx.mailing_address.street2; "
"; ctx.mailing_address.street2 | html; END; %] +

+ [% ctx.mailing_address.city | html %]
+ [% ctx.mailing_address.state | html %]
+ [% ctx.mailing_address.country | html %]
+ [% ctx.mailing_address.post_code | html %]
+
+
+ [%- END; %] + + [%- IF ctx.library.parent_ou; %] +

Branch relationship

+
[% l('Parent library: ') %] + [% ctx.parent.name | html %] +
+ [% END; -%] + +
+
+[%- END %] +
diff --git a/Open-ILS/src/templates/opac/parts/library/hours.tt2 b/Open-ILS/src/templates/opac/parts/library/hours.tt2 new file mode 100644 index 0000000000..37513b1010 --- /dev/null +++ b/Open-ILS/src/templates/opac/parts/library/hours.tt2 @@ -0,0 +1,57 @@ +

[% l('Opening hours') %]

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