API calls to expose the circ/hold history stored procedures
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 28 May 2010 14:19:21 +0000 (14:19 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 28 May 2010 14:19:21 +0000 (14:19 +0000)
moved circ chain summary creator code to apputils for sharing

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16529 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ.pm

index b81d5ac..3d21d50 100644 (file)
@@ -3981,5 +3981,89 @@ sub event_def_opt_in_settings {
 }
 
 
+__PACKAGE__->register_method(
+    method    => "user_visible_circs",
+    api_name  => "open-ils.actor.history.circ.visible",
+    stream => 1,
+    signature => {
+        desc   => 'Returns the set of opt-in visible circulations accompanied by circulation chain summaries',
+        params => [
+            { desc => 'Authentication token',  type => 'string'},
+            { desc => 'User ID.  If no user id is present, the authenticated user is assumed', type => 'number' },
+            { desc => 'Options hash.  Supported fields are "limit" and "offset"', type => 'object' },
+        ],
+        return => {
+            desc => q/An object with 2 fields: circulation and summary.  
+                circulation is the "circ" object.   summary is the related "accs" object/,
+            type => 'object',
+        }
+    }
+);
+
+__PACKAGE__->register_method(
+    method    => "user_visible_circs",
+    api_name  => "open-ils.actor.history.hold.visible",
+    stream => 1,
+    signature => {
+        desc   => 'Returns the set of opt-in visible holds',
+        params => [
+            { desc => 'Authentication token',  type => 'string'},
+            { desc => 'User ID.  If no user id is present, the authenticated user is assumed', type => 'number' },
+            { desc => 'Options hash.  Supported fields are "limit" and "offset"', type => 'object' },
+        ],
+        return => {
+            desc => q/An object with 1 field: "hold"/,
+            type => 'object',
+        }
+    }
+);
+
+
+sub user_visible_circs {
+    my($self, $conn, $auth, $user_id, $options) = @_;
+
+    my $is_hold = ($self->api_name =~ /hold/);
+    my $e = new_editor(authtoken => $auth);
+    return $e->event unless $e->checkauth;
+
+    $user_id ||= $e->requestor->id;
+    $options ||= {};
+    $options->{limit} ||= 50;
+    $options->{offset} ||= 0;
+
+    if($user_id != $e->requestor->id) {
+        my $perm = ($is_hold) ? 'VIEW_HOLD' : 'VIEW_CIRCULATIONS';
+        my $user = $e->retrieve_actor_user($user_id) or return $e->event;
+        return $e->event unless $e->allowed($perm, $user->home_ou);
+    }
+
+    my $db_func = ($is_hold) ? 'action.usr_visible_holds' : 'action.usr_visible_circs';
+
+    my $data = $e->json_query({
+        from => [$db_func, $user_id],
+        limit => $$options{limit},
+        offset => $$options{offset}
+
+        # TODO: I only want IDs. code below didn't get me there
+        # {"select":{"au":[{"column":"id", "result_field":"id", 
+        # "transform":"action.usr_visible_circs"}]}, "where":{"id":10}, "from":"au"}
+    });
+
+    foreach (@$data) {
+        my $id = $_->{id};
+        if($is_hold) {
+            $conn->respond({hold => $e->retrieve_action_hold_request($id)});
+        } else {
+            $conn->respond({
+                circ => $e->retrieve_action_circulation($id),
+                summary => $U->create_circ_chain_summary($e, $id)
+            });
+        }
+    }
+
+    return undef;
+}
+
+
 
 1;
index 97f04b2..d9165f8 100644 (file)
@@ -1676,5 +1676,14 @@ sub create_uuid_string {
     return create_UUID_as_string();
 }
 
+sub create_circ_chain_summary {
+    my($class, $e, $circ_id) = @_;
+    my $sum = $e->json_query({from => ['action.summarize_circ_chain', $circ_id]})->[0];
+    return undef unless $sum;
+    my $obj = Fieldmapper::action::circ_chain_summary->new;
+    $obj->$_($sum->{$_}) for keys %$sum;
+    return $obj;
+}
+
 1;
 
index bd25981..16bd62e 100644 (file)
@@ -1476,11 +1476,7 @@ sub retrieve_circ_chain {
        return $e->event unless $e->allowed('VIEW_CIRCULATIONS');
 
     if($self->api_name =~ /summary/) {
-        my $sum = $e->json_query({from => ['action.summarize_circ_chain', $circ_id]})->[0];
-        return undef unless $sum;
-        my $obj = Fieldmapper::action::circ_chain_summary->new;
-        $obj->$_($sum->{$_}) for keys %$sum;
-        return $obj;
+        return $U->create_circ_chain_summary($e, $circ_id);
 
     } else {