]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Merge branch 'master' of git+ssh://yeti.esilibrary.com/home/evergreen/evergreen-equin...
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / WWW / EGCatLoader / Record.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 #   record : bre object
12 sub load_record {
13     my $self = shift;
14     $self->ctx->{page} = 'record';
15
16     my $org = $self->cgi->param('loc') || $self->ctx->{aou_tree}->()->id;
17     my $depth = $self->cgi->param('depth') || 0;
18     my $copy_limit = int($self->cgi->param('copy_limit') || 20);
19     my $copy_offset = int($self->cgi->param('copy_offset') || 0);
20
21     my $rec_id = $self->ctx->{page_args}->[0]
22         or return Apache2::Const::HTTP_BAD_REQUEST;
23
24     # run copy retrieval in parallel to bib retrieval
25     my $copy_rec = OpenSRF::AppSession->create('open-ils.cstore')->request(
26         'open-ils.cstore.json_query.atomic', 
27         $self->mk_copy_query($rec_id, $org, $depth, $copy_limit, $copy_offset));
28
29     $self->ctx->{record} = $self->editor->retrieve_biblio_record_entry($rec_id);
30     $self->ctx->{marc_xml} = XML::LibXML->new->parse_string($self->ctx->{record}->marc);
31
32     $self->ctx->{copies} = $copy_rec->gather(1);
33     $self->ctx->{copy_limit} = $copy_limit;
34     $self->ctx->{copy_offset} = $copy_offset;
35
36     return Apache2::Const::OK;
37 }
38
39 sub mk_copy_query {
40     my $self = shift;
41     my $rec_id = shift;
42     my $org = shift;
43     my $depth = shift;
44     my $copy_limit = shift;
45     my $copy_offset = shift;
46
47     my $query = {
48         select => {
49             acp => ['id', 'barcode', 'circ_lib', 'create_date', 'age_protect', 'holdable'],
50             acpl => [
51                 {column => 'name', alias => 'copy_location'},
52                 {column => 'holdable', alias => 'location_holdable'}
53             ],
54             ccs => [
55                 {column => 'name', alias => 'copy_status'},
56                 {column => 'holdable', alias => 'status_holdable'}
57             ],
58             acn => [
59                 {column => 'label', alias => 'call_number_label'},
60                 {column => 'id', alias => 'call_number'}
61             ],
62             circ => ['due_date'],
63         },
64         from => {
65             acp => {
66                 acn => {},
67                 acpl => {},
68                 ccs => {},
69                 circ => {type => 'left'},
70                 aou => {}
71             }
72         },
73         where => {
74             '+acp' => {
75                 deleted => 'f',
76                 call_number => {
77                     in => {
78                         select => {acn => ['id']},
79                         from => 'acn',
80                         where => {record => $rec_id}
81                     }
82                 },
83                 circ_lib => {
84                     in => {
85                         select => {aou => [{
86                             column => 'id', 
87                             transform => 'actor.org_unit_descendants', 
88                             result_field => 'id', 
89                             params => [$depth]
90                         }]},
91                         from => 'aou',
92                         where => {id => $org}
93                     }
94                 }
95             },
96             '+acn' => {deleted => 'f'},
97             '+circ' => {checkin_time => undef}
98         },
99
100         # Order is: copies with circ_lib=org, followed by circ_lib name, followed by call_number label
101         order_by => [
102             {class => 'aou', field => 'name'}, 
103             {class => 'acn', field => 'label'}
104         ],
105
106         limit => $copy_limit,
107         offset => $copy_offset
108     };
109
110     # Filter hidden items if this is the public catalog
111     unless($self->ctx->{is_staff}) { 
112         $query->{where}->{'+acp'}->{opac_visible} = 't';
113         $query->{where}->{'+acpl'}->{opac_visible} = 't';
114         $query->{where}->{'+ccs'}->{opac_visible} = 't';
115     }
116
117     return $query;
118     #return $self->editor->json_query($query);
119 }
120
121 sub mk_marc_html {
122     my($self, $rec_id) = @_;
123
124     $self->ctx->{marc_html} = $U->simplereq(
125         'open-ils.search', 'open-ils.search.biblio.record.html', $rec_id);
126 }
127
128 1;