From b67d76ba069f4f3498cb8cb77de84e5a2f71baf9 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 28 Jun 2005 20:52:08 +0000 Subject: [PATCH] get locations with copies, and the counts thereof git-svn-id: svn://svn.open-ils.org/ILS/trunk@955 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Storage/Publisher/biblio.pm | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm index 8995e2fcc8..13eab203bd 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm @@ -180,4 +180,59 @@ __PACKAGE__->register_method( =cut +sub global_record_copy_count { + my $self = shift; + my $client = shift; + + my $rec = shift; + + my $cn_table = asset::call_number->table; + my $cp_table = asset::copy->table; + + my $copies_visible = 'AND cp.opac_visible IS TRUE'; + $copies_visible = '' if ($self->api_name =~ /staff/o); + + my $sql = <<" SQL"; + + SELECT owning_lib, sum(avail), sum(tot) + FROM ( + SELECT owning_lib, count(cp.id) as avail, 0 as tot + FROM $cn_table cn + JOIN $cp_table cp ON (cn.id = cp.call_number) + WHERE cn.record = ? + AND cp.status = 0 + $copies_visible + GROUP BY 1 + UNION + SELECT owning_lib, 0 as avail, count(cp.id) as tot + FROM $cn_table cn + JOIN $cp_table cp ON (cn.id = cp.call_number) + WHERE cn.record = ? + $copies_visible + GROUP BY 1 + ) x + GROUP BY 1 + SQL + + my $sth = biblio::record_entry->db_Main->prepare_cached($sql); + $sth->execute("$rec", "$rec"); + + $client->respond( $_ ) for (@{$sth->fetchall_arrayref}); + return undef; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.biblio.record_entry.global_copy_count', + method => 'global_record_copy_count', + api_level => 1, + stream => 1, + cachable => 1, +); +__PACKAGE__->register_method( + api_name => 'open-ils.storage.biblio.record_entry.global_copy_count.staff', + method => 'global_record_copy_count', + api_level => 1, + stream => 1, + cachable => 1, +); + 1; -- 2.11.0