Prepares SQL where query according SQL condition array and attaches it to SQL end.
For each search value if german umlauts exist, adds them
and replaced by spec. char to query

@param string $fieldValue Filters

@return string
540007
protected function _processFilter($fieldValue)
    {
        $stringModifier = getStr();

        //removing % symbols
        $fieldValue = $stringModifier->preg_replace("/^%|%$/", "", trim($fieldValue));

        return $stringModifier->preg_replace("/\s+/", " ", $fieldValue);
    }
205329
public function insertRecordIntoIndex($fieldValues)
    {
        $queryBuilder = Db::getQueryBuilder('tx_kesearch_index');
        $addQueryPartFor = $this->getQueryPartForAdditionalFields($fieldValues);

        $queryArray = array();
        $queryArray['set'] = 'SET
			@pid = ' . $queryBuilder->quote($fieldValues['pid'], \PDO::PARAM_INT) . ',
			@title = ' . $queryBuilder->quote($fieldValues['title'], \PDO::PARAM_STR) . ',
			@type = ' . $queryBuilder->quote($fieldValues['type'], \PDO::PARAM_STR) . ',
			@targetpid = ' . $queryBuilder->quote($fieldValues['targetpid'], \PDO::PARAM_INT) . ',
			@content = ' . $queryBuilder->quote($fieldValues['content'], \PDO::PARAM_STR) . ',
			@tags = ' . $queryBuilder->quote($fieldValues['tags'], \PDO::PARAM_STR) . ',
			@params = ' . $queryBuilder->quote($fieldValues['params'], \PDO::PARAM_STR) . ',
			@abstract = ' . $queryBuilder->quote($fieldValues['abstract'], \PDO::PARAM_STR) . ',
			@language = ' . $queryBuilder->quote($fieldValues['language'], \PDO::PARAM_INT) . ',
			@starttime = ' . $queryBuilder->quote($fieldValues['starttime'], \PDO::PARAM_INT) . ',
			@endtime = ' . $queryBuilder->quote($fieldValues['endtime'], \PDO::PARAM_INT) . ',
			@fe_group = ' . $queryBuilder->quote($fieldValues['fe_group'], \PDO::PARAM_INT) . ',
			@tstamp = ' . $queryBuilder->quote($fieldValues['tstamp'], \PDO::PARAM_INT) . ',
			@crdate = ' . $queryBuilder->quote($fieldValues['crdate'], \PDO::PARAM_INT)
            . $addQueryPartFor['set'] . '
		;';

        $queryArray['execute'] = 'EXECUTE insertStmt USING '
            . '@pid, '
            . '@title, '
            . '@type, '
            . '@targetpid, '
            . '@content, '
            . '@tags, '
            . '@params, '
            . '@abstract, '
            . '@language, '
            . '@starttime, '
            . '@endtime, '
            . '@fe_group, '
            . '@tstamp, '
            . '@crdate'
            . $addQueryPartFor['execute'] . ';';

        try  {
            Db::getDatabaseConnection('tx_kesearch_index')->exec($queryArray['set']);
            Db::getDatabaseConnection('tx_kesearch_index')->exec($queryArray['execute']);
        } catch (\Exception $e) {
            $this->logger->error($e->getMessage());
        }

    }
169075
public function getDistinctResultByColumn($selectField = '', $whereValue = [])
    {
        if (!is_array($selectField)) {
            $selectField = [$selectField];
        }
        $this->connection();
        $db = DB::table($this->table);
        if (is_array($whereValue) && count($whereValue) > 0) {
            foreach ($whereValue as $column => $column_value) {
                if (is_array($column_value)) {
                    $db->whereIn($column, $column_value);
                } else {
                    $db->where($column, self::OPERATOR_EQUAL_TO, $column_value);
                }
            }
        } else {
            if (!empty($whereValue)) {
                if (is_array($whereValue)) {
                    $db->whereIn($selectField, $whereValue);
                } else {
                    $db->where($selectField, self::OPERATOR_EQUAL_TO, $whereValue);
                }
            }
        }
        $db->distinct();
        $this->debug->debug(__FUNCTION__, 'SQL Queries: ' . $db->toSql());
        $result = $db->get($selectField);
        $this->debug->debug(__FUNCTION__, 'Result from DB => ' . json_encode($result));

        return $result;
    }
