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