Lines 233-249
sub update {
Link Here
|
233 |
=head3 filter_by_last_update |
233 |
=head3 filter_by_last_update |
234 |
|
234 |
|
235 |
my $filtered_objects = $objects->filter_by_last_update({ |
235 |
my $filtered_objects = $objects->filter_by_last_update({ |
236 |
days => $days, from => $date1, to => $date2, days_inclusive => 1, |
236 |
from => $date1, to => $date2, |
237 |
older_than => $days, younger_than => $days, |
237 |
days|older_than => $days, min_days => $days, younger_than => $days, |
238 |
datetime => 1, |
238 |
datetime => 1, |
239 |
}); |
239 |
}); |
240 |
|
240 |
|
241 |
You should pass at least one of the parameters: days, from, to, older_than, |
241 |
You should pass at least one of the parameters: from, to, days|older_than, |
242 |
younger_than. Make sure that they do not conflict with each other to get |
242 |
min_days or younger_than. Make sure that they do not conflict with each other |
243 |
meaningful results. |
243 |
to get meaningful results. |
244 |
By default, from and to are inclusive and days is exclusive (unless you |
244 |
Note: from, to and min_days are inclusive! And by nature days|older_than |
245 |
passed the optional days_inclusive parameter). |
245 |
and younger_than are exclusive. |
246 |
By nature older_than and younger_than are exclusive. This cannot be changed. |
|
|
247 |
The optional parameter datetime allows datetime comparison. |
246 |
The optional parameter datetime allows datetime comparison. |
248 |
|
247 |
|
249 |
The from and to parameters can be DateTime objects or date strings. |
248 |
The from and to parameters can be DateTime objects or date strings. |
Lines 253-273
The from and to parameters can be DateTime objects or date strings.
Link Here
|
253 |
sub filter_by_last_update { |
252 |
sub filter_by_last_update { |
254 |
my ( $self, $params ) = @_; |
253 |
my ( $self, $params ) = @_; |
255 |
my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp'; |
254 |
my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp'; |
256 |
my $days_inclusive = $params->{days_inclusive} || 0; |
|
|
257 |
my $conditions; |
255 |
my $conditions; |
258 |
Koha::Exceptions::MissingParameter->throw("Please pass: days|from|to|older_than|younger_than") |
256 |
Koha::Exceptions::MissingParameter->throw("Please pass: days|from|to|older_than|younger_than") |
259 |
unless grep { exists $params->{$_} } qw/days from to older_than younger_than/; |
257 |
unless grep { exists $params->{$_} } qw/days from to older_than younger_than min_days/; |
260 |
|
258 |
|
261 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
259 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
262 |
my $method = $params->{datetime} ? 'format_datetime' : 'format_date'; |
260 |
my $method = $params->{datetime} ? 'format_datetime' : 'format_date'; |
263 |
foreach my $p ( qw/days older_than younger_than/ ) { |
261 |
foreach my $p ( qw/days older_than younger_than min_days/ ) { |
264 |
next if !exists $params->{$p}; |
262 |
next if !exists $params->{$p}; |
265 |
my $dt = Koha::DateUtils::dt_from_string(); |
263 |
my $dt = Koha::DateUtils::dt_from_string(); |
266 |
my $operator = $p eq 'days' && $days_inclusive |
264 |
my $operator = { days => '<', older_than => '<', min_days => '<=' }->{$p} // '>'; |
267 |
? '<=' |
|
|
268 |
: $p eq 'younger_than' |
269 |
? '>' |
270 |
: '<'; |
271 |
$conditions->{$operator} = $dtf->$method( $dt->subtract( days => $params->{$p} ) ); |
265 |
$conditions->{$operator} = $dtf->$method( $dt->subtract( days => $params->{$p} ) ); |
272 |
} |
266 |
} |
273 |
if ( exists $params->{from} ) { |
267 |
if ( exists $params->{from} ) { |