]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm
tons of storage server changes... see diffs
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / biblio.pm
1 package OpenILS::Application::Storage::Publisher::biblio;
2 use base qw/OpenILS::Application::Storage/;
3 use vars qw/$VERSION/;
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;
8
9 $VERSION = 1;
10
11 my $org_unit_lookup;
12 sub record_copy_count {
13         my $self = shift;
14         my $client = shift;
15         my $oid = shift;
16         my @recs = @_;
17
18         if ($self->api_name !~ /batch/o) {
19                 @recs = ($recs[0]);
20         }
21
22         throw OpenSRF::EX::InvalidArg ( "No org_unit id passed!" )
23                 unless ($oid);
24
25         throw OpenSRF::EX::InvalidArg ( "No record id passed!" )
26                 unless (@recs);
27
28         $org_unit_lookup ||= $self->method_lookup('open-ils.storage.direct.actor.org_unit.retrieve');
29         my ($org_unit) = $org_unit_lookup->run($oid);
30
31         # XXX Use descendancy tree here!!!
32         my $short_name_hack = $org_unit->shortname;
33         $short_name_hack = '' if (!$org_unit->parent_ou);
34         $short_name_hack .= '%';
35         # XXX Use descendancy tree here!!!
36
37         my $rec_list = join(',',@recs);
38
39         my $cp_table = asset::copy->table;
40         my $cn_table = asset::call_number->table;
41
42         my $select =<<" SQL";
43                 SELECT  cn.record as record, count(cp.*) as copies
44                   FROM  $cn_table cn
45                         JOIN $cp_table cp ON (cp.call_number = cn.id)
46                   WHERE cn.owning_lib LIKE ? AND
47                         cn.record IN ($rec_list)
48                   GROUP BY cn.record
49         SQL
50
51         my $sth = asset::copy->db_Main->prepare_cached($select);
52         $sth->execute($short_name_hack);
53
54         my $results = $sth->fetchall_hashref('record');
55
56         $client->respond($$results{$_}{copies} || 0) for (@recs);
57
58         return undef;
59 }
60 __PACKAGE__->register_method(
61         method          => 'record_copy_count',
62         api_name        => 'open-ils.storage.direct.biblio.record_copy_count',
63         api_level       => 1,
64         argc            => 1,
65 );
66 __PACKAGE__->register_method(
67         method          => 'record_copy_count',
68         api_name        => 'open-ils.storage.direct.biblio.record_copy_count.batch',
69         api_level       => 1,
70         argc            => 1,
71         stream          => 1,
72 );
73
74 1;