From 730d20dc2d496e4377b166819076809da7868898 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 28 Jun 2005 20:52:33 +0000 Subject: [PATCH] order records of a metarecord by format,copycount git-svn-id: svn://svn.open-ils.org/ILS/trunk@956 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Storage/Publisher/metabib.pm | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm index 5313304c1c..e5af5036cc 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm @@ -13,6 +13,91 @@ my $log = 'OpenSRF::Utils::Logger'; $VERSION = 1; +# need to order record IDs by: +# 1) format - text, movie, sound, software, images, maps, mixed, music, 3d +# 2) proximity --- XXX Can't do it cheap... +# 3) count +sub ordered_records_from_metarecord { + my $self = shift; + my $client = shift; + my $mr = shift; + + my $copies_visible = 'AND cp.opac_visible IS TRUE'; + $copies_visible = '' if ($self->api_name =~ /staff/o); + + my $sm_table = metabib::metarecord_source_map->table; + my $rd_table = metabib::record_descriptor->table; + my $cn_table = asset::call_number->table; + my $cp_table = asset::copy->table; + my $out_table = actor::org_unit_type->table; + + my $sql = <<" SQL"; + SELECT cn.record, + rd.item_type, + sum((SELECT count(cp.id) + FROM $cp_table cp + WHERE cn.id = cp.call_number + $copies_visible + )) AS count + FROM $cn_table cn, + $sm_table sm, + $rd_table rd + WHERE cn.record = sm.source + AND cn.record = rd.record + AND sm.metarecord = ? + GROUP BY cn.record, rd.item_type + ORDER BY + CASE + WHEN rd.item_type IS NULL -- default + THEN 0 + WHEN rd.item_type = '' -- default + THEN 0 + WHEN rd.item_type IN ('a','t') -- books + THEN 1 + WHEN rd.item_type = 'g' -- movies + THEN 2 + WHEN rd.item_type IN ('i','j') -- sound recordings + THEN 3 + WHEN rd.item_type = 'm' -- software + THEN 4 + WHEN rd.item_type = 'k' -- images + THEN 5 + WHEN rd.item_type IN ('e','f') -- maps + THEN 6 + WHEN rd.item_type IN ('o','p') -- mixed + THEN 7 + WHEN rd.item_type IN ('c','d') -- music + THEN 8 + WHEN rd.item_type = 'r' -- 3d + THEN 9 + END, + count DESC + SQL + + my $sth = metabib::metarecord_source_map->db_Main->prepare_cached($sql); + $sth->execute("$mr"); + while ( my $row = $sth->fetchrow_arrayref ) { + $client->respond( $$row[0] ); + } + return undef; + +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.ordered.metabib.metarecord.records', + method => 'ordered_records_from_metarecord', + api_level => 1, + stream => 1, + cachable => 1, +); +__PACKAGE__->register_method( + api_name => 'open-ils.storage.ordered.metabib.metarecord.records.staff', + method => 'ordered_records_from_metarecord', + api_level => 1, + stream => 1, + cachable => 1, +); + + sub metarecord_copy_count { my $self = shift; my $client = shift; -- 2.11.0