From 3ba8a2a5d0edd5e6fbf3529ffa1740089fa60d5d Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 7 Oct 2024 19:38:29 +0000 Subject: [PATCH] - Fixed 'value' for SearchRequestOrderBy and also fixed a typo where SearchManual would not be set --- src/Entity/Field/Datetime.php | 16 ++++++++++++---- .../SearchRequestFromRequestTrait.php | 9 +++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Entity/Field/Datetime.php b/src/Entity/Field/Datetime.php index e5c3a5e..b11f673 100644 --- a/src/Entity/Field/Datetime.php +++ b/src/Entity/Field/Datetime.php @@ -12,12 +12,20 @@ class Datetime extends \DateTime implements EntityObjectInterface { { $value = $arguments[0]; - # From Timestamp - if ( is_numeric($value) ) { - return new static("@$value"); + try { + # From Timestamp + if ( is_numeric($value) ) { + $obj = new static("@$value"); + } + else { + $obj = new static($value); + } + } + catch(\Throwable $ex) { + throw new \Exception(sprintf("An error occured trying to instanciate from '%s'. %s", $value, $ex->getMessage()), $ex->getCode(), $ex); } - return new static($value); + return $obj; } public function save() diff --git a/src/SearchRequest/SearchRequestFromRequestTrait.php b/src/SearchRequest/SearchRequestFromRequestTrait.php index 3bbe2f9..9f150b8 100644 --- a/src/SearchRequest/SearchRequestFromRequestTrait.php +++ b/src/SearchRequest/SearchRequestFromRequestTrait.php @@ -60,6 +60,8 @@ trait SearchRequestFromRequestTrait $field = $fieldName; } + $value = $this->getValueFromSource($request, $propertyName, $attribute); + switch(true) { case $attribute instanceof SearchGroupBy: $this->parseAttributeGroupBy($attribute, $field, $propertyName); @@ -67,14 +69,13 @@ trait SearchRequestFromRequestTrait case $attribute instanceof SearchWhere: case $attribute instanceof SearchLike: - case $attribute instanceof SearchManuel: - - $value = $this->getValueFromSource($request, $propertyName, $attribute); - + case $attribute instanceof SearchManual: if ($value !== null) { $value = $this->transformValue($property->getAttributes(Attribute\PropertyValueModifier::class), $value); } + dump($value); + if ($attribute->toggle) { $this->$propertyName = !empty($value); } elseif ($value !== null) {