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 $ctx->{have_mfhd_to_show} = 0;
48 $self->get_hold_copy_summary($rec_id, $org);
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}});
64 $ctx->{mfhd_summaries} =
65 $self->get_mfhd_summaries($rec_id, $org, $depth);
67 if ($ctx->{mfhd_summaries} && scalar(@{$ctx->{mfhd_summaries}})
69 $ctx->{have_mfhd_to_show} = 1;
75 $ctx->{marchtml} = $self->mk_marc_html($rec_id);
78 $ctx->{expanded_holdings} =
79 $self->get_expanded_holdings($rec_id, $org, $depth)
80 if $ctx->{have_holdings_to_show};
83 $self->prepare_browse_call_numbers();
87 my @expand = $self->cgi->param('expand');
88 if (grep {$_ eq 'all'} @expand) {
89 $ctx->{expand_all} = 1;
90 $expandies{$_}->() for keys %expandies;
93 for my $exp (@expand) {
94 $ctx->{"expand_$exp"} = 1;
95 $expandies{$exp}->() if exists $expandies{$exp};
99 return Apache2::Const::OK;
107 my $copy_limit = shift;
108 my $copy_offset = shift;
112 acp => ['id', 'barcode', 'circ_lib', 'create_date', 'age_protect', 'holdable'],
114 {column => 'name', alias => 'copy_location'},
115 {column => 'holdable', alias => 'location_holdable'}
118 {column => 'name', alias => 'copy_status'},
119 {column => 'holdable', alias => 'status_holdable'}
122 {column => 'label', alias => 'call_number_label'},
123 {column => 'id', alias => 'call_number'}
125 circ => ['due_date'],
131 join => {bre => {filter => {id => $rec_id }}},
132 filter => {deleted => 'f'}
134 circ => { # If the copy is circulating, retrieve the open circ
136 filter => {checkin_time => undef}
144 where => {'+acp' => {deleted => 'f' }},
147 {class => 'aou', field => 'name'},
148 {class => 'acn', field => 'label'}
151 limit => $copy_limit,
152 offset => $copy_offset
155 # XXX In the future, $sort_org should be understood to be an abstration
156 # that refers to something configurable, not necessariyl orig_loc.
158 if (my $sort_org = $self->ctx->{orig_loc}) {
159 unshift @{$query->{order_by}}, {
160 class => 'acp', field => 'circ_lib', transform => 'numeric_eq',
161 params => [$sort_org], direction => 'desc'
165 if($org != $self->ctx->{aou_tree}->()->id) {
166 # no need to add the org join filter if we're not actually filtering
167 $query->{from}->{acp}->{aou} = {
175 transform => 'actor.org_unit_descendants',
176 result_field => 'id',
180 where => {id => $org}
187 # Filter hidden items if this is the public catalog
188 unless($self->ctx->{is_staff}) {
189 $query->{where}->{'+acp'}->{opac_visible} = 't';
190 $query->{from}->{'acp'}->{'acpl'}->{filter} = {opac_visible => 't'};
191 $query->{from}->{'acp'}->{'ccs'}->{filter} = {opac_visible => 't'};
198 my($self, $rec_id) = @_;
200 # could be optimized considerably by performing the xslt on the already fetched record
201 return $U->simplereq(
203 'open-ils.search.biblio.record.html', $rec_id, 1);
206 sub get_holding_summaries {
207 my ($self, $rec_id, $org, $depth) = @_;
209 my $serial = create OpenSRF::AppSession("open-ils.serial");
210 my $result = $serial->request(
211 "open-ils.serial.bib.summary_statements",
212 $rec_id, {"org_id" => $org, "depth" => $depth}
219 sub get_mfhd_summaries {
220 my ($self, $rec_id, $org, $depth) = @_;
222 # XXX TODO Filter results on OU / depth before returning
223 # Perhaps in a modified form of the osrf method, rather than here
224 my $serial = create OpenSRF::AppSession("open-ils.search");
225 my $result = $serial->request(
226 "open-ils.search.serial.record.bib.retrieve",
234 sub get_expanded_holdings {
235 my ($self, $rec_id, $org, $depth) = @_;
237 my $holding_limit = int($self->cgi->param("holding_limit") || 10);
238 my $holding_offset = int($self->cgi->param("holding_offset") || 0);
239 my $type = $self->cgi->param("expand_holding_type");
241 my $serial = create OpenSRF::AppSession("open-ils.serial");
242 my $result = $serial->request(
243 "open-ils.serial.received_siss.retrieve.by_bib.atomic",
245 "ou" => $org, "depth" => $depth,
246 "limit" => $holding_limit, "offset" => $holding_offset,
255 sub any_call_number_label {
258 if ($self->ctx->{copies} and @{$self->ctx->{copies}}) {
259 return $self->ctx->{copies}->[0]->{call_number_label};
265 sub prepare_browse_call_numbers {
268 my $cn = ($self->cgi->param("cn") || $self->any_call_number_label) or
271 my $org_unit = $self->ctx->{get_aou}->($self->cgi->param('loc')) ||
272 $self->ctx->{aou_tree}->();
274 my $supercat = create OpenSRF::AppSession("open-ils.supercat");
275 my $results = $supercat->request(
276 "open-ils.supercat.call_number.browse",
277 $cn, $org_unit->shortname, 9, $self->cgi->param("cnoffset")
282 $self->ctx->{browsed_call_numbers} = [
285 (new XML::LibXML)->parse_string($_->record->marc)
290 $self->ctx->{browsing_ou} = $org_unit;
293 sub get_hold_copy_summary {
294 my ($self, $rec_id, $org) = @_;
296 my $search = OpenSRF::AppSession->create('open-ils.search');
297 my $req1 = $search->request(
298 'open-ils.search.biblio.record.copy_count', $org, $rec_id);
300 $self->ctx->{record_hold_count} = $U->simplereq(
301 'open-ils.circ', 'open-ils.circ.bre.holds.count', $rec_id);
303 $self->ctx->{copy_summary} = $req1->recv->content;