[open-ils-commits] r16529 - trunk/Open-ILS/src/perlmods/OpenILS/Application (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri May 28 10:19:24 EDT 2010
Author: erickson
Date: 2010-05-28 10:19:21 -0400 (Fri, 28 May 2010)
New Revision: 16529
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
Log:
API calls to expose the circ/hold history stored procedures
moved circ chain summary creator code to apputils for sharing
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2010-05-28 13:25:47 UTC (rev 16528)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2010-05-28 14:19:21 UTC (rev 16529)
@@ -3981,5 +3981,89 @@
}
+__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;
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2010-05-28 13:25:47 UTC (rev 16528)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2010-05-28 14:19:21 UTC (rev 16529)
@@ -1676,5 +1676,14 @@
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;
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm 2010-05-28 13:25:47 UTC (rev 16528)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm 2010-05-28 14:19:21 UTC (rev 16529)
@@ -1476,11 +1476,7 @@
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 {
More information about the open-ils-commits
mailing list