- Added some SearchRequest attributes ; now it's even simpler to add searchable fields
- Began decoupling of QueryBuilder from native MySQL method ; some works needs to be done on for the Repository object splitting also.
This commit is contained in:
1 parent
15be1597b8
commit
4571517dc8
30 files changed
+1007
-615
No files matched your search
+15
-47
@@ -4,19 +4,16 @@ namespace Ulmus;
|
||||
|
||||
use Notes\Attribute\Ignore;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\{Common\EntityResolver,
|
||||
Common\EntityField,
|
||||
Entity\EntityInterface,
|
||||
Query\QueryBuilderInterface,
|
||||
SearchRequest\SearchRequestInterface,
|
||||
SearchRequest\SearchRequestPaginationTrait};
|
||||
use Ulmus\{Common\EntityResolver, Common\EntityField, Entity\EntityInterface, Query\QueryBuilderInterface};
|
||||
use Ulmus\SearchRequest\{Attribute\SearchParameter,
|
||||
SearchMethodEnum,
|
||||
SearchRequestInterface,
|
||||
SearchRequestFromRequestTrait,
|
||||
SearchRequestPaginationTrait};
|
||||
|
||||
trait EntityTrait {
|
||||
use EventTrait;
|
||||
|
||||
#[Ignore]
|
||||
public string $loadedFromAdapter;
|
||||
|
||||
#[Ignore]
|
||||
protected bool $entityStrictFieldsDeclaration = false;
|
||||
|
||||
@@ -327,6 +324,7 @@ trait EntityTrait {
|
||||
#[Ignore]
|
||||
public static function field($name, null|string|false $alias = Repository::DEFAULT_ALIAS) : EntityField
|
||||
{
|
||||
|
||||
$default = ( $alias === false ? '' : Repository::DEFAULT_ALIAS ); # bw compatibility, to be deprecated
|
||||
|
||||
return new EntityField(static::class, $name, $alias ? Ulmus::repository(static::class)->adapter->adapter()->escapeIdentifier($alias, Adapter\AdapterInterface::IDENTIFIER_FIELD) : $default, Ulmus::resolveEntity(static::class));
|
||||
@@ -343,47 +341,17 @@ trait EntityTrait {
|
||||
#[Ignore]
|
||||
public static function searchRequest(...$arguments) : SearchRequestInterface
|
||||
{
|
||||
return new class() implements SearchRequestInterface, \JsonSerializable
|
||||
{
|
||||
use SearchRequestPaginationTrait;
|
||||
return new #[SearchRequest\Attribute\SearchRequestParameter(self::class)] class(... $arguments) extends SearchRequest\SearchRequest {
|
||||
# Define searchable properties here, some ex:
|
||||
|
||||
public function fromRequest(ServerRequestInterface $request) : self
|
||||
{
|
||||
$get = new \ArrayObject(array_filter($request->getQueryParams(), function($i) { return $i !== ""; }));
|
||||
# #[SearchParameter(method: SearchMethodEnum::Where)]
|
||||
# public ? string $username = null;
|
||||
|
||||
$this->page = $get->offsetExists('page') ? $get['page'] : 1;
|
||||
$this->limit = 100;
|
||||
# #[SearchParameter(method: SearchMethodEnum::Where, toggle: true)]
|
||||
# public ? string $hidden = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filter(Repository $repository) : Repository
|
||||
{
|
||||
return $repository;
|
||||
}
|
||||
|
||||
public function wheres() : iterable
|
||||
{
|
||||
return array_filter([
|
||||
], fn($i) => ! is_null($i) ) + [ ];
|
||||
}
|
||||
|
||||
public function likes(): iterable
|
||||
{
|
||||
return array_filter([
|
||||
], fn($i) => ! is_null($i) ) + [];
|
||||
}
|
||||
|
||||
public function groups(): iterable
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function orders(): iterable
|
||||
{
|
||||
return array_filter([
|
||||
], fn($e) => ! is_null($e) && $e !== "" );
|
||||
}
|
||||
# #[SearchParameter(method: SearchMethodEnum::Like)]
|
||||
# public ? string $word = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user