Merge remote-tracking branch 'origin' into dev-sql-escape

This commit is contained in:
Dave Mc Nicoll committed 2020-04-09 10:00:48 -04:00
commit def8decb4e
18 files changed
+246 -26

No files matched your search

+98 -6
View File
@@ -214,6 +214,32 @@ class Repository
return $this;
}
public function wheres(array $fieldValues, string $operator = Query\Where::OPERATOR_EQUAL) : self
{
foreach($fieldValues as $field => $value) {
if ( is_array($value) ) {
switch ($value[1]) {
case Query\Where::CONDITION_AND:
$this->where($field, $value[0], $operator);
break;
case Query\Where::CONDITION_OR:
$this->or($field, $value[0], $operator);
break;
case Query\Where::CONDITION_NOT:
$this->notWhere($field, $value[0], $operator);
break;
}
}
else {
$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);
@@ -233,9 +259,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->where($field, $value, $operator, Query\Where::CONDITION_OR, true);
$this->queryBuilder->notWhere($field, $value, $operator, Query\Where::CONDITION_OR, true);
return $this;
}
@@ -296,18 +322,51 @@ class Repository
public function like($field, $value) : self
{
$this->queryBuilder->where($field, $value, Query\Where::OPERATOR_LIKE, Query\Where::CONDITION_AND);
$this->where($field, $value, Query\Where::OPERATOR_LIKE);
return $this;
}
public function orLike($field, $value) : self
{
$this->or($field, $value, Query\Where::OPERATOR_LIKE);
return $this;
}
public function notLike($field, $value) : self
{
$this->queryBuilder->where($field, $value, Query\Where::OPERATOR_LIKE, Query\Where::CONDITION_AND, true);
$this->notWhere($field, $value, Query\Where::OPERATOR_LIKE);
return $this;
}
public function likes(array $fieldValues, string $condition = Query\Where::CONDITION_AND) : self
{
foreach($fieldValues as $field => $value) {
if ( is_array($value) ) {
switch ($value[1]) {
case Query\Where::CONDITION_AND:
$this->like($field, $value[0]);
break;
case Query\Where::CONDITION_OR:
$this->orLike($field, $value[0]);
break;
case Query\Where::CONDITION_NOT:
$this->notLike($field, $value[0]);
break;
}
}
else {
$this->like($field, $value);
}
}
return $this;
}
public function match() : self
{
@@ -330,10 +389,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);
@@ -341,6 +405,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);
@@ -375,7 +449,25 @@ class Repository
return $this->where($primaryKeyField[$pkField]->name ?? $pkField, $value);
}
public function filterServerRequest(SearchRequest\SearchRequestInterface $searchRequest) : self
{
$searchRequest->count = $searchRequest->filter( clone $this )
->wheres($searchRequest->wheres(), Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
->likes($searchRequest->likes(), Query\Where::CONDITION_OR)
->orders($searchRequest->orders())
->groups($searchRequest->groups())
->count();
return $searchRequest->filter($this)
->wheres($searchRequest->wheres(), Query\Where::OPERATOR_EQUAL, Query\Where::CONDITION_AND)
->likes($searchRequest->likes(), Query\Where::CONDITION_OR)
->orders($searchRequest->orders())
->groups($searchRequest->groups())
->offset($searchRequest->offset())
->limit($searchRequest->limit());
}
public function collectionFromQuery(? string $entityClass = null) : EntityCollection
{