|
Lines 25-31
use Class::Inspector;
Link Here
|
| 25 |
|
25 |
|
| 26 |
use Koha::Database; |
26 |
use Koha::Database; |
| 27 |
use Koha::Exceptions::Object; |
27 |
use Koha::Exceptions::Object; |
| 28 |
use Koha::DateUtils qw( dt_from_string ); |
|
|
| 29 |
|
28 |
|
| 30 |
=head1 NAME |
29 |
=head1 NAME |
| 31 |
|
30 |
|
|
Lines 232-241
sub update {
Link Here
|
| 232 |
|
231 |
|
| 233 |
=head3 filter_by_last_update |
232 |
=head3 filter_by_last_update |
| 234 |
|
233 |
|
| 235 |
my $filtered_objects = $objects->filter_by_last_update({ |
234 |
my $filtered_objects = $objects->filter_by_last_update({ |
| 236 |
from => $date1, to => $date2, |
235 |
from => $from_datetime, to => $to_datetime, |
| 237 |
days|older_than => $days, min_days => $days, younger_than => $days, |
236 |
days|older_than => $days, min_days => $days, younger_than => $days, |
| 238 |
}); |
237 |
}); |
| 239 |
|
238 |
|
| 240 |
You should pass at least one of the parameters: from, to, days|older_than, |
239 |
You should pass at least one of the parameters: from, to, days|older_than, |
| 241 |
min_days or younger_than. Make sure that they do not conflict with each other |
240 |
min_days or younger_than. Make sure that they do not conflict with each other |
|
Lines 243-249
to get meaningful results.
Link Here
|
| 243 |
Note: from, to and min_days are inclusive! And by nature days|older_than |
242 |
Note: from, to and min_days are inclusive! And by nature days|older_than |
| 244 |
and younger_than are exclusive. |
243 |
and younger_than are exclusive. |
| 245 |
|
244 |
|
| 246 |
The from and to parameters can be DateTime objects or date strings. |
245 |
The from and to parameters must be DateTime objects. |
| 247 |
|
246 |
|
| 248 |
=cut |
247 |
=cut |
| 249 |
|
248 |
|
|
Lines 254-274
sub filter_by_last_update {
Link Here
|
| 254 |
Koha::Exceptions::MissingParameter->throw("Please pass: days|from|to|older_than|younger_than") |
253 |
Koha::Exceptions::MissingParameter->throw("Please pass: days|from|to|older_than|younger_than") |
| 255 |
unless grep { exists $params->{$_} } qw/days from to older_than younger_than min_days/; |
254 |
unless grep { exists $params->{$_} } qw/days from to older_than younger_than min_days/; |
| 256 |
|
255 |
|
|
|
256 |
foreach my $key (qw(from to)) { |
| 257 |
if (exists $params->{$key} and ref $params->{$key} ne 'DateTime') { |
| 258 |
Koha::Exceptions::WrongParameter->throw("'$key' parameter must be a DateTime object"); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 257 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
262 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 258 |
foreach my $p ( qw/days older_than younger_than min_days/ ) { |
263 |
foreach my $p ( qw/days older_than younger_than min_days/ ) { |
| 259 |
next if !exists $params->{$p}; |
264 |
next if !exists $params->{$p}; |
| 260 |
my $dt = Koha::DateUtils::dt_from_string(); |
265 |
my $days = $params->{$p}; |
| 261 |
my $operator = { days => '<', older_than => '<', min_days => '<=' }->{$p} // '>'; |
266 |
my $operator = { days => '<', older_than => '<', min_days => '<=' }->{$p} // '>'; |
| 262 |
$dt->subtract( days => $params->{$p} )->truncate( to => 'day' ); |
267 |
$conditions->{$operator} = \['DATE_SUB(CURDATE(), INTERVAL ? DAY)', $days]; |
| 263 |
$conditions->{$operator} = $dtf->format_datetime( $dt ); |
|
|
| 264 |
} |
268 |
} |
| 265 |
if ( exists $params->{from} ) { |
269 |
if ( exists $params->{from} ) { |
| 266 |
my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from}); |
270 |
$conditions->{'>='} = $dtf->format_datetime( $params->{from} ); |
| 267 |
$conditions->{'>='} = $dtf->format_datetime( $from ); |
|
|
| 268 |
} |
271 |
} |
| 269 |
if ( exists $params->{to} ) { |
272 |
if ( exists $params->{to} ) { |
| 270 |
my $to = ref($params->{to}) ? $params->{to} : dt_from_string($params->{to}); |
273 |
$conditions->{'<='} = $dtf->format_datetime( $params->{to} ); |
| 271 |
$conditions->{'<='} = $dtf->format_datetime( $to ); |
|
|
| 272 |
} |
274 |
} |
| 273 |
|
275 |
|
| 274 |
return $self->search( |
276 |
return $self->search( |