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 $copy_rec = OpenSRF::AppSession->create('open-ils.cstore')->request(
28 'open-ils.cstore.json_query.atomic',
29 $self->mk_copy_query($rec_id, $org, $depth, $copy_limit, $copy_offset));
31 my (undef, @rec_data) = $self->get_records_and_facets([$rec_id], undef, {flesh => '{holdings_xml,mra}'});
32 $ctx->{bre_id} = $rec_data[0]->{id};
33 $ctx->{marc_xml} = $rec_data[0]->{marc_xml};
35 $ctx->{copies} = $copy_rec->gather(1);
36 $ctx->{copy_limit} = $copy_limit;
37 $ctx->{copy_offset} = $copy_offset;
39 $ctx->{have_holdings_to_show} = 0;
40 $self->get_hold_copy_summary($rec_id, $org);
42 # XXX TODO we'll also need conditional logic to show MFHD-based holdings
44 $ctx->{get_org_setting}->
45 ($org, "opac.fully_compressed_serial_holdings")
47 $ctx->{holding_summaries} =
48 $self->get_holding_summaries($rec_id, $org, $depth);
50 $ctx->{have_holdings_to_show} =
51 scalar(@{$ctx->{holding_summaries}->{basic}}) ||
52 scalar(@{$ctx->{holding_summaries}->{index}}) ||
53 scalar(@{$ctx->{holding_summaries}->{supplement}});
56 # XXX probably should replace the following with a dispatch table
57 for my $expand ($self->cgi->param('expand')) {
58 $ctx->{"expand_$expand"} = 1;
59 if ($expand eq 'marchtml') {
60 $ctx->{marchtml} = $self->mk_marc_html($rec_id);
61 } elsif ($expand eq 'issues' and $ctx->{have_holdings_to_show}) {
62 $ctx->{expanded_holdings} =
63 $self->get_expanded_holdings($rec_id, $org, $depth);
64 } elsif ($expand eq 'cnbrowse') {
65 $ctx->{browsed_call_numbers} = $self->browse_call_numbers();
70 return Apache2::Const::OK;
78 my $copy_limit = shift;
79 my $copy_offset = shift;
83 acp => ['id', 'barcode', 'circ_lib', 'create_date', 'age_protect', 'holdable'],
85 {column => 'name', alias => 'copy_location'},
86 {column => 'holdable', alias => 'location_holdable'}
89 {column => 'name', alias => 'copy_status'},
90 {column => 'holdable', alias => 'status_holdable'}
93 {column => 'label', alias => 'call_number_label'},
94 {column => 'id', alias => 'call_number'}
103 circ => {type => 'left'},
112 select => {acn => ['id']},
114 where => {record => $rec_id}
121 transform => 'actor.org_unit_descendants',
122 result_field => 'id',
126 where => {id => $org}
130 '+acn' => {deleted => 'f'},
131 '+circ' => {checkin_time => undef}
134 # Order is: copies with circ_lib=org, followed by circ_lib name, followed by call_number label
136 {class => 'aou', field => 'name'},
137 {class => 'acn', field => 'label'}
140 limit => $copy_limit,
141 offset => $copy_offset
144 # Filter hidden items if this is the public catalog
145 unless($self->ctx->{is_staff}) {
146 $query->{where}->{'+acp'}->{opac_visible} = 't';
147 $query->{where}->{'+acpl'}->{opac_visible} = 't';
148 $query->{where}->{'+ccs'}->{opac_visible} = 't';
152 #return $self->editor->json_query($query);
156 my($self, $rec_id) = @_;
158 # could be optimized considerably by performing the xslt on the already fetched record
159 return $U->simplereq(
161 'open-ils.search.biblio.record.html', $rec_id, 1);
164 sub get_holding_summaries {
165 my ($self, $rec_id, $org, $depth) = @_;
168 create OpenSRF::AppSession("open-ils.serial")->request(
169 "open-ils.serial.bib.summary_statements",
170 $rec_id, {"org_id" => $org, "depth" => $depth}
175 sub get_expanded_holdings {
176 my ($self, $rec_id, $org, $depth) = @_;
178 my $holding_limit = int($self->cgi->param("holding_limit") || 10);
179 my $holding_offset = int($self->cgi->param("holding_offset") || 0);
180 my $type = $self->cgi->param("expand_holding_type");
182 return create OpenSRF::AppSession("open-ils.serial")->request(
183 "open-ils.serial.received_siss.retrieve.by_bib.atomic",
185 "ou" => $org, "depth" => $depth,
186 "limit" => $holding_limit, "offset" => $holding_offset,
192 sub any_call_number_label {
195 if ($self->ctx->{copies} and @{$self->ctx->{copies}}) {
196 return $self->ctx->{copies}->[0]->{call_number_label};
202 sub browse_call_numbers {
205 my $cn = $self->any_call_number_label or
208 my $org_unit = $self->ctx->{get_aou}->($self->cgi->param('loc')) ||
209 $self->ctx->{aou_tree}->();
211 my $supercat = create OpenSRF::AppSession("open-ils.supercat");
212 my $results = $supercat->request(
213 "open-ils.supercat.call_number.browse",
214 $cn, $org_unit->shortname, 9, $self->cgi->param("cnoffset")
220 (new XML::LibXML)->parse_string($_->record->marc)
227 sub get_hold_copy_summary {
228 my ($self, $rec_id, $org) = @_;
230 my $req1 = OpenSRF::AppSession->create('open-ils.search')->request(
231 'open-ils.search.biblio.record.copy_count', $org, $rec_id);
233 $self->ctx->{record_hold_count} = $U->simplereq(
234 'open-ils.circ', 'open-ils.circ.bre.holds.count', $rec_id);
236 $self->ctx->{copy_summary} = $req1->recv->content;