From 6b948c81f943f666b3e31b0a9e19764979e72502 Mon Sep 17 00:00:00 2001 From: Jeff Godin Date: Fri, 31 May 2013 11:26:47 -0400 Subject: [PATCH] Add limit to penalty variant of collections call 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 Conflicts: Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm --- .../perlmods/lib/OpenILS/Application/Collections.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm index 750468c22e..c66daba113 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm @@ -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 -- 2.11.0