/** * Build an expression used to filter data * * @param FilterDatasourceAdapterInterface $ds * @param int $comparisonType 0 to compare with false, 1 to compare with true * @param string $fieldName * @return string */ protected function buildComparisonExpr(FilterDatasourceAdapterInterface $ds, $comparisonType, $fieldName) { switch ($comparisonType) { case BooleanFilterType::TYPE_YES: return $ds->expr()->eq($fieldName, 'true'); default: return $ds->expr()->neq($fieldName, 'true'); } }
/** * {@inheritdoc} */ protected function buildComparisonExpr(FilterDatasourceAdapterInterface $ds, $comparisonType, $fieldName, $parameterName) { switch ($comparisonType) { case ChoiceFilterType::TYPE_NOT_CONTAINS: return $ds->expr()->neq($fieldName, $parameterName, true); default: return $ds->expr()->eq($fieldName, $parameterName, true); } }
/** * Applies filter to query by attribute * * @param FilterDatasourceAdapterInterface $ds * @param string $field * @param mixed $value * @param string $operator */ public function applyFilterByAttribute(FilterDatasourceAdapterInterface $ds, $field, $value, $operator) { $attribute = $this->getAttribute($field); $productQueryBuilder = $this->getProductRepository()->getProductQueryBuilder($ds->getQueryBuilder()); if ($attribute) { $productQueryBuilder->addAttributeFilter($attribute, $operator, $value); } else { $productQueryBuilder->addFieldFilter($field, $operator, $value); } }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $operator = $this->getOperator($data['type']); $parameterName = $ds->generateParameterName($this->getName()); $this->applyFilterToClause($ds, $ds->expr()->comparison($this->get(FilterUtility::DATA_NAME_KEY), $operator, $parameterName, true)); $ds->setParameter($parameterName, $data['value']); return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } if (is_array($data['value'])) { $data['value'] = reset($data['value']); } $ds->addGroupBy($data['value']); return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $ids = $data['value']; $qb = $ds->getQueryBuilder(); $repository = $this->util->getProductRepository(); $pqb = $repository->getProductQueryBuilder($qb); $pqb->addFieldFilter('family', 'IN', $ids); return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $qb = $ds->getQueryBuilder(); $value = current($data['value']); $repository = $this->util->getProductRepository(); $pqb = $repository->getProductQueryBuilder($qb); $pqb->addFieldFilter('enabled', '=', $value); return true; }
/** * {@inheritDoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $type = $data['type']; $parameterName = $ds->generateParameterName($this->getName()); $this->applyFilterToClause($ds, $this->buildComparisonExpr($ds, $type, $this->get(FilterUtility::DATA_NAME_KEY), $parameterName)); if (!in_array($type, [FilterUtility::TYPE_EMPTY, FilterUtility::TYPE_NOT_EMPTY], true)) { $ds->setParameter($parameterName, $data['value']); } return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $operator = $this->getOperator($data['type']); $ds->generateParameterName($this->getName()); $data['data'] = $data['value']; unset($data['value']); unset($data['type']); $this->util->applyFilter($ds, $this->get(ProductFilterUtility::DATA_NAME_KEY), $operator, $data); return true; }
/** * @param FilterDatasourceAdapterInterface $ds * @param mixed $data * * @return array|bool */ protected function prepareData(FilterDatasourceAdapterInterface $ds, $data) { if (!is_array($data) || !array_key_exists('value', $data) || !array_key_exists('type', $data) || !$data['value'] && FilterType::TYPE_EMPTY !== $data['type']) { return false; } $data['value'] = preg_quote($data['value']); $data['type'] = isset($data['type']) ? $data['type'] : null; if ('in' === $data['type']) { $data['value'] = explode(',', $data['value']); } else { $format = $ds->getFormatByComparisonType($data['type']); $data['value'] = sprintf($format, $data['value']); } return $data; }
/** * {@inheritDoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $type = $data['type']; if (count($data['value']) > 1 || isset($data['value'][0]) && $data['value'][0] != "") { $parameterName = $ds->generateParameterName($this->getName()); $this->applyFilterToClause($ds, $this->get(FilterUtility::DATA_NAME_KEY) . ' in (:' . $parameterName . ')'); if (!in_array($type, [FilterUtility::TYPE_EMPTY, FilterUtility::TYPE_NOT_EMPTY], true)) { $ds->setParameter($parameterName, $data['value']); } } return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $associationType = $this->getAssociationType(); $product = $this->getCurrentProduct(); $productIds = $this->getAssociatedProductIds($product, $associationType); $operator = $data['value'] === BooleanFilterType::TYPE_YES ? 'IN' : 'NOT IN'; $qb = $ds->getQueryBuilder(); $repository = $this->util->getProductRepository(); $pqb = $repository->getProductQueryBuilder($qb); $pqb->addFieldFilter('id', $operator, $productIds); return true; }
/** * {@inheritDoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $type = $data['type']; if (count($data['value']) > 1 || isset($data['value'][0]) && $data['value'][0] != "") { $parameterName = $ds->generateParameterName($this->getName()); $qb2 = $this->registry->getManager()->getRepository('Oro\\Bundle\\UserBundle\\Entity\\User')->createQueryBuilder('u')->select('u.id')->leftJoin('u.businessUnits', 'bu')->where('bu.id in (:' . $parameterName . ')')->getQuery()->getDQL(); $this->applyFilterToClause($ds, $this->get(FilterUtility::DATA_NAME_KEY) . ' in (' . $qb2 . ')'); if (!in_array($type, [FilterUtility::TYPE_EMPTY, FilterUtility::TYPE_NOT_EMPTY], true)) { $ds->setParameter($parameterName, $data['value']); } } return true; }
/** * Build an expression used to filter data * * @param FilterDatasourceAdapterInterface $ds * @param int $comparisonType * @param string $fieldName * @param string $parameterName * * @return mixed */ protected function buildComparisonExpr(FilterDatasourceAdapterInterface $ds, $comparisonType, $fieldName, $parameterName) { switch ($comparisonType) { case DictionaryFilterType::TYPE_NOT_IN: return $ds->expr()->notIn($fieldName, $parameterName, true); break; case DictionaryFilterType::EQUAL: return $ds->expr()->eq($fieldName, $parameterName, true); break; case DictionaryFilterType::NOT_EQUAL: return $ds->expr()->neq($fieldName, $parameterName, true); break; default: return $ds->expr()->in($fieldName, $parameterName, true); break; } }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $operator = $this->getOperator($data['type']); $parameter = $ds->generateParameterName($this->getName()); if ('IN' == $operator) { $expression = $ds->expr()->in($this->get(FilterUtility::DATA_NAME_KEY), $parameter, true); } else { $expression = $ds->expr()->notIn($this->get(FilterUtility::DATA_NAME_KEY), $parameter, true); } $this->applyFilterToClause($ds, $expression); $ds->setParameter($parameter, $data['value']); return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $groupId = $this->extractor->getDatagridParameter('currentGroup'); if (!$groupId) { throw new \LogicException('The current product group must be configured'); } $value = [$groupId]; $operator = $data['value'] === BooleanFilterType::TYPE_YES ? 'IN' : 'NOT IN'; $qb = $ds->getQueryBuilder(); $repository = $this->util->getProductRepository(); $pqb = $repository->getProductQueryBuilder($qb); $pqb->addFieldFilter('groups', $operator, $value); return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $operator = $this->getOperator($data['type']); $ds->generateParameterName($this->getName()); // Convert value to base unit if ('EMPTY' !== $operator) { $this->converter->setFamily($this->family); $baseValue = $this->converter->convertBaseToStandard($data['unit'], $data['value']); } else { $baseValue = null; } $this->util->applyFilterByAttribute($ds, $this->get(ProductFilterUtility::DATA_NAME_KEY), $baseValue, $operator); return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $this->activityAlias = $ds->generateParameterName('r'); $this->activityListAlias = $ds->generateParameterName('a'); if (!$ds instanceof OrmFilterDatasourceAdapter) { throw new LogicException(sprintf('"Oro\\Bundle\\FilterBundle\\Datasource\\Orm\\OrmFilterDatasourceAdapter" expected but "%s" given.', get_class($ds))); } $type = $data['filterType']; unset($data['filterType']); $qb = $ds->getQueryBuilder(); $em = $qb->getEntityManager(); $metadata = $em->getClassMetadata($data['entityClassName']); $activityQb = $this->createActivityQueryBuilder($em, $data, $this->getIdentifier($metadata)); $activityPart = $ds->expr()->exists($activityQb->getQuery()->getDQL()); if ($type === static::TYPE_HAS_NOT_ACTIVITY) { $activityPart = $ds->expr()->not($activityPart); } $this->applyFilterToClause($ds, $activityPart); $this->copyParameters($activityQb, $qb); }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $qb = $ds->getQueryBuilder(); switch ($data['value']) { case BooleanFilterType::TYPE_YES: $operator = '='; break; case BooleanFilterType::TYPE_NO: default: $operator = '<'; break; } $repository = $this->util->getProductRepository(); $pqb = $repository->getProductQueryBuilder($qb); $pqb->addFieldFilter('completeness', $operator, '100'); return true; }
/** * {@inheritDoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $this->auditAlias = $ds->generateParameterName('a'); $this->auditFieldAlias = $ds->generateParameterName('f'); $this->fieldParam = $ds->generateParameterName('field'); $this->objectClassParam = $ds->generateParameterName('objectClass'); if (!$ds instanceof OrmFilterDatasourceAdapter) { throw new LogicException(sprintf('"Oro\\Bundle\\FilterBundle\\Datasource\\Orm\\OrmFilterDatasourceAdapter" expected but "%s" given.', get_class($ds))); } $qb = $ds->getQueryBuilder(); $fieldName = $this->getField($data['auditFilter']['columnName']); list($objectAlias) = $qb->getRootAliases(); $objectClass = $this->getClass($data['auditFilter']['columnName'], $qb->getRootEntities()); $metadata = $qb->getEntityManager()->getClassMetadata($objectClass); if ($metadata->isIdentifierComposite) { throw new \LogicException('Composite identifiers are not supported.'); } $identifier = $metadata->getIdentifier()[0]; $auditQb = $qb->getEntityManager()->getRepository('OroDataAuditBundle:Audit')->createQueryBuilder($this->auditAlias); $auditQb->select('1')->andWhere(sprintf('%s.objectClass = :%s', $this->auditAlias, $this->objectClassParam))->andWhere(sprintf('%s.objectId = %s.%s', $this->auditAlias, $objectAlias, $identifier))->setParameter($this->objectClassParam, $objectClass)->setMaxResults(1); $auditQb->join(sprintf('%s.fields', $this->auditAlias), $this->auditFieldAlias, Expr\Join::WITH, sprintf('%s.field = :%s', $this->auditFieldAlias, $this->fieldParam))->setParameter($this->fieldParam, $fieldName); $auditDs = new OrmFilterDatasourceAdapter($auditQb); $this->applyFilter($auditDs, 'datetime', sprintf('%s.loggedAt', $this->auditAlias), $data['auditFilter']['data']); $this->applyNewAuditValueFilter($auditDs, $objectClass, $fieldName, $data); $this->applyFilterToClause($ds, $ds->expr()->exists($auditQb->getQuery()->getDQL())); foreach ($auditQb->getParameters() as $parameter) { $qb->setParameter($parameter->getName(), $parameter->getValue(), $parameter->getType()); } }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $field = $this->get(FilterUtility::DATA_NAME_KEY); $compareExpression = $ds->expr()->neq($field, 'false'); if ($this->getOr(self::NULLABLE_KEY, false)) { $summaryExpression = $ds->expr()->andX($ds->expr()->isNotNull($field), $compareExpression); } else { $summaryExpression = $compareExpression; } switch ($data['value']) { case BooleanFilterType::TYPE_YES: $expression = $summaryExpression; break; case BooleanFilterType::TYPE_NO: default: $expression = $ds->expr()->not($summaryExpression); break; } $this->applyFilterToClause($ds, $expression); return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $expression = false; switch (true) { case $data['in'] === null && $data['out'] !== null && empty($data['out']): $expression = $ds->expr()->eq(1, 1); break; case $data['out'] === null && $data['in'] !== null && empty($data['in']): $expression = $ds->expr()->eq(0, 1); break; case !empty($data['in']): $expression = $ds->expr()->in($this->get(FilterUtility::DATA_NAME_KEY), $data['in']); break; case !empty($data['out']): $expression = $ds->expr()->notIn($this->get(FilterUtility::DATA_NAME_KEY), $data['out']); break; } if (!$expression) { return false; } $this->applyFilterToClause($ds, $expression); return true; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } if ($data['in'] !== null) { if (!empty($data['in'])) { $parameterName = $ds->generateParameterName($this->getName()); $this->applyFilterToClause($ds, $ds->expr()->in($this->get(FilterUtility::DATA_NAME_KEY), $parameterName, true)); $ds->setParameter($parameterName, $data['in']); } else { // requested to return all selected rows, but no one row are selected $this->applyFilterToClause($ds, $ds->expr()->eq(0, 1)); } } elseif ($data['out'] !== null && !empty($data['out'])) { $parameterName = $ds->generateParameterName($this->getName()); $this->applyFilterToClause($ds, $ds->expr()->notIn($this->get(FilterUtility::DATA_NAME_KEY), $parameterName, true)); $ds->setParameter($parameterName, $data['out']); } return true; }
/** * @param FilterDatasourceAdapterInterface $ds * @param string $fieldName * * @return bool */ protected function isAggregateField(FilterDatasourceAdapterInterface $ds, $fieldName) { return (bool) preg_match('/(?<![\\w:.])(\\w+)\\s*\\(/im', $ds->getFieldByAlias($fieldName)); }
/** * Apply filter expression to having or where clause depending on configuration * * @param FilterDatasourceAdapterInterface $ds * @param mixed $expression */ protected function applyFilterToClause(FilterDatasourceAdapterInterface $ds, $expression) { $ds->addRestriction($expression, $this->getOr(FilterUtility::CONDITION_KEY, FilterUtility::CONDITION_AND), $this->getOr(FilterUtility::BY_HAVING_KEY, false)); }
/** * @param FilterDatasourceAdapterInterface $ds * @param string $fieldName * @param mixed $valueStart * @param mixed $valueEnd * @return string */ protected function buildNotBetweenExpr(FilterDatasourceAdapterInterface $ds, $fieldName, $valueStart, $valueEnd) { $parameterStart = $ds->generateParameterName($this->getName()); $parameterEnd = $ds->generateParameterName($this->getName()); if ($valueStart && $valueEnd) { $ds->setParameter($parameterStart, $valueStart); $ds->setParameter($parameterEnd, $valueEnd); return $ds->expr()->orX($ds->expr()->lt($fieldName, $parameterStart, true), $ds->expr()->gt($fieldName, $parameterEnd, true)); } elseif ($valueStart) { $ds->setParameter($parameterStart, $valueStart); return $ds->expr()->lt($fieldName, $parameterStart, true); } else { $ds->setParameter($parameterEnd, $valueEnd); return $ds->expr()->gt($fieldName, $parameterEnd, true); } }
/** * Applies filter to query by attribute * * @param FilterDatasourceAdapterInterface $ds * @param string $field * @param string $operator * @param mixed $value */ public function applyFilter(FilterDatasourceAdapterInterface $ds, $field, $operator, $value) { $ds->getProductQueryBuilder()->addFilter($field, $operator, $value); }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { if (!(isset($data['value']) && $data['value'] instanceof Segment)) { return false; } /** @var Segment $segment */ $segment = $data['value']; /** @var Query $query */ if ($segment->getType()->getName() === SegmentType::TYPE_DYNAMIC) { $query = $this->dynamicSegmentQueryBuilderLink->getService()->build($segment); } else { $query = $this->staticSegmentQueryBuilderLink->getService()->build($segment); } $field = $this->get(FilterUtility::DATA_NAME_KEY); $expr = $ds->expr()->in($field, $query->getDQL()); $this->applyFilterToClause($ds, $expr); $params = $query->getParameters(); /** @var Parameter $param */ foreach ($params as $param) { $ds->setParameter($param->getName(), $param->getValue(), $param->getType()); } return true; }
/** * @param int $comparisonType * @param string $value * * @return array */ protected function getValueParts($comparisonType, $value) { return array_map(function ($val) use($comparisonType) { return parent::parseValue($comparisonType, $val); }, $this->tokenizer->tokenize($value, $this->ds->getDatabasePlatform())); }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { if (!(isset($data['value']) && $data['value'] instanceof Segment)) { return false; } if (!$this->isExpressionBuilderSupported($ds->expr())) { throw new \LogicException('The SegmentFilter supports ORM data source only.'); } $queryBuilder = $this->getSegmentQueryBuilder($data); $query = $queryBuilder->getQuery(); /**@var OrmExpressionBuilder $expressionBuilder */ $expressionBuilder = $ds->expr(); $expr = $expressionBuilder->exists($query->getDQL()); $this->applyFilterToClause($ds, $expr); $params = $query->getParameters(); /** @var Parameter $param */ foreach ($params as $param) { $ds->setParameter($param->getName(), $param->getValue(), $param->getType()); } return true; }