From: Jeff Godin Date: Fri, 31 May 2013 15:26:47 +0000 (-0400) Subject: Add limit to penalty variant of collections call X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=692d20dca9d811a120fb8fe67c3e4cb76aba5aab;p=evergreen%2Ftadl.git 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 --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm index e5da73cbc1..64f302f4f1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm @@ -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