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

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Sep 30 16:04:31 EDT 2009


Author: erickson
Date: 2009-09-30 16:04:26 -0400 (Wed, 30 Sep 2009)
New Revision: 14234

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
Log:
added API call that, given a circulation, will return all circulations in the renewal chain for that circ

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm	2009-09-30 19:46:22 UTC (rev 14233)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm	2009-09-30 20:04:26 UTC (rev 14234)
@@ -1283,6 +1283,61 @@
 }
 
 
+__PACKAGE__->register_method(
+	method	=> "retrieve_circ_chain",
+	api_name	=> "open-ils.circ.renewal_chain.retrieve_by_circ",
+    stream => 1,
+	signature => {
+        desc => q/Given a circulation, this returns all circulation objects
+                that are part of the same chain of renewals./,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'Circ ID', type => 'number'},
+        ],
+        return => {desc => q/List of circ objects, orderd by oldest circ first/}
+    }
+);
+
+sub retrieve_circ_chain {
+    my($self, $conn, $auth, $circ_id) = @_;
+
+    my $e = new_editor(authtoken => $auth);
+    return $e->event unless $e->checkauth;
+
+    # grab the base circ and all parent (previous) circs by fleshing
+    my $base_circ = $e->retrieve_action_circulation([
+        $circ_id,
+        {
+            flesh => -1,
+            flesh_fields => {circ => ['parent_circ']}
+        }
+    ]) or return $e->event;
+
+    return $e->event unless $e->allowed('VIEW_CIRCULATIONS', $base_circ->circ_lib);
+
+    # send each circ to the caller, starting with the oldest circulation
+    my @chain;
+    my $circ = $base_circ;
+    while($circ) {
+        push(@chain, $circ);
+
+        # unflesh for consistency
+        my $parent = $circ->parent_circ;
+        $circ->parent_circ($parent->id) if $parent; 
+
+        $circ = $parent;
+    }
+    $conn->respond($_) for reverse(@chain);
+
+    # base circ may not be the end of the chain.  see if there are any subsequent circs
+    $circ = $base_circ;
+    $conn->respond($circ) while ($circ = $e->search_action_circulation({parent_circ => $circ->id})->[0]);
+
+    return undef;
+}
+
+
+
 # {"select":{"acp":["id"],"circ":[{"aggregate":true,"transform":"count","alias":"count","column":"id"}]},"from":{"acp":{"circ":{"field":"target_copy","fkey":"id","type":"left"},"acn"{"field":"id","fkey":"call_number"}}},"where":{"+acn":{"record":200057}}
 
 



More information about the open-ils-commits mailing list