/** * Applies operation to data source and returns modified data source. * * @param QueryBuilder $src * @param OperationInterface|FilterOperation $operation * @return QueryBuilder */ public function process($src, OperationInterface $operation) { $value = $operation->getValue(); $operator = $operation->getOperator(); $fieldName = $operation->getField(); $parameterName = 'p' . md5($fieldName . $operator); $src->andWhere("{$fieldName} {$operator} :{$parameterName}"); $src->setParameter($parameterName, $value); return $src; }
/** * Applies operation to source and returns modified source. * * @param $src * @param OperationInterface|FilterOperation $operation * @return mixed */ public function process($src, OperationInterface $operation) { $res = []; foreach ($src as $row) { $testedValue = mp\getValue($row, $operation->getField()); $argument = $operation->getValue(); $operator = $operation->getOperator(); if ($this->checkValue($testedValue, $operator, $argument)) { $res[] = $row; } } return $res; }
/** * @param Builder $src * @param OperationInterface|FilterOperation $operation * @return mixed */ public function process($src, OperationInterface $operation) { $value = $operation->getValue(); $operator = $operation->getOperator(); $field = $operation->getField(); switch ($operator) { case FilterOperation::OPERATOR_STR_STARTS_WITH: $operator = FilterOperation::OPERATOR_LIKE; $value .= '%'; break; case FilterOperation::OPERATOR_STR_ENDS_WITH: $operator = FilterOperation::OPERATOR_LIKE; $value = '%' . $value; break; case FilterOperation::OPERATOR_STR_CONTAINS: $operator = FilterOperation::OPERATOR_LIKE; $value = '%' . $value . '%'; break; } $src->where($field, $operator, $value); return $src; }
/** * Applies operation to source and returns modified source. * * @param Query $src * @param OperationInterface|FilterOperation $operation * @return Query */ public function process($src, OperationInterface $operation) { $argument = $operation->getValue(); $operator = $operation->getOperator(); $field = $operation->getField(); switch ($operator) { case FilterOperation::OPERATOR_STR_STARTS_WITH: $operator = FilterOperation::OPERATOR_LIKE; $argument .= '%'; break; case FilterOperation::OPERATOR_STR_ENDS_WITH: $operator = FilterOperation::OPERATOR_LIKE; $argument = '%' . $argument; break; case FilterOperation::OPERATOR_STR_CONTAINS: $operator = FilterOperation::OPERATOR_LIKE; $argument = '%' . $argument . '%'; break; } $src->conditions[] = "{$field} {$operator} :{$field}"; $src->bindings[':' . $field] = $argument; return $src; }