/** * Applies operation to data source and returns modified data source. * * @param $src * @param OperationInterface|CustomOperation $operation * @return mixed modified data source */ public function process($src, OperationInterface $operation) { $callable = $operation->getCallback(); $arguments = array_merge([$src], $operation->getArguments()); $res = call_user_func_array($callable, $arguments); return $res ?: $src; }
/** * Applies operation to source and returns modified source. * * @param Query $src * @param OperationInterface|SortOperation $operation * @return Query */ public function process($src, OperationInterface $operation) { $field = $operation->getField(); $order = $operation->getOrder(); $src->order .= "ORDER BY {$field} {$order}"; return $src; }
/** * Applies operation to data source and returns modified data source. * * @param QueryBuilder $src * @param OperationInterface|SortOperation $operation * @return QueryBuilder */ public function process($src, OperationInterface $operation) { $field = $operation->getField(); $order = $operation->getOrder(); $src->orderBy($field, $order); return $src; }
/** * 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; }
/** * Applies operation to source and returns modified source. * * @param $src * @param OperationInterface|SortOperation $operation * @return mixed */ public function process($src, OperationInterface $operation) { $field = $operation->getField(); $desc = $operation->getOrder() === SortOperation::DESC; usort($src, function ($row1, $row2) use($field, $desc) { $val1 = mp\getValue($row1, $field); $val2 = mp\getValue($row2, $field); if ($val1 == $val2) { return 0; } $res = $val1 < $val2 ? -1 : 1; return $desc ? -$res : $res; }); return $src; }
/** * @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; }
/** * @param Builder|EloquentBuilder $src * @param OperationInterface|PaginateOperation $operation * @return mixed */ public function process($src, OperationInterface $operation) { $src->limit($operation->getPageSize())->offset($this->getOffset($operation)); return $src; }