825571
protected function prepareFields($fields, $values) {
        $_fields = [];
        foreach ($fields as $field) {
            if ($field instanceof Query) { // sub-select SQL as field
                $field->setDialect($this->dialect);
                $field->setBindValues($values);
                $as = $field->getAlias();
                if ($as) {
                    $_fields [] = '(' . $field . ') AS ' . $this->sanitize('`' . $as . '`');
                }
            } else if ($field instanceof ImmutableValue) {
                $_fields [] = $field->__toString();
            } else { // this is simple field
                $_fields [] = $this->sanitize($field);
            }
        }
        if ($_fields) {
            return implode(',', $_fields);
        } else {
            return false;
        }
    }
895621
protected function applyFieldFilters($propertyValue)
    {
        $filterConfig = $this->field->getFilters();
        if (count($filterConfig)) {
            $filterCollection = $this->createFilterCollection($filterConfig);
            $propertyValue = $filterCollection->filter($propertyValue);
        }

        return $propertyValue;
    }
585331
protected function applyHtmlSpecialCharsOnSingleFieldValue($fieldValue)
    {
        if (is_array($fieldValue)) {
            foreach ($fieldValue as $key => $fieldValueItem) {
                $fieldValue[$key] = htmlspecialchars($fieldValueItem, null, null, false);
            }
        } else {
            $fieldValue = htmlspecialchars($fieldValue, null, null, false);
        }

        return $fieldValue;
    }
514670
public function prepareFieldName($fieldName)
    {
        list($fieldName) = $this->prepareQueryElement($fieldName, null, null, false);

        return $fieldName;
    }
969656
private function canonicalizeFieldValue($fieldname, $fieldvalue)
    {
        switch ($fieldname) {
            case 'email':
                return strtolower(trim($fieldvalue));

            case 'username':
                return strtolower(preg_replace('/[^a-zA-Z0-9_\\-]/', '', $fieldvalue));

            default:
                return trim($fieldvalue);
        }
    }
704974
private function addConditionsToSqlWhithWhereIn(): string
    {
        if (count($this->wheresIn) === 0) {
            throw new OrmException('Argument 2 passed to "whereIn()" can not be an empty array.');
        }
        
        $paramsWhereIn = " ( ";

        foreach ($this->wheresIn as $value) {                
            $paramsWhereIn .= " ?, ";

            $this->wheresBindValue[] = $value;
        }

        $this->wheresIn = [];

        return rtrim($paramsWhereIn, ', ')." ) ";
    }
372901
public function sql(ValueBinder $generator)
    {
        if (empty($this->_values) && empty($this->_query)) {
            return '';
        }

        if (!$this->_castedExpressions) {
            $this->_processExpressions();
        }

        $columns = $this->_columnNames();
        $defaults = array_fill_keys($columns, null);
        $placeholders = [];

        $types = [];
        $typeMap = $this->getTypeMap();
        foreach ($defaults as $col => $v) {
            $types[$col] = $typeMap->type($col);
        }

        foreach ($this->_values as $row) {
            $row += $defaults;
            $rowPlaceholders = [];

            foreach ($columns as $column) {
                $value = $row[$column];

                if ($value instanceof ExpressionInterface) {
                    $rowPlaceholders[] = '(' . $value->sql($generator) . ')';
                    continue;
                }

                $placeholder = $generator->placeholder('c');
                $rowPlaceholders[] = $placeholder;
                $generator->bind($placeholder, $value, $types[$column]);
            }

            $placeholders[] = implode(', ', $rowPlaceholders);
        }

        if ($this->getQuery()) {
            return ' ' . $this->getQuery()->sql($generator);
        }

        return sprintf(' VALUES (%s)', implode('), (', $placeholders));
    }
