Lines 232-242
sub update {
Link Here
|
232 |
|
232 |
|
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, |
237 |
}); |
236 |
|
238 |
|
237 |
days exclusive by default (will be inclusive if days_inclusive is passed and set) |
239 |
Note: days are exclusive by default (will be inclusive if days_inclusive is passed and set). |
238 |
from inclusive |
240 |
The parameters from and to are inclusive. They can be DateTime objects or date strings. |
239 |
to inclusive |
241 |
You should pass at least one of the parameters days, from or to. |
|
|
242 |
The optional parameter datetime allows datetime comparison. |
240 |
|
243 |
|
241 |
=cut |
244 |
=cut |
242 |
|
245 |
|
Lines 252-269
sub filter_by_last_update {
Link Here
|
252 |
or exists $params->{to}; |
255 |
or exists $params->{to}; |
253 |
|
256 |
|
254 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
257 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
|
|
258 |
my $method = $params->{datetime} ? 'format_datetime' : 'format_date'; |
255 |
if ( exists $params->{days} ) { |
259 |
if ( exists $params->{days} ) { |
256 |
my $dt = Koha::DateUtils::dt_from_string(); |
260 |
my $dt = Koha::DateUtils::dt_from_string(); |
257 |
my $operator = $days_inclusive ? '<=' : '<'; |
261 |
my $operator = $days_inclusive ? '<=' : '<'; |
258 |
$conditions->{$operator} = $dtf->format_date( $dt->subtract( days => $params->{days} ) ); |
262 |
$conditions->{$operator} = $dtf->$method( $dt->subtract( days => $params->{days} ) ); |
259 |
} |
263 |
} |
260 |
if ( exists $params->{from} ) { |
264 |
if ( exists $params->{from} ) { |
261 |
my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from}); |
265 |
my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from}); |
262 |
$conditions->{'>='} = $dtf->format_date( $from ); |
266 |
$conditions->{'>='} = $dtf->$method( $from ); |
263 |
} |
267 |
} |
264 |
if ( exists $params->{to} ) { |
268 |
if ( exists $params->{to} ) { |
265 |
my $to = ref($params->{to}) ? $params->{to} : dt_from_string($params->{to}); |
269 |
my $to = ref($params->{to}) ? $params->{to} : dt_from_string($params->{to}); |
266 |
$conditions->{'<='} = $dtf->format_date( $to ); |
270 |
$conditions->{'<='} = $dtf->$method( $to ); |
267 |
} |
271 |
} |
268 |
|
272 |
|
269 |
return $self->search( |
273 |
return $self->search( |
270 |
- |
|
|