コード例 #1
0
 /**
  * {@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;
 }
コード例 #2
0
ファイル: NumberFilter.php プロジェクト: Maksold/platform
 /**
  * Build an expression used to filter data
  *
  * @param FilterDatasourceAdapterInterface $ds
  * @param int                              $comparisonType
  * @param string                           $fieldName
  * @param string                           $parameterName
  * @return string
  */
 protected function buildComparisonExpr(FilterDatasourceAdapterInterface $ds, $comparisonType, $fieldName, $parameterName)
 {
     switch ($comparisonType) {
         case NumberFilterType::TYPE_GREATER_EQUAL:
             return $ds->expr()->gte($fieldName, $parameterName, true);
         case NumberFilterType::TYPE_GREATER_THAN:
             return $ds->expr()->gt($fieldName, $parameterName, true);
         case NumberFilterType::TYPE_LESS_EQUAL:
             return $ds->expr()->lte($fieldName, $parameterName, true);
         case NumberFilterType::TYPE_LESS_THAN:
             return $ds->expr()->lt($fieldName, $parameterName, true);
         case NumberFilterType::TYPE_NOT_EQUAL:
             return $ds->expr()->neq($fieldName, $parameterName, true);
         case FilterUtility::TYPE_EMPTY:
             if ($this->isAggregateField($ds, $fieldName)) {
                 $fieldName = $ds->expr()->coalesce([$fieldName]);
             }
             return $ds->expr()->isNull($fieldName);
         case FilterUtility::TYPE_NOT_EMPTY:
             if ($this->isAggregateField($ds, $fieldName)) {
                 $fieldName = $ds->expr()->coalesce([$fieldName]);
             }
             return $ds->expr()->isNotNull($fieldName);
         default:
             return $ds->expr()->eq($fieldName, $parameterName, true);
     }
 }
コード例 #3
0
ファイル: StringFilter.php プロジェクト: Maksold/platform
 /**
  * Build an expression used to filter data
  *
  * @param FilterDatasourceAdapterInterface $ds
  * @param int                              $comparisonType
  * @param string                           $fieldName
  * @param string                           $parameterName
  *
  * @return string
  */
 protected function buildComparisonExpr(FilterDatasourceAdapterInterface $ds, $comparisonType, $fieldName, $parameterName)
 {
     switch ($comparisonType) {
         case TextFilterType::TYPE_EQUAL:
             return $ds->expr()->eq($fieldName, $parameterName, true);
         case TextFilterType::TYPE_NOT_CONTAINS:
             return $ds->expr()->notLike($fieldName, $parameterName, true);
         case TextFilterType::TYPE_IN:
             return $ds->expr()->in($fieldName, $parameterName, true);
         case TextFilterType::TYPE_NOT_IN:
             return $ds->expr()->notIn($fieldName, $parameterName, true);
         case FilterUtility::TYPE_EMPTY:
             $emptyString = $ds->expr()->literal('');
             if ($this->isCompositeField($ds, $fieldName)) {
                 $fieldName = $ds->expr()->trim($fieldName);
             }
             return $ds->expr()->andX($ds->expr()->orX($ds->expr()->isNull($fieldName), $ds->expr()->eq($fieldName, $emptyString)), $ds->expr()->eq(true, true));
         case FilterUtility::TYPE_NOT_EMPTY:
             $emptyString = $ds->expr()->literal('');
             if ($this->isCompositeField($ds, $fieldName)) {
                 $fieldName = $ds->expr()->trim($fieldName);
             }
             return $ds->expr()->andX($ds->expr()->isNotNull($fieldName), $ds->expr()->neq($fieldName, $emptyString));
         default:
             return $ds->expr()->like($fieldName, $parameterName, true);
     }
 }
コード例 #4
0
 /**
  * {@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;
 }
コード例 #5
0
ファイル: BooleanFilter.php プロジェクト: startupz/platform-1
 /**
  * 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');
     }
 }
コード例 #6
0
 /**
  * {@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);
     }
 }
コード例 #7
0
 /**
  * {@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;
 }
コード例 #8
0
 /**
  * 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;
     }
 }
コード例 #9
0
 /**
  * @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);
     }
 }
コード例 #10
0
ファイル: SegmentFilter.php プロジェクト: xamin123/platform
 /**
  * {@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;
 }
コード例 #11
0
ファイル: SegmentFilter.php プロジェクト: Maksold/platform
 /**
  * {@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;
 }
コード例 #12
0
 /**
  * Apply expression using "not between" filtering
  *
  * @param FilterDatasourceAdapterInterface $ds
  * @param string                           $dateStartValue
  * @param string                           $dateEndValue
  * @param string                           $startDateParameterName
  * @param string                           $endDateParameterName
  * @param string                           $fieldName
  */
 protected function applyFilterNotBetween($ds, $dateStartValue, $dateEndValue, $startDateParameterName, $endDateParameterName, $fieldName)
 {
     if ($dateStartValue || $dateEndValue) {
         $expr = null;
         if ($dateStartValue) {
             if ($dateEndValue) {
                 $expr = $ds->expr()->orX($ds->expr()->lt($fieldName, $startDateParameterName, true), $ds->expr()->gt($fieldName, $endDateParameterName, true));
             } else {
                 $expr = $ds->expr()->lt($fieldName, $startDateParameterName, true);
             }
         } else {
             $expr = $ds->expr()->gt($fieldName, $endDateParameterName, true);
         }
         $this->applyFilterToClause($ds, $expr);
     }
 }
コード例 #13
0
ファイル: ChoiceFilter.php プロジェクト: Maksold/platform
 /**
  * Build an expression contains both comparison and null value expressions
  *
  * @param FilterDatasourceAdapterInterface $ds
  * @param int                              $comparisonType
  * @param mixed                            $comparisonExpr
  * @param mixed                            $nullValueExpr
  *
  * @return mixed
  */
 protected function buildCombinedExpr(FilterDatasourceAdapterInterface $ds, $comparisonType, $comparisonExpr, $nullValueExpr)
 {
     switch ($comparisonType) {
         case ChoiceFilterType::TYPE_NOT_CONTAINS:
             return $ds->expr()->andX($comparisonExpr, $nullValueExpr);
         default:
             return $ds->expr()->orX($comparisonExpr, $nullValueExpr);
     }
 }