]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Library.pm
First inklings of schema.org support for library pages
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / WWW / EGCatLoader / Library.pm
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::Logger qw/$logger/;
5 use OpenILS::Utils::CStoreEditor qw/:funcs/;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenILS::Application::AppUtils;
8 my $U = 'OpenILS::Application::AppUtils';
9
10 # context additions: 
11 #   library : aou object
12 #   parent: aou object
13 sub load_library {
14     my $self = shift;
15     my %kwargs = @_;
16     my $ctx = $self->ctx;
17     $ctx->{page} = 'library';  
18
19     $self->timelog("load_library() began");
20
21     my $lib_id = $ctx->{page_args}->[0];
22     $lib_id = $self->_resolve_org_id_or_shortname($lib_id);
23
24     return Apache2::Const::HTTP_BAD_REQUEST 
25         unless $lib_id;
26
27     my $aou = $ctx->{get_aou}->($lib_id);
28     my $sname = $aou->parent_ou;
29
30     $ctx->{library} = $aou;
31     if ($aou->parent_ou) {
32         $ctx->{parent} = $ctx->{get_aou}->($aou->parent_ou);
33     }
34
35     $self->timelog("got basic lib info");
36
37     # Get mailing address
38     if ($aou->mailing_address) {
39         my $session = OpenSRF::AppSession->create("open-ils.actor");
40         $ctx->{mailing_address} =
41             $session->request('open-ils.actor.org_unit.address.retrieve',
42             $aou->mailing_address)->gather(1);
43     }
44
45     # Get current hours of operation
46     my $hours = $self->editor->retrieve_actor_org_unit_hours_of_operation($lib_id);
47     if ($hours) {
48         $ctx->{hours} = $hours;
49         # Generate naive schema.org format
50         $ctx->{hours_schema} = "Mo " . substr($hours->dow_0_open, 0, 5) . "-" . substr($hours->dow_0_close, 0, 5) .
51             ",Tu " . substr($hours->dow_1_open, 0, 5) . "-" . substr($hours->dow_1_close, 0, 5) .
52             ",We " . substr($hours->dow_2_open, 0, 5) . "-" . substr($hours->dow_2_close, 0, 5) .
53             ",Th " . substr($hours->dow_3_open, 0, 5) . "-" . substr($hours->dow_3_close, 0, 5) .
54             ",Fr " . substr($hours->dow_4_open, 0, 5) . "-" . substr($hours->dow_4_close, 0, 5) .
55             ",Sa " . substr($hours->dow_5_open, 0, 5) . "-" . substr($hours->dow_5_close, 0, 5) .
56             ",Su " . substr($hours->dow_6_open, 0, 5) . "-" . substr($hours->dow_6_close, 0, 5);
57     }
58
59     return Apache2::Const::OK;
60 }
61
62 1;