137996
protected function _filterField($fieldValue)
    {
        //usuwanie html i obcinanie zbyt długich ciągów
        return (new \Mmi\Filter\Truncate)->filter((new \Mmi\Filter\Escape)->filter($fieldValue));
    }
843994
public Object getSQLValue(String fieldname, Serializable fieldvalue) {
        if (this.cryptmap == null) return fieldvalue;
        CryptHandler handler = this.cryptmap.get(fieldname);
        if (handler == null) return fieldvalue;
        return handler.encrypt(fieldvalue);
    }
464869
protected function parseConditions(QueryBuilderInterface $queryBuilder, $where)
    {
        if (empty($where)) {
            return '';
        }

        $sql = '';
        if ($this->isWherePart($where)) {
            $operator = $where['___operator'];
            $childWhere = $where['___where'];
            $condition = $where['___condition'];
            if ($this->isWherePart($childWhere)) {
                $whereSql = $this->parseConditions($queryBuilder, $childWhere);
                $sql .= '('.$whereSql.') '.strtoupper($operator).' ('.$this->parsePart($condition, $operator).')';
            } else {
                $sql .= $this->parsePart($queryBuilder, $childWhere, $operator);
            }
        } else {
            $sql .= $this->parsePart($queryBuilder, $where);
        }

        if (empty($sql)) {
            return '';
        }

        return $sql;
    }
381728
public function sqlFilters()
    {
        if (!$this->hasFilters()) {
            return '';
        }

        $criteria = $this->createFilter([
            'filters' => $this->filters()
        ]);

        $sql = $criteria->sql();
        if (strlen($sql) > 0) {
            $sql = ' WHERE '.$sql;
        }

        return $sql;
    }
181895
public function resolveField(FieldValue $fieldValue): FieldValue
    {
        return $fieldValue->setResolver(
            function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): LengthAwarePaginator {
                /** @var int $first */
                /** @var int $page */
                [$first, $page] = PaginationUtils::extractArgs($args, $this->paginationType(), $this->paginateMaxCount());

                if ($this->directiveHasArgument('builder')) {
                    $query = call_user_func(
                        $this->getResolverFromArgument('builder'),
                        $root,
                        $args,
                        $context,
                        $resolveInfo
                    );
                } else {
                    /** @var \Illuminate\Database\Eloquent\Model $model */
                    $model = $this->getPaginatorModel();
                    $query = $model::query();
                }

                $query = $resolveInfo
                    ->builder
                    ->addScopes(
                        $this->directiveArgValue('scopes', [])
                    )
                    ->apply(
                        $query,
                        $args
                    );

                if ($query instanceof ScoutBuilder) {
                    return $query->paginate($first, 'page', $page);
                }

                return $query->paginate($first, ['*'], 'page', $page);
            }
        );
    }
954087
public function query($formValue)
    {
        /// 单表查询
        $query = $this->query;
        $fields = explode('.', $this->field);

        if (count($fields) == 1) {
            return call_user_func_array([$this->builder, $query], $this->getQueryArgs($formValue));
        }

        /// 关系查询
        $query = 'whereHas';
        [$relation, $this->field] = $fields;

        return call_user_func_array([$this->builder, $query], [$relation, function($builder) use ($formValue) {
            call_user_func_array([$builder, $this->query], $this->getQueryArgs($formValue));
        }]);
    }
123556
final public function sqlLikeSearch(
        string $fieldName,
        string $searchTerms,
        bool $matchAnyTerm = true,
        string $termsSeparator = ' '
    ): string {
        return implode(
            ($matchAnyTerm) ? ' OR ' : ' AND ',
            array_map(function (string $term) use ($fieldName): string {
                return '(' . $this->sqlLike($fieldName, $term) . ')';
            }, array_unique(array_filter(explode($termsSeparator, $searchTerms) ?: [])))
        );
    }