Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datetime filter with empty input #1717

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/Table/Column/FilterModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Atk4\Data\Field;
use Atk4\Data\Model;
use Atk4\Data\Persistence;
use Atk4\Data\Types\Types as CustomTypes;
use Doctrine\DBAL\Types\Types;

/**
* Implement a generic filter model for filtering column data.
Expand Down Expand Up @@ -52,13 +54,25 @@ class FilterModel extends Model
public static function factoryType(Field $field): self
{
$persistence = new Persistence\Array_();
$filterDomain = self::class . '\\Type';

// check if field as a type and use string as default
if (empty($type = $field->type)) {
$type = 'string';
}
$class = $filterDomain . ucfirst($type);
$class = [
Types::STRING => FilterModel\TypeString::class,
Types::TEXT => FilterModel\TypeString::class,

Types::BOOLEAN => FilterModel\TypeBoolean::class,
Types::INTEGER => FilterModel\TypeNumber::class,
Types::FLOAT => FilterModel\TypeNumber::class,
CustomTypes::MONEY => FilterModel\TypeNumber::class,

Types::DATE_MUTABLE => FilterModel\TypeDate::class,
Types::DATE_IMMUTABLE => FilterModel\TypeDate::class,
Types::TIME_MUTABLE => FilterModel\TypeTime::class,
Types::TIME_IMMUTABLE => FilterModel\TypeTime::class,
Types::DATETIME_MUTABLE => FilterModel\TypeDatetime::class,
Types::DATETIME_IMMUTABLE => FilterModel\TypeDatetime::class,

'TODO we do not support enum type, any type can be enum' => FilterModel\TypeEnum::class,
][$field->type ?? 'string'];

/*
* You can set your own filter model condition by extending
Expand Down
2 changes: 1 addition & 1 deletion src/Table/Column/FilterModel/TypeDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function getDate($dateModifier)

break;
default:
$date = new DateTime($dateModifier);
$date = ($dateModifier ? new DateTime($dateModifier) : null);

break;
}
Expand Down
9 changes: 0 additions & 9 deletions src/Table/Column/FilterModel/TypeInteger.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Table/Column/FilterModel/TypeMoney.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Table/Column/FilterModel/TypeText.php

This file was deleted.