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';
14 $self->ctx->{page} = 'record';
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);
21 my $rec_id = $self->ctx->{page_args}->[0]
22 or return Apache2::Const::HTTP_BAD_REQUEST;
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));
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);
32 $self->ctx->{copies} = $copy_rec->gather(1);
33 $self->ctx->{copy_limit} = $copy_limit;
34 $self->ctx->{copy_offset} = $copy_offset;
36 return Apache2::Const::OK;
44 my $copy_limit = shift;
45 my $copy_offset = shift;
49 acp => ['id', 'barcode', 'circ_lib', 'create_date', 'age_protect', 'holdable'],
51 {column => 'name', alias => 'copy_location'},
52 {column => 'holdable', alias => 'location_holdable'}
55 {column => 'name', alias => 'copy_status'},
56 {column => 'holdable', alias => 'status_holdable'}
59 {column => 'label', alias => 'call_number_label'},
60 {column => 'id', alias => 'call_number'}
69 circ => {type => 'left'},
78 select => {acn => ['id']},
80 where => {record => $rec_id}
87 transform => 'actor.org_unit_descendants',
96 '+acn' => {deleted => 'f'},
97 '+circ' => {checkin_time => undef}
100 # Order is: copies with circ_lib=org, followed by circ_lib name, followed by call_number label
102 {class => 'aou', field => 'name'},
103 {class => 'acn', field => 'label'}
106 limit => $copy_limit,
107 offset => $copy_offset
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';
118 #return $self->editor->json_query($query);
122 my($self, $rec_id) = @_;
124 $self->ctx->{marc_html} = $U->simplereq(
125 'open-ils.search', 'open-ils.search.biblio.record.html', $rec_id);