[open-ils-commits] r16307 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Apr 26 14:14:35 EDT 2010


Author: erickson
Date: 2010-04-26 14:14:31 -0400 (Mon, 26 Apr 2010)
New Revision: 16307

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
Log:
Added API call to return the total hold count for titles and metarecords

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm	2010-04-26 17:14:44 UTC (rev 16306)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm	2010-04-26 18:14:31 UTC (rev 16307)
@@ -2550,4 +2550,134 @@
 }
 
 
+__PACKAGE__->register_method(
+    method    => 'rec_hold_count',
+    api_name  => 'open-ils.circ.bre.holds.count',
+    signature => {
+        desc => q/Returns the total number of holds that target the 
+            selected bib record or its associated copies and call_numbers/,
+        params => [
+            { desc => 'Bib ID', type => 'number' },
+        ],
+        return => {desc => 'Hold count', type => 'number'}
+    }
+);
+
+__PACKAGE__->register_method(
+    method    => 'rec_hold_count',
+    api_name  => 'open-ils.circ.mmr.holds.count',
+    signature => {
+        desc => q/Returns the total number of holds that target the 
+            selected metarecord or its associated copies, call_numbers, and bib records/,
+        params => [
+            { desc => 'Metarecord ID', type => 'number' },
+        ],
+        return => {desc => 'Hold count', type => 'number'}
+    }
+);
+
+sub rec_hold_count {
+    my($self, $conn, $target_id) = @_;
+
+
+    my $mmr_join = {
+        mmrsm => {
+            field => 'id',
+            fkey => 'source',
+            filter => {metarecord => $target_id}
+        }
+    };
+
+    my $bre_join = {
+        bre => {
+            field => 'id',
+            filter => { id => $target_id },
+            fkey => 'record'
+        }
+    };
+
+    if($self->api_name =~ /mmr/) {
+        delete $bre_join->{bre}->{filter};
+        $bre_join->{bre}->{join} = $mmr_join;
+    }
+
+    my $cn_join = {
+        acn => {
+            field => 'id',
+            fkey => 'call_number',
+            join => $bre_join
+        }
+    };
+
+    my $query = {
+        select => {ahr => [{column => 'id', transform => 'count', alias => 'count'}]},
+        from => 'ahr',
+        where => {
+            '+ahr' => {
+                cancel_time => undef, 
+                fulfillment_time => undef,
+                '-or' => [
+                    {
+                        '-and' => {
+                            hold_type => 'C',
+                            target => {
+                                in => {
+                                    select => {acp => ['id']},
+                                    from => { acp => $cn_join }
+                                }
+                            }
+                        }
+                    },
+                    {
+                        '-and' => {
+                            hold_type => 'V',
+                            target => {
+                                in => {
+                                    select => {acn => ['id']},
+                                    from => {acn => $bre_join}
+                                }
+                            }
+                        }
+                    },
+                    {
+                        '-and' => {
+                            hold_type => 'T',
+                            target => $target_id
+                        }
+                    }
+                ]
+            }
+        }
+    };
+
+    if($self->api_name =~ /mmr/) {
+        $query->{where}->{'+ahr'}->{'-or'}->[2] = {
+            '-and' => {
+                hold_type => 'T',
+                target => {
+                    in => {
+                        select => {bre => ['id']},
+                        from => {bre => $mmr_join}
+                    }
+                }
+            }
+        };
+
+        $query->{where}->{'+ahr'}->{'-or'}->[3] = {
+            '-and' => {
+                hold_type => 'M',
+                target => $target_id
+            }
+        };
+    }
+
+
+    return new_editor()->json_query($query)->[0]->{count};
+}
+
+
+
+
+
+
 1;



More information about the open-ils-commits mailing list