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)
34 JOIN $out_table t ON (u.ou_type = t.id)
38 my $sth = biblio::record_entry->db_Main->prepare_cached($sql);
39 $sth->execute(''.$args{record}, ''.$args{org_unit});
40 while ( my $row = $sth->fetchrow_hashref ) {
41 $client->respond( $row );
45 __PACKAGE__->register_method(
46 api_name => 'open-ils.storage.biblio.record_entry.copy_count',
47 method => 'record_copy_count',
57 sub record_copy_count {
63 if ($self->api_name !~ /batch/o) {
67 throw OpenSRF::EX::InvalidArg ( "No org_unit id passed!" )
70 throw OpenSRF::EX::InvalidArg ( "No record id passed!" )
73 $org_unit_lookup ||= $self->method_lookup('open-ils.storage.direct.actor.org_unit.retrieve');
74 my ($org_unit) = $org_unit_lookup->run($oid);
76 # XXX Use descendancy tree here!!!
77 my $short_name_hack = $org_unit->shortname;
78 $short_name_hack = '' if (!$org_unit->parent_ou);
79 $short_name_hack .= '%';
80 # XXX Use descendancy tree here!!!
82 my $rec_list = join(',',@recs);
84 my $cp_table = asset::copy->table;
85 my $cn_table = asset::call_number->table;
88 SELECT count(cp.*) as copies
90 JOIN $cp_table cp ON (cp.call_number = cn.id)
91 WHERE cn.owning_lib LIKE ? AND
92 cn.record IN ($rec_list)
95 my $sth = asset::copy->db_Main->prepare_cached($select);
96 $sth->execute($short_name_hack);
98 my $results = $sth->fetchall_hashref('record');
100 $client->respond($$results{$_}{copies} || 0) for (@recs);
104 __PACKAGE__->register_method(
105 method => 'record_copy_count',
106 api_name => 'open-ils.storage.direct.biblio.record_copy_count',
110 __PACKAGE__->register_method(
111 method => 'record_copy_count',
112 api_name => 'open-ils.storage.direct.biblio.record_copy_count.batch',