- Work done on search request mostly
This commit is contained in:
parent
f938e18572
commit
7b35de3258
@ -103,7 +103,8 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
|||||||
|
|
||||||
if ( is_a($type, Entity\Field\Date::class, true) || is_a($type, Entity\Field\Time::class, true) || is_a($type, \DateTime::class, true) ) {
|
if ( is_a($type, Entity\Field\Date::class, true) || is_a($type, Entity\Field\Time::class, true) || is_a($type, \DateTime::class, true) ) {
|
||||||
$type = "TEXT";
|
$type = "TEXT";
|
||||||
$length = strlen((string) $type);
|
|
||||||
|
#$length = strlen((string) $type);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
switch($type) {
|
switch($type) {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use Ulmus\Query;
|
|||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
|
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
|
||||||
class Where {
|
class Where {
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string|\Stringable|array $field,
|
public string|\Stringable|array $field,
|
||||||
public mixed $value = null,
|
public mixed $value = null,
|
||||||
@ -21,18 +22,23 @@ class Where {
|
|||||||
|
|
||||||
public function getValue(/* null|EntityInterface */ $entity = null) : mixed
|
public function getValue(/* null|EntityInterface */ $entity = null) : mixed
|
||||||
{
|
{
|
||||||
if ($this->generateValue) {
|
if ($entity) {
|
||||||
if ($entity) {
|
if ($this->generateValue) {
|
||||||
return call_user_func_array($this->generateValue, [ $entity ]);
|
return call_user_func_array($this->generateValue, [ $entity ]);
|
||||||
}
|
}
|
||||||
else {
|
elseif ($this->fieldValue) {
|
||||||
|
throw new \Exception(sprintf("Field value, from %s, could not be included in query since the entity is already loaded; it is meant to be used with a OneToOne relation loaded within a join.", (string) $this->fieldValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ($this->fieldValue) {
|
||||||
|
return $this->fieldValue;
|
||||||
|
}
|
||||||
|
elseif ($this->generateValue) {
|
||||||
throw new \Exception(sprintf("Could not generate value from non-instanciated entity for field %s.", (string) $this->field));
|
throw new \Exception(sprintf("Could not generate value from non-instanciated entity for field %s.", (string) $this->field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($this->fieldValue && $entity) {
|
|
||||||
throw new \Exception(sprintf("Field value, from %s, could not be included in query since the entity is already loaded; it is meant to be used with a OneToOne relation loaded within a join.", (string) $this->fieldValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->fieldValue ?? $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,7 +95,7 @@ class EntityResolver {
|
|||||||
return $fieldList;
|
return $fieldList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function relation(string $name) : array
|
public function relation(string $name, bool $throwOnError = true) : ? array
|
||||||
{
|
{
|
||||||
$property = $this->reflectedClass->getProperties(true)[$name] ?? false;
|
$property = $this->reflectedClass->getProperties(true)[$name] ?? false;
|
||||||
|
|
||||||
@ -111,8 +111,10 @@ class EntityResolver {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
catch(\Throwable $e) {
|
catch(\Throwable $e) {
|
||||||
throw new \InvalidArgumentException("Can't find entity relation's column named `$name` from entity {$this->entityClass}");
|
$throwOnError && throw new \InvalidArgumentException("Can't find entity relation's column named `$name` from entity {$this->entityClass}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPropertyHavingAttribute(array|object|string $type) : array
|
public function getPropertyHavingAttribute(array|object|string $type) : array
|
||||||
|
|||||||
@ -258,10 +258,11 @@ trait EntityTrait {
|
|||||||
$dataset = [];
|
$dataset = [];
|
||||||
|
|
||||||
foreach($this->entityYieldDataset($objectAttribute->includeRelations ?? true, false, false) as $key => $value) {
|
foreach($this->entityYieldDataset($objectAttribute->includeRelations ?? true, false, false) as $key => $value) {
|
||||||
$field = $resolver->searchField($key, EntityResolver::KEY_COLUMN_NAME);
|
$field = $resolver->searchField($key, EntityResolver::KEY_COLUMN_NAME); # ?: $resolver->relation($key, false);
|
||||||
|
|
||||||
if ($field) {
|
if ($field) {
|
||||||
$jsonSerialize = $field->getAttribute(\Ulmus\Attribute\Property\JsonSerialize::class);
|
$jsonSerialize = $field->getAttribute(\Ulmus\Attribute\Property\JsonSerialize::class);
|
||||||
|
|
||||||
if ($jsonSerialize) {
|
if ($jsonSerialize) {
|
||||||
# Should we ignore the field ?
|
# Should we ignore the field ?
|
||||||
if ($jsonSerialize->object->ignoreField) {
|
if ($jsonSerialize->object->ignoreField) {
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
namespace Ulmus\SearchRequest\Attribute;
|
namespace Ulmus\SearchRequest\Attribute;
|
||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
|
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
|
||||||
abstract class PropertyValueModifier
|
class PropertyValueModifier
|
||||||
{
|
{
|
||||||
public abstract function run(mixed $value) : mixed;
|
public abstract function run(mixed $value) : mixed;
|
||||||
}
|
}
|
||||||
@ -5,7 +5,7 @@ namespace Ulmus\SearchRequest\Attribute;
|
|||||||
use Ulmus\SearchRequest\SearchMethodEnum;
|
use Ulmus\SearchRequest\SearchMethodEnum;
|
||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
||||||
abstract class SearchParameter {
|
class SearchParameter {
|
||||||
|
|
||||||
public PropertyValueSource|array $source = PropertyValueSource::QueryParams;
|
public PropertyValueSource|array $source = PropertyValueSource::QueryParams;
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,9 @@ trait SearchRequestFromRequestTrait
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SearchMethodEnum::OrderBy:
|
case SearchMethodEnum::OrderBy:
|
||||||
$repository->orderBy($param->field, $param->value());
|
$value = $param->value();
|
||||||
|
|
||||||
|
$repository->orderBy($param->field, $value instanceof \BackedEnum ? $value->value : $value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SearchMethodEnum::GroupBy:
|
case SearchMethodEnum::GroupBy:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user