Add option addFieldFilter([]) to the QueryBuilder
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
4de01cfcb8
commit
b400c08211
5 changed files with 63 additions and 9 deletions
|
|
@ -2,22 +2,49 @@
|
|||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Exception\FunctionInvalidInputException;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||
|
||||
class Filter extends Base
|
||||
{
|
||||
/**
|
||||
* @var KeyValue $keyValue
|
||||
* @var mixed $filter
|
||||
*/
|
||||
private $keyValue;
|
||||
private $filter;
|
||||
|
||||
public function __construct(KeyValue $keyValue)
|
||||
public function __construct($filter)
|
||||
{
|
||||
$this->keyValue = $keyValue;
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> filter(fn: (r) => ' . $this->keyValue . ') ';
|
||||
return '|> filter(fn: (r) => ' . $this->format() . ') ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FunctionInvalidInputException
|
||||
*/
|
||||
protected function format(): string
|
||||
{
|
||||
if ($this->filter instanceof KeyValue) {
|
||||
return $this->filter->__toString();
|
||||
} elseif (is_array($this->filter)) {
|
||||
$filterCounter = 0;
|
||||
$filterString = '';
|
||||
foreach ($this->filter as $filter) {
|
||||
if ($filterCounter > 0) {
|
||||
$filterString .= ' or ';
|
||||
}
|
||||
|
||||
$filterString .= 'r._field == "' . $filter . '"';
|
||||
|
||||
$filterCounter++;
|
||||
}
|
||||
|
||||
return $filterString;
|
||||
}
|
||||
|
||||
throw new FunctionInvalidInputException('Filter input is incorrect.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue