Add limit to penalty variant of collections call user/jeff/collections_limit_and_order
authorJeff Godin <jgodin@tadl.org>
Fri, 31 May 2013 16:09:23 +0000 (12:09 -0400)
committerJeff Godin <jgodin@tadl.org>
Fri, 31 May 2013 16:09:23 +0000 (12:09 -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 8d61327..ba56f4e 100644 (file)
@@ -161,6 +161,14 @@ __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"/,
             }
         ],
 
@@ -188,7 +196,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);
 
@@ -254,6 +262,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