/** * Check if value is valid * * @param string $field * @param mixed $values */ protected function checkValue($field, $values) { FieldFilterHelper::checkArray($field, $values, FieldFilterHelper::getCode($field)); foreach ($values as $value) { FieldFilterHelper::checkIdentifier($field, $value, FieldFilterHelper::getCode($field)); } }
/** * {@inheritdoc} */ public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = []) { if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) { $this->checkValue($field, $value); if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) { $value = $this->objectIdResolver->getIdsFromCodes('family', $value); } } $rootAlias = $this->qb->getRootAlias(); $entityAlias = $this->getUniqueAlias('filter' . FieldFilterHelper::getCode($field)); $this->qb->leftJoin($rootAlias . '.' . FieldFilterHelper::getCode($field), $entityAlias); switch ($operator) { case Operators::IN_LIST: $this->qb->andWhere($this->qb->expr()->in($entityAlias . '.id', $value)); break; case Operators::NOT_IN_LIST: $this->qb->andWhere($this->qb->expr()->orX($this->qb->expr()->notIn($entityAlias . '.id', $value), $this->qb->expr()->isNull($entityAlias . '.id'))); break; case Operators::IS_EMPTY: $this->qb->andWhere($this->qb->expr()->isNull($entityAlias . '.id')); break; case Operators::IS_NOT_EMPTY: $this->qb->andWhere($this->qb->expr()->isNotNull($entityAlias . '.id')); break; } return $this; }
/** * {@inheritdoc} */ public function getFilter($code, $operator) { $attribute = $this->attributeRepository->findOneBy(['code' => FieldFilterHelper::getCode($code)]); if (null !== $attribute) { return $this->getAttributeFilter($attribute, $operator); } return $this->getFieldFilter($code, $operator); }
/** * {@inheritdoc} */ public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = []) { if (!is_bool($value)) { throw InvalidArgumentException::booleanExpected($field, 'filter', 'boolean', gettype($value)); } $field = current($this->qb->getRootAliases()) . '.' . FieldFilterHelper::getCode($field); $condition = $this->prepareCriteriaCondition($field, $operator, $value); $this->qb->andWhere($condition); return $this; }
/** * {@inheritdoc} */ public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = []) { if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) { $this->checkValue($field, $value); if (FieldFilterHelper::CODE_PROPERTY === FieldFilterHelper::getProperty($field)) { $value = $this->objectIdResolver->getIdsFromCodes('family', $value); } else { $value = array_map('intval', $value); } } $field = FieldFilterHelper::getCode($field); $this->applyFilter($field, $operator, $value); return $this; }
/** * {@inheritdoc} */ public function addFilter($field, $operator, $value, array $context = []) { $attribute = $this->attributeRepository->findOneByIdentifier(FieldFilterHelper::getCode($field)); if (null !== $attribute) { $filter = $this->filterRegistry->getAttributeFilter($attribute, $operator); } else { $filter = $this->filterRegistry->getFieldFilter($field, $operator); } if (null === $filter) { throw new \LogicException(sprintf('Filter on property "%s" is not supported or does not support operator "%s"', $field, $operator)); } $context = $this->getFinalContext($context); if (null !== $attribute) { $context['field'] = $field; $this->addAttributeFilter($filter, $attribute, $operator, $value, $context); } else { $this->addFieldFilter($filter, $field, $operator, $value, $context); } $this->rawFilters[] = ['field' => $field, 'operator' => $operator, 'value' => $value, 'context' => $context]; return $this; }