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',
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 return biblio::record_entry->retrieve( $r )->to_fieldmapper;
78 __PACKAGE__->register_method(
79 api_name => 'open-ils.storage.biblio.record_entry.retrieve_by_copy',
80 method => 'record_by_copy',
88 sub record_copy_count {
94 if ($self->api_name !~ /batch/o) {
98 throw OpenSRF::EX::InvalidArg ( "No org_unit id passed!" )
101 throw OpenSRF::EX::InvalidArg ( "No record id passed!" )
104 $org_unit_lookup ||= $self->method_lookup('open-ils.storage.direct.actor.org_unit.retrieve');
105 my ($org_unit) = $org_unit_lookup->run($oid);
107 # XXX Use descendancy tree here!!!
108 my $short_name_hack = $org_unit->shortname;
109 $short_name_hack = '' if (!$org_unit->parent_ou);
110 $short_name_hack .= '%';
111 # XXX Use descendancy tree here!!!
113 my $rec_list = join(',',@recs);
115 my $cp_table = asset::copy->table;
116 my $cn_table = asset::call_number->table;
118 my $select =<<" SQL";
119 SELECT count(cp.*) as copies
121 JOIN $cp_table cp ON (cp.call_number = cn.id)
122 WHERE cn.owning_lib LIKE ? AND
123 cn.record IN ($rec_list)
126 my $sth = asset::copy->db_Main->prepare_cached($select);
127 $sth->execute($short_name_hack);
129 my $results = $sth->fetchall_hashref('record');
131 $client->respond($$results{$_}{copies} || 0) for (@recs);
135 __PACKAGE__->register_method(
136 method => 'record_copy_count',
137 api_name => 'open-ils.storage.direct.biblio.record_copy_count',
141 __PACKAGE__->register_method(
142 method => 'record_copy_count',
143 api_name => 'open-ils.storage.direct.biblio.record_copy_count.batch',