- Multiple bugfixe linked to query fragments
- Added a new SearchRequest package to handle search request efficiently
This commit is contained in:
1 parent
4b29232543
commit
938639a590
15 files changed
+148
-27
No files matched your search
+56
-11
@@ -53,15 +53,11 @@ class Repository
|
||||
|
||||
public function count() : int
|
||||
{
|
||||
$this->select("count(*) as totalItem")->selectSqlQuery();
|
||||
$this->select("count(*)")->selectSqlQuery();
|
||||
|
||||
$this->finalizeQuery();
|
||||
|
||||
foreach(Ulmus::iterateQueryBuilder($this->queryBuilder, $this->adapter) as $entityData) {
|
||||
return $entityData['totalItem'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
return Ulmus::runQuery($this->queryBuilder, $this->adapter)->fetchColumn(0);
|
||||
}
|
||||
|
||||
public function deleteOne()
|
||||
@@ -218,6 +214,15 @@ class Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function wheres(array $fieldValues, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
||||
{
|
||||
foreach($fieldValues as $field => $value) {
|
||||
$this->where($field, $value, $operator);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function and($field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
||||
{
|
||||
return $this->where($field, $value, $operator);
|
||||
@@ -237,9 +242,9 @@ class Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orNot($field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
||||
public function orNot($field, $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self
|
||||
{
|
||||
$this->queryBuilder->notWhere($condition, Query\Where::CONDITION_OR, true);
|
||||
$this->queryBuilder->notWhere($field, $value, $operator, Query\Where::CONDITION_OR, true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -289,11 +294,21 @@ class Repository
|
||||
|
||||
public function notLike($field, $value) : self
|
||||
{
|
||||
$this->queryBuilder->where($field, $value, Query\Where::OPERATOR_LIKE, Query\Where::CONDITION_AND, true);
|
||||
$this->queryBuilder->notWhere($field, $value, Query\Where::OPERATOR_LIKE, Query\Where::CONDITION_AND, true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function likes(array $fieldValues) : self
|
||||
{
|
||||
foreach($fieldValues as $field => $value) {
|
||||
$this->like($field, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function match() : self
|
||||
{
|
||||
|
||||
@@ -316,10 +331,15 @@ class Repository
|
||||
|
||||
public function groupBy() : self
|
||||
{
|
||||
#$this->queryBuilder->groupBy();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function groups(array $groups) : self
|
||||
{
|
||||
# foreach($this->groups)
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orderBy($field, ? string $direction = null) : self
|
||||
{
|
||||
$this->queryBuilder->orderBy($field, $direction);
|
||||
@@ -327,6 +347,16 @@ class Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orders(array $orderList) : self
|
||||
{
|
||||
foreach($orderList as $field => $direction) {
|
||||
$this->queryBuilder->orderBy($field, $direction);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function limit(int $value) : self
|
||||
{
|
||||
$this->queryBuilder->limit($value);
|
||||
@@ -362,9 +392,24 @@ class Repository
|
||||
return $this->where($primaryKeyField[$pkField]->name ?? $pkField, $value);
|
||||
}
|
||||
|
||||
public function filterServerRequest(SearchRequest\SearchRequestInterface $searchRequest) : self
|
||||
{
|
||||
$searchRequest->count = (clone $this)->wheres($searchRequest->wheres())
|
||||
->likes($searchRequest->likes())
|
||||
->orders($searchRequest->orders())
|
||||
->groups($searchRequest->groups())
|
||||
->count();
|
||||
|
||||
return $this->wheres($searchRequest->wheres())
|
||||
->likes($searchRequest->likes())
|
||||
->orders($searchRequest->orders())
|
||||
->groups($searchRequest->groups())
|
||||
->offset($searchRequest->offset())
|
||||
->limit($searchRequest->limit());
|
||||
}
|
||||
|
||||
protected function collectionFromQuery() : EntityCollection
|
||||
{
|
||||
|
||||
$class = $this->entityClass;
|
||||
|
||||
$entityCollection = new EntityCollection();
|
||||
|
||||
Reference in new issue
Block a user