/**
  * @param FilterInterface $filter
  * @param FormInterface $form
  * @param QueryBuilder $qb
  * @param string $alias
  */
 public function handleForm(FilterInterface $filter, FormInterface $form, QueryBuilder $qb, $alias)
 {
     $data = $form->getData();
     if (!$data) {
         return;
     }
     $columns = $filter->getFullAttributeReferences($alias);
     if (!empty($data[DateRangeType::START_NAME])) {
         $startDate = $data[DateRangeType::START_NAME];
         $dql = [];
         foreach ($columns as $column) {
             $uid = uniqid('fromDate');
             $dql[] = "{$column} >= :{$uid}";
             $qb->setParameter($uid, $startDate);
         }
         $qb->andWhere(implode(' OR ', $dql));
     }
     if (!empty($data[DateRangeType::END_NAME])) {
         $endDate = $data[DateRangeType::END_NAME];
         $dql = [];
         foreach ($columns as $column) {
             $uid = uniqid('endDate');
             $dql[] = "{$column} <= :{$uid}";
             $qb->setParameter($uid, $endDate);
         }
         $qb->andWhere(implode(' OR ', $dql));
     }
 }
 /**
  * @inheritDoc
  * @throws \UnexpectedValueException
  */
 public function getFormOptions(FilterInterface $filter, QueryBuilder $qb, $alias)
 {
     if (count($filter->getAttributes()) > 1) {
         throw new \UnexpectedValueException("Autocomplete filters does not support multiple attributes ({$filter->getCode()})");
     }
     /** @var FamilyInterface $currentFamily */
     $currentFamily = $filter->getOptions()['family'];
     $attribute = $currentFamily->getAttribute(current($filter->getAttributes()));
     return ['family' => $attribute->getFormOptions()['family']];
 }
 /**
  * @param FilterInterface $filter
  * @param FormInterface   $form
  * @param QueryBuilder    $qb
  * @param string          $alias
  */
 public function handleForm(FilterInterface $filter, FormInterface $form, QueryBuilder $qb, $alias)
 {
     $data = $form->getData();
     if (!$data) {
         return;
     }
     $dql = [];
     foreach ($filter->getFullAttributeReferences($alias) as $column) {
         $uid = uniqid('text');
         $dql[] = "{$column} LIKE :{$uid}";
         $qb->setParameter($uid, '%' . $data . '%');
     }
     $qb->andWhere(implode(' OR ', $dql));
 }
 /**
  * @inheritDoc
  */
 public function getFormOptions(FilterInterface $filter, QueryBuilder $qb, $alias)
 {
     if (isset($this->formOptions['choices'])) {
         return $this->formOptions;
     }
     $choices = [];
     foreach ($filter->getFullAttributeReferences($alias) as $column) {
         $qb = clone $qb;
         $qb->select("{$column} AS __value")->groupBy($column);
         foreach ($qb->getQuery()->getArrayResult() as $result) {
             $value = $result['__value'];
             $choices[$value] = $value;
         }
     }
     return array_merge($this->formOptions, ['choices' => $choices]);
 }
 /**
  * @param FilterInterface $filter
  * @param int             $index
  * @return FilterConfigurationHandler
  * @throws UnexpectedValueException
  */
 public function addFilter(FilterInterface $filter, $index = null)
 {
     if (null === $index) {
         $this->filters[$filter->getCode()] = $filter;
     } else {
         $count = count($this->filters);
         if (!is_int($index) && !is_numeric($index)) {
             throw new UnexpectedValueException("Given index should be an integer '{$index}' given");
         }
         if (abs($index) > $count) {
             $index = 0;
         }
         if ($index < 0) {
             $index = $count + $index;
         }
         /** @noinspection AdditionOperationOnArraysInspection */
         $this->filters = array_slice($this->filters, 0, $index, true) + [$filter->getCode() => $filter] + array_slice($this->filters, $index, $count - $index, true);
     }
     return $this;
 }