/** * 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) { $this->checkValue($field, $value); if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) { $value = $this->objectIdResolver->getIdsFromCodes('family', $value); } } $fieldCode = FieldFilterHelper::getCode($field); switch ($operator) { case Operators::IN_LIST: $expr = new Expr(); $this->qb->addAnd($expr->field($fieldCode)->in($value)); break; case Operators::NOT_IN_LIST: $this->qb->field($fieldCode)->notIn($value); break; case Operators::IS_EMPTY: $exists = new Expr(); $equals = new Expr(); $expr = new Expr(); $exists->field($fieldCode)->exists(false); $equals->field($fieldCode)->equals(null); $expr->addOr($exists)->addOr($equals); $this->qb->addAnd($expr); break; } return $this; }
/** * {@inheritdoc} */ public function getFilter($code) { $attribute = $this->attributeRepository->findOneBy(['code' => FieldFilterHelper::getCode($code)]); if (null !== $attribute) { return $this->getAttributeFilter($attribute); } return $this->getFieldFilter($code); }
/** * {@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 = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, FieldFilterHelper::getCode($field)); $this->qb->field($field)->equals($value); return $this; }
/** * {@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) { $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); if ($operator === Operators::IN_LIST) { $this->qb->andWhere($this->qb->expr()->in($entityAlias . '.id', $value)); } elseif ($operator === Operators::NOT_IN_LIST) { $this->qb->andWhere($this->qb->expr()->orX($this->qb->expr()->notIn($entityAlias . '.id', $value), $this->qb->expr()->isNull($entityAlias . '.id'))); } elseif ($operator === Operators::IS_EMPTY) { $this->qb->andWhere($this->qb->expr()->isNull($entityAlias . '.id')); } return $this; }
/** * {@inheritdoc} */ public function addFilter($field, $operator, $value, array $context = []) { $attribute = $this->attributeRepository->findOneBy(['code' => FieldFilterHelper::getCode($field)]); if ($attribute !== null) { $filter = $this->filterRegistry->getAttributeFilter($attribute); } else { $filter = $this->filterRegistry->getFieldFilter($field); } if ($filter === null) { throw new \LogicException(sprintf('Filter on field "%s" is not supported', $field)); } if ($filter->supportsOperator($operator) === false) { throw new \LogicException(sprintf('Filter on field "%s" doesn\'t provide operator "%s"', $field, $operator)); } $context = $this->getFinalContext($context); if ($attribute !== null) { $context['field'] = $field; $this->addAttributeFilter($filter, $attribute, $operator, $value, $context); } else { $this->addFieldFilter($filter, $field, $operator, $value, $context); } return $this; }