51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace KupShop\GraphQLBundle\ApiShared\Util;
|
|
|
|
use KupShop\GraphQLBundle\ApiAdmin\Types\DateFilterInput;
|
|
use KupShop\GraphQLBundle\ApiAdmin\Types\Parameters;
|
|
use KupShop\GraphQLBundle\ApiShared\ApiUtil;
|
|
use KupShop\GraphQLBundle\ApiShared\Query\ApiQuery;
|
|
use Query\Operator;
|
|
use Query\QueryBuilder;
|
|
|
|
class ParametersAssembler
|
|
{
|
|
/**
|
|
* @param Parameters $inputFilter UserFilterInput [Factory]
|
|
* @param Parameters $inputSort UserSortInput [Factory]
|
|
*/
|
|
public function assemblyInput(?Parameters $inputFilter, ?Parameters $inputSort, ?int $offset, ?int $limit, QueryBuilder &$qb)
|
|
{
|
|
foreach ((!empty($inputFilter) ? $inputFilter->getData() : []) as $field => $value) {
|
|
if (!($value ?? false)) {
|
|
continue;
|
|
}
|
|
|
|
if (is_callable($value)) {
|
|
$qb->andWhere($value);
|
|
}
|
|
|
|
if (is_array($value)) {
|
|
$qb->andWhere(Operator::inStringArray($value, $field));
|
|
}
|
|
|
|
if ($value instanceof DateFilterInput) {
|
|
$qb->andWhere(ApiUtil::getDateTimeFilter($value, $field));
|
|
}
|
|
|
|
if (is_string($value) || is_numeric($value)) {
|
|
$qb->andWhere(Operator::equals([$field => $value]));
|
|
}
|
|
}
|
|
|
|
foreach ((!empty($inputSort) ? $inputSort->getData() : []) as $key => $value) {
|
|
if ($value ?? false) {
|
|
$qb->addOrderBy($key, $value->value);
|
|
}
|
|
}
|
|
|
|
$qb->andWhere(ApiQuery::limit($limit, $offset));
|
|
}
|
|
}
|