<?php
namespace App\Admin\Extensions\Tools;
use Encore\Admin\Grid\Filter\Between;
class TimestampBetween extends Between
{
public function condition($inputs)
{
if (!array_has($inputs, $this->column)) {
return;
}
$this->value = array_get($inputs, $this->column);
$value = array_filter($this->value, function ($val) {
return $val !== '';
});
if (empty($value)) {
return;
}
if (!isset($value['start'])) {
$value['end'] = strtotime($value['end']);
return $this->buildCondition($this->column, '<=', $value['end']);
}
if (!isset($value['end'])) {
$value['start'] = strtotime($value['start']);
return $this->buildCondition($this->column, '>=', $value['start']);
}
$this->query = 'whereBetween';
$value['end'] = strtotime($value['end']);
$value['start'] = strtotime($value['start']);
return $this->buildCondition($this->column, $value);
}
}
|