Commit 6c947852 authored by Pavel's avatar Pavel
Browse files

filter type

parent eec91f2b
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -8,11 +8,14 @@ class FilterGroupCollection extends AbstractCollection
{
    /** @var LogicOperator Тип логической операции для коллекции */
    protected LogicOperator $type;
    /** @var FilterType Тип фильтра для коллекции */
    protected FilterType $filterType;

    public function __construct(array $data = [])
    {
        parent::__construct($data);
        $this->type = new LogicOperator(LogicOperator::AND);
        $this->filterType = new FilterType(FilterType::FILTER);
    }

    /**
@@ -46,4 +49,28 @@ class FilterGroupCollection extends AbstractCollection
    {
        return $this->type;
    }

    /**
     * Установка типа фильтрации
     *
     * @param FilterType $type
     *
     * @return $this
     */
    public function setFilterType(FilterType $type): self
    {
        $this->filterType = $type;

        return $this;
    }

    /**
     * Получение типа фильтрации
     *
     * @return FilterType
     */
    public function getFilterType(): FilterType
    {
        return $this->filterType;
    }
}
+41 −0
Original line number Diff line number Diff line
<?php

namespace IQDEV\Search\Filter;

final class FilterType
{
    /**
     * Тип пост фильтрации по свойствам
     */
    public const FILTER = 'filter';
    /**
     * Тип полной фильтрации
     */
    public const QUERY = 'query';
    private string $operator;

    public function __construct(string $operator)
    {
        if (!in_array($operator, self::toArray(), true)) {
            throw new \InvalidArgumentException(sprintf('invalid operator %s', $operator));
        }

        $this->operator = $operator;
    }

    public function value(): string
    {
        return $this->operator;
    }

    /**
     * @return string[]
     */
    public static function toArray(): array
    {
        return [
            self::FILTER,
            self::QUERY
        ];
    }
}