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 $self->get_staff_search_settings;
26 if ($ctx->{staff_saved_search_size}) {
27 $ctx->{saved_searches} = ($self->staff_load_searches)[1];
30 # run copy retrieval in parallel to bib retrieval
32 my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
33 my $copy_rec = $cstore->request(
34 'open-ils.cstore.json_query.atomic',
35 $self->mk_copy_query($rec_id, $org, $depth, $copy_limit, $copy_offset)
38 my (undef, @rec_data) = $self->get_records_and_facets([$rec_id], undef, {flesh => '{holdings_xml,mra,acp}'});
39 $ctx->{bre_id} = $rec_data[0]->{id};
40 $ctx->{marc_xml} = $rec_data[0]->{marc_xml};
42 $ctx->{copies} = $copy_rec->gather(1);
43 $ctx->{copy_limit} = $copy_limit;
44 $ctx->{copy_offset} = $copy_offset;
46 $ctx->{have_holdings_to_show} = 0;
47 $self->get_hold_copy_summary($rec_id, $org);
51 # XXX TODO we'll also need conditional logic to show MFHD-based holdings
53 $ctx->{get_org_setting}->
54 ($org, "opac.fully_compressed_serial_holdings")
56 $ctx->{holding_summaries} =
57 $self->get_holding_summaries($rec_id, $org, $depth);
59 $ctx->{have_holdings_to_show} =
60 scalar(@{$ctx->{holding_summaries}->{basic}}) ||
61 scalar(@{$ctx->{holding_summaries}->{index}}) ||
62 scalar(@{$ctx->{holding_summaries}->{supplement}});
67 $ctx->{marchtml} = $self->mk_marc_html($rec_id);
70 $ctx->{expanded_holdings} =
71 $self->get_expanded_holdings($rec_id, $org, $depth)
72 if $ctx->{have_holdings_to_show};
75 $self->prepare_browse_call_numbers();
79 my @expand = $self->cgi->param('expand');
80 if (grep {$_ eq 'all'} @expand) {
81 $ctx->{expand_all} = 1;
82 $expandies{$_}->() for keys %expandies;
85 for my $exp (@expand) {
86 $ctx->{"expand_$exp"} = 1;
87 $expandies{$exp}->() if exists $expandies{$exp};
91 return Apache2::Const::OK;
99 my $copy_limit = shift;
100 my $copy_offset = shift;
104 acp => ['id', 'barcode', 'circ_lib', 'create_date', 'age_protect', 'holdable'],
106 {column => 'name', alias => 'copy_location'},
107 {column => 'holdable', alias => 'location_holdable'}
110 {column => 'name', alias => 'copy_status'},
111 {column => 'holdable', alias => 'status_holdable'}
114 {column => 'label', alias => 'call_number_label'},
115 {column => 'id', alias => 'call_number'}
117 circ => ['due_date'],
123 join => {bre => {filter => {id => $rec_id }}},
124 filter => {deleted => 'f'}
126 circ => { # If the copy is circulating, retrieve the open circ
128 filter => {checkin_time => undef}
136 where => {'+acp' => {deleted => 'f' }},
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 if($org != $self->ctx->{aou_tree}->()->id) {
158 # no need to add the org join filter if we're not actually filtering
159 $query->{from}->{acp}->{aou} = {
167 transform => 'actor.org_unit_descendants',
168 result_field => 'id',
172 where => {id => $org}
179 # Filter hidden items if this is the public catalog
180 unless($self->ctx->{is_staff}) {
181 $query->{where}->{'+acp'}->{opac_visible} = 't';
182 $query->{from}->{'acp'}->{'acpl'}->{filter} = {opac_visible => 't'};
183 $query->{from}->{'acp'}->{'ccs'}->{filter} = {opac_visible => 't'};
190 my($self, $rec_id) = @_;
192 # could be optimized considerably by performing the xslt on the already fetched record
193 return $U->simplereq(
195 'open-ils.search.biblio.record.html', $rec_id, 1);
198 sub get_holding_summaries {
199 my ($self, $rec_id, $org, $depth) = @_;
201 my $serial = create OpenSRF::AppSession("open-ils.serial");
202 my $result = $serial->request(
203 "open-ils.serial.bib.summary_statements",
204 $rec_id, {"org_id" => $org, "depth" => $depth}
211 sub get_expanded_holdings {
212 my ($self, $rec_id, $org, $depth) = @_;
214 my $holding_limit = int($self->cgi->param("holding_limit") || 10);
215 my $holding_offset = int($self->cgi->param("holding_offset") || 0);
216 my $type = $self->cgi->param("expand_holding_type");
218 my $serial = create OpenSRF::AppSession("open-ils.serial");
219 my $result = $serial->request(
220 "open-ils.serial.received_siss.retrieve.by_bib.atomic",
222 "ou" => $org, "depth" => $depth,
223 "limit" => $holding_limit, "offset" => $holding_offset,
232 sub any_call_number_label {
235 if ($self->ctx->{copies} and @{$self->ctx->{copies}}) {
236 return $self->ctx->{copies}->[0]->{call_number_label};
242 sub prepare_browse_call_numbers {
245 my $cn = ($self->cgi->param("cn") || $self->any_call_number_label) or
248 my $org_unit = $self->ctx->{get_aou}->($self->cgi->param('loc')) ||
249 $self->ctx->{aou_tree}->();
251 my $supercat = create OpenSRF::AppSession("open-ils.supercat");
252 my $results = $supercat->request(
253 "open-ils.supercat.call_number.browse",
254 $cn, $org_unit->shortname, 9, $self->cgi->param("cnoffset")
259 $self->ctx->{browsed_call_numbers} = [
262 (new XML::LibXML)->parse_string($_->record->marc)
267 $self->ctx->{browsing_ou} = $org_unit;
270 sub get_hold_copy_summary {
271 my ($self, $rec_id, $org) = @_;
273 my $search = OpenSRF::AppSession->create('open-ils.search');
274 my $req1 = $search->request(
275 'open-ils.search.biblio.record.copy_count', $org, $rec_id);
277 $self->ctx->{record_hold_count} = $U->simplereq(
278 'open-ils.circ', 'open-ils.circ.bre.holds.count', $rec_id);
280 $self->ctx->{copy_summary} = $req1->recv->content;