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';
15 $ctx->{page} = 'record';
17 my $org = $self->cgi->param('loc') || $ctx->{aou_tree}->()->id;
18 my $depth = $self->cgi->param('depth') || 0;
19 my $copy_limit = int($self->cgi->param('copy_limit') || 10);
20 my $copy_offset = int($self->cgi->param('copy_offset') || 0);
22 my $rec_id = $ctx->{page_args}->[0]
23 or return Apache2::Const::HTTP_BAD_REQUEST;
25 # run copy retrieval in parallel to bib retrieval
27 my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
28 my $copy_rec = $cstore->request(
29 'open-ils.cstore.json_query.atomic',
30 $self->mk_copy_query($rec_id, $org, $depth, $copy_limit, $copy_offset)
33 my (undef, @rec_data) = $self->get_records_and_facets([$rec_id], undef, {flesh => '{holdings_xml,mra,acp}'});
34 $ctx->{bre_id} = $rec_data[0]->{id};
35 $ctx->{marc_xml} = $rec_data[0]->{marc_xml};
37 $ctx->{copies} = $copy_rec->gather(1);
38 $ctx->{copy_limit} = $copy_limit;
39 $ctx->{copy_offset} = $copy_offset;
41 $ctx->{have_holdings_to_show} = 0;
42 $self->get_hold_copy_summary($rec_id, $org);
46 # XXX TODO we'll also need conditional logic to show MFHD-based holdings
48 $ctx->{get_org_setting}->
49 ($org, "opac.fully_compressed_serial_holdings")
51 $ctx->{holding_summaries} =
52 $self->get_holding_summaries($rec_id, $org, $depth);
54 $ctx->{have_holdings_to_show} =
55 scalar(@{$ctx->{holding_summaries}->{basic}}) ||
56 scalar(@{$ctx->{holding_summaries}->{index}}) ||
57 scalar(@{$ctx->{holding_summaries}->{supplement}});
60 # XXX probably should replace the following with a dispatch table
61 for my $expand ($self->cgi->param('expand')) {
62 $ctx->{"expand_$expand"} = 1;
63 if ($expand eq 'marchtml') {
64 $ctx->{marchtml} = $self->mk_marc_html($rec_id);
65 } elsif ($expand eq 'issues' and $ctx->{have_holdings_to_show}) {
66 $ctx->{expanded_holdings} =
67 $self->get_expanded_holdings($rec_id, $org, $depth);
68 } elsif ($expand eq 'cnbrowse') {
69 $self->prepare_browse_call_numbers();
73 return Apache2::Const::OK;
81 my $copy_limit = shift;
82 my $copy_offset = shift;
86 acp => ['id', 'barcode', 'circ_lib', 'create_date', 'age_protect', 'holdable'],
88 {column => 'name', alias => 'copy_location'},
89 {column => 'holdable', alias => 'location_holdable'}
92 {column => 'name', alias => 'copy_status'},
93 {column => 'holdable', alias => 'status_holdable'}
96 {column => 'label', alias => 'call_number_label'},
97 {column => 'id', alias => 'call_number'}
106 circ => {type => 'left'},
115 select => {acn => ['id']},
117 where => {record => $rec_id}
124 transform => 'actor.org_unit_descendants',
125 result_field => 'id',
129 where => {id => $org}
133 '+acn' => {deleted => 'f'},
134 '+circ' => {checkin_time => undef}
137 # Order is: copies with circ_lib=org, followed by circ_lib name, followed by call_number label
139 {class => 'aou', field => 'name'},
140 {class => 'acn', field => 'label'}
143 limit => $copy_limit,
144 offset => $copy_offset
147 # XXX In the future, $sort_org should be understood to be an abstration
148 # that refers to something configurable, not necessariyl orig_loc.
150 if (my $sort_org = $self->ctx->{orig_loc}) {
151 unshift @{$query->{order_by}}, {
152 class => 'acp', field => 'circ_lib', transform => 'numeric_eq',
153 params => [$sort_org], direction => 'desc'
157 # Filter hidden items if this is the public catalog
158 unless($self->ctx->{is_staff}) {
159 $query->{where}->{'+acp'}->{opac_visible} = 't';
160 $query->{where}->{'+acpl'}->{opac_visible} = 't';
161 $query->{where}->{'+ccs'}->{opac_visible} = 't';
165 #return $self->editor->json_query($query);
169 my($self, $rec_id) = @_;
171 # could be optimized considerably by performing the xslt on the already fetched record
172 return $U->simplereq(
174 'open-ils.search.biblio.record.html', $rec_id, 1);
177 sub get_holding_summaries {
178 my ($self, $rec_id, $org, $depth) = @_;
180 my $serial = create OpenSRF::AppSession("open-ils.serial");
181 my $result = $serial->request(
182 "open-ils.serial.bib.summary_statements",
183 $rec_id, {"org_id" => $org, "depth" => $depth}
190 sub get_expanded_holdings {
191 my ($self, $rec_id, $org, $depth) = @_;
193 my $holding_limit = int($self->cgi->param("holding_limit") || 10);
194 my $holding_offset = int($self->cgi->param("holding_offset") || 0);
195 my $type = $self->cgi->param("expand_holding_type");
197 my $serial = create OpenSRF::AppSession("open-ils.serial");
198 my $result = $serial->request(
199 "open-ils.serial.received_siss.retrieve.by_bib.atomic",
201 "ou" => $org, "depth" => $depth,
202 "limit" => $holding_limit, "offset" => $holding_offset,
211 sub any_call_number_label {
214 if ($self->ctx->{copies} and @{$self->ctx->{copies}}) {
215 return $self->ctx->{copies}->[0]->{call_number_label};
221 sub prepare_browse_call_numbers {
224 my $cn = ($self->cgi->param("cn") || $self->any_call_number_label) or
227 my $org_unit = $self->ctx->{get_aou}->($self->cgi->param('loc')) ||
228 $self->ctx->{aou_tree}->();
230 my $supercat = create OpenSRF::AppSession("open-ils.supercat");
231 my $results = $supercat->request(
232 "open-ils.supercat.call_number.browse",
233 $cn, $org_unit->shortname, 9, $self->cgi->param("cnoffset")
238 $self->ctx->{browsed_call_numbers} = [
241 (new XML::LibXML)->parse_string($_->record->marc)
246 $self->ctx->{browsing_ou} = $org_unit;
249 sub get_hold_copy_summary {
250 my ($self, $rec_id, $org) = @_;
252 my $search = OpenSRF::AppSession->create('open-ils.search');
253 my $req1 = $search->request(
254 'open-ils.search.biblio.record.copy_count', $org, $rec_id);
256 $self->ctx->{record_hold_count} = $U->simplereq(
257 'open-ils.circ', 'open-ils.circ.bre.holds.count', $rec_id);
259 $self->ctx->{copy_summary} = $req1->recv->content;