Add limit to penalty variant of collections call
authorJeff Godin <jgodin@tadl.org>
Fri, 31 May 2013 15:26:47 +0000 (11:26 -0400)
committerJeff Godin <jgodin@tadl.org>
Fri, 31 May 2013 15:26:47 +0000 (11:26 -0400)
Add a limit and sort order param to the API method
open-ils.collections.users_of_interest.warning_penalty.retrieve

When a limit is supplied, users are sorted by set_date (default
DESC, for most recently set). Supplying "ASC" as a param will sort
by oldest.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm

index e5da73c..64f302f 100644 (file)
@@ -156,7 +156,15 @@ __PACKAGE__->register_method(
                 name => 'max_age',
                                desc => q/Optional.  Maximum age of the penalty application/,
                                type => q/interval, e.g "90 days"/,
-                       }
+                       }, {
+                name => 'limit',
+                               desc => q/Optional.  Return a maximum of this many users/,
+                               type => q/integer/,
+                       }, {
+                name => 'sort',
+                               desc => q/Optional.  Sort by penalty set_time, asc or desc, defaults to desc/,
+                               type => q/string, "asc" or "desc"/,
+            }
                ],
 
                'return' => { 
@@ -183,7 +191,7 @@ __PACKAGE__->register_method(
 
 
 sub users_of_interest_warning_penalty {
-    my( $self, $conn, $auth, $location, $min_age, $max_age ) = @_;
+    my( $self, $conn, $auth, $location, $min_age, $max_age, $limit, $sort ) = @_;
 
     return OpenILS::Event->new('BAD_PARAMS') unless ($auth and $location);
 
@@ -240,6 +248,14 @@ sub users_of_interest_warning_penalty {
     push(@{$query->{where}->{'-and'}}, {set_date => {'>' => $max_set_date}}) if $max_set_date;
     push(@{$query->{where}->{'-and'}}, {set_date => {'<' => $min_set_date}}) if $min_set_date;
 
+    if ($limit) {
+        $query->{limit} = $limit;
+        my $sort_order = $sort || "DESC";
+        $query->{order_by} = [
+            {class => 'ausp', field => 'set_date', direction => $sort_order}
+        ];
+    }
+
     my $req = $ses->request('open-ils.cstore.json_query', $query);
 
     # let the client know we're still here