1 package OpenILS::Application::Storage::Publisher::biblio;
2 use base qw/OpenILS::Application::Storage/;
4 use OpenSRF::EX qw/:try/;
5 #use OpenILS::Application::Storage::CDBI::biblio;
6 #use OpenILS::Application::Storage::CDBI::asset;
7 use OpenILS::Utils::Fieldmapper;
11 sub record_copy_count {
17 my $cn_table = asset::call_number->table;
18 my $cp_table = asset::copy->table;
19 my $out_table = actor::org_unit_type->table;
20 my $descendants = "actor.org_unit_descendants(u.id)";
21 my $ancestors = "actor.org_unit_ancestors(?)";
29 JOIN $cp_table cp ON (cn.id = cp.call_number)
30 JOIN $descendants a ON (cp.circ_lib = a.id)
36 JOIN $cp_table cp ON (cn.id = cp.call_number)
37 JOIN $descendants a ON (cp.circ_lib = a.id)
42 JOIN $out_table t ON (u.ou_type = t.id)
46 my $sth = biblio::record_entry->db_Main->prepare_cached($sql);
47 $sth->execute(''.$args{record}, ''.$args{record}, ''.$args{org_unit});
48 while ( my $row = $sth->fetchrow_hashref ) {
49 $client->respond( $row );
53 __PACKAGE__->register_method(
54 api_name => 'open-ils.storage.biblio.record_entry.copy_count',
55 method => 'record_copy_count',
61 sub record_by_barcode {
65 my $cn_table = asset::call_number->table;
66 my $cp_table = asset::copy->table;
69 my ($r) = biblio::record_entry->db_Main->selectrow_array( <<" SQL", {}, $id );
72 JOIN $cp_table cp ON (cp.call_number = cn.id)
76 my $rec = biblio::record_entry->retrieve( $r );
78 return $rec->to_fieldmapper if ($rec);
81 __PACKAGE__->register_method(
82 api_name => 'open-ils.storage.biblio.record_entry.retrieve_by_barcode',
83 method => 'record_by_barcode',
92 my $cn_table = asset::call_number->table;
93 my $cp_table = asset::copy->table;
96 my ($r) = biblio::record_entry->db_Main->selectrow_array( <<" SQL", {}, $id );
99 JOIN $cp_table cp ON (cp.call_number = cn.id)
103 my $rec = biblio::record_entry->retrieve( $r );
104 return undef unless ($rec);
106 my $r_fm = $rec->to_fieldmapper;
107 my $ff = $rec->record_descriptor->next;
108 $r_fm->fixed_fields( $ff->to_fieldmapper ) if ($ff);
112 __PACKAGE__->register_method(
113 api_name => 'open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy',
114 method => 'record_by_copy',
123 sub record_copy_count {
129 if ($self->api_name !~ /batch/o) {
133 throw OpenSRF::EX::InvalidArg ( "No org_unit id passed!" )
136 throw OpenSRF::EX::InvalidArg ( "No record id passed!" )
139 $org_unit_lookup ||= $self->method_lookup('open-ils.storage.direct.actor.org_unit.retrieve');
140 my ($org_unit) = $org_unit_lookup->run($oid);
142 # XXX Use descendancy tree here!!!
143 my $short_name_hack = $org_unit->shortname;
144 $short_name_hack = '' if (!$org_unit->parent_ou);
145 $short_name_hack .= '%';
146 # XXX Use descendancy tree here!!!
148 my $rec_list = join(',',@recs);
150 my $cp_table = asset::copy->table;
151 my $cn_table = asset::call_number->table;
153 my $select =<<" SQL";
154 SELECT count(cp.*) as copies
156 JOIN $cp_table cp ON (cp.call_number = cn.id)
157 WHERE cn.owning_lib LIKE ? AND
158 cn.record IN ($rec_list)
161 my $sth = asset::copy->db_Main->prepare_cached($select);
162 $sth->execute($short_name_hack);
164 my $results = $sth->fetchall_hashref('record');
166 $client->respond($$results{$_}{copies} || 0) for (@recs);
170 __PACKAGE__->register_method(
171 method => 'record_copy_count',
172 api_name => 'open-ils.storage.direct.biblio.record_copy_count',
176 __PACKAGE__->register_method(
177 method => 'record_copy_count',
178 api_name => 'open-ils.storage.direct.biblio.record_copy_count.batch',
186 sub global_record_copy_count {
192 my $cn_table = asset::call_number->table;
193 my $cp_table = asset::copy->table;
194 my $cl_table = asset::copy_location->table;
195 my $cs_table = config::copy_status->table;
197 my $copies_visible = 'AND cp.opac_visible IS TRUE AND cs.holdable IS TRUE AND cl.opac_visible IS TRUE';
198 $copies_visible = '' if ($self->api_name =~ /staff/o);
202 SELECT owning_lib, sum(avail), sum(tot)
204 SELECT cn.owning_lib, count(cp.id) as avail, 0 as tot
206 JOIN $cp_table cp ON (cn.id = cp.call_number)
207 JOIN $cs_table cs ON (cs.id = cp.status)
208 JOIN $cl_table cl ON (cl.id = cp.location)
214 SELECT cn.owning_lib, 0 as avail, count(cp.id) as tot
216 JOIN $cp_table cp ON (cn.id = cp.call_number)
217 JOIN $cs_table cs ON (cs.id = cp.status)
218 JOIN $cl_table cl ON (cl.id = cp.location)
226 my $sth = biblio::record_entry->db_Main->prepare_cached($sql);
227 $sth->execute("$rec", "$rec");
229 $client->respond( $_ ) for (@{$sth->fetchall_arrayref});
232 __PACKAGE__->register_method(
233 api_name => 'open-ils.storage.biblio.record_entry.global_copy_count',
234 method => 'global_record_copy_count',
239 __PACKAGE__->register_method(
240 api_name => 'open-ils.storage.biblio.record_entry.global_copy_count.staff',
241 method => 'global_record_copy_count',
247 sub record_copy_status_count {
253 my $cn_table = asset::call_number->table;
254 my $cp_table = asset::copy->table;
255 my $cl_table = asset::copy_location->table;
256 my $cs_table = config::copy_status->table;
260 SELECT cp.circ_lib, cn.label, cp.status, count(cp.id)
266 AND cp.call_number = cn.id
267 AND cp.location = cl.id
268 AND cp.status = cs.id
269 AND cl.opac_visible IS TRUE
270 AND cp.opac_visible IS TRUE
276 my $sth = biblio::record_entry->db_Main->prepare_cached($sql);
277 $sth->execute("$rec");
279 my ($ou,$cn) = (0,'');
281 for my $row (@{$sth->fetchall_arrayref}) {
282 if ($ou and $ou ne $$row[0]) {
284 $client->respond( [$ou, $cn, {%data}] );
287 ($ou,$cn) = ($$row[0],$$row[1]);
288 $data{$$row[2]} = $$row[3];
290 return [$ou, $cn, {%data}] if ($ou);
293 __PACKAGE__->register_method(
294 api_name => 'open-ils.storage.biblio.record_entry.status_copy_count',
295 method => 'record_copy_status_count',