src/QueryParserCustomFields.php
private function prepareNormalSql(array $searchCriteria, string $classname, string $andOr, int $fKey): string
    {
        $sql = '';
        $textFields = $this->getTextFields($classname);
        list($searchField, $operator, $searchValues) = $searchCriteria;
        $operator = $this->operators[$operator];

        if (trim($searchValues) !== '') {
            if ($searchValues == '%%') {
                $sql .= ' ' . $andOr . ' (' . $classname . '.' . $searchField . ' IS NULL';
                $sql .= ' OR ' . $classname . '.' . $searchField . ' = ""';

                if ($this->model->$searchField === 0) {
                    $sql .= ' OR ' . $classname . '.' . $searchField . ' = 0';
                }

                $sql .= ')';
            } elseif ($searchValues == '$$') {
                $sql .= ' ' . $andOr . ' (' . $classname . '.' . $searchField . ' IS NOT NULL';
                $sql .= ' OR ' . $classname . '.' . $searchField . ' != ""';

                if ($this->model->$searchField === 0) {
                    $sql .= ' OR ' . $classname . '.' . $searchField . ' != 0';
                }

                $sql .= ')';
            } else {
                if (strpos($searchValues, '|')) {
                    $searchValues = explode('|', $searchValues);
                } else {
                    $searchValues = [$searchValues];
                }

                foreach ($searchValues as $vKey => $value) {
                    if ((in_array($searchField, $textFields)
                        && preg_match('#^%[^%]+%|%[^%]+|[^%]+%$#i', $value))
                        || $value == '%%'
                    ) {
                        $operator = 'LIKE';
                    }

                    if (!$vKey) {
                        $sql .= ' ' . $andOr . ' (' . $classname . '.' . $searchField . ' ' . $operator . ' :f' . $searchField . $fKey . $vKey;
                    } else {
                        $sql .= ' OR ' . $classname . '.' . $searchField . ' ' . $operator . ' :f' . $searchField . $fKey . $vKey;
                    }

                    $this->bindParamsKeys[] = 'f' . $searchField . $fKey . $vKey;
                    $this->bindParamsValues[] = $value;
                }

                $sql .= ')';
            }
        }

        return $sql;
    }
private function prepareNormalSql(array $searchCriteria, string $classname, string $andOr, int $fKey): string
    {
        $sql = '';
        $textFields = $this->getTextFields($classname);
        list($searchField, $operator, $searchValues) = $searchCriteria;
        $operator = $this->operators[$operator];

        if (trim($searchValues) !== '') {
            if ($searchValues == '%%') {
                $sql .= ' ' . $andOr . ' (' . $classname . '.' . $searchField . ' IS NULL';
                $sql .= ' OR ' . $classname . '.' . $searchField . ' = ""';

                if ($this->model->$searchField === 0) {
                    $sql .= ' OR ' . $classname . '.' . $searchField . ' = 0';
                }

                $sql .= ')';
            } elseif ($searchValues == '$$') {
                $sql .= ' ' . $andOr . ' (' . $classname . '.' . $searchField . ' IS NOT NULL';
                $sql .= ' OR ' . $classname . '.' . $searchField . ' != ""';

                if ($this->model->$searchField === 0) {
                    $sql .= ' OR ' . $classname . '.' . $searchField . ' != 0';
                }

                $sql .= ')';
            } else {
                if (strpos($searchValues, '|')) {
                    $searchValues = explode('|', $searchValues);
                } else {
                    $searchValues = [$searchValues];
                }

                foreach ($searchValues as $vKey => $value) {
                    if ((in_array($searchField, $textFields)
                        && preg_match('#^%[^%]+%|%[^%]+|[^%]+%$#i', $value))
                        || $value == '%%'
                    ) {
                        $operator = 'LIKE';
                    }

                    if (!$vKey) {
                        $sql .= ' ' . $andOr . ' (' . $classname . '.' . $searchField . ' ' . $operator . ' :f' . $searchField . $fKey . $vKey;
                    } else {
                        $sql .= ' OR ' . $classname . '.' . $searchField . ' ' . $operator . ' :f' . $searchField . $fKey . $vKey;
                    }

                    $this->bindParamsKeys[] = 'f' . $searchField . $fKey . $vKey;
                    $this->bindParamsValues[] = $value;
                }

                $sql .= ')';
            }
        }

        return $sql;
    }
private function prepareNormalSql ( array $ searchCriteria , string $ classname , string $ andOr , int $ fKey ) : string { $ sql = '' ; $ textFields = $ this -> getTextFields ( $ classname ) ; list ( $ searchField , $ operator , $ searchValues ) = $ searchCriteria ; $ operator = $ this -> operators [ $ operator ] ; if ( trim ( $ searchValues ) !== '' ) { if ( $ searchValues == '%%' ) { $ sql .= ' ' . $ andOr . ' (' . $ classname . '.' . $ searchField . ' IS NULL' ; $ sql .= ' OR ' . $ classname . '.' . $ searchField . ' = ""' ; if ( $ this -> model -> $ searchField === 0 ) { $ sql .= ' OR ' . $ classname . '.' . $ searchField . ' = 0' ; } $ sql .= ')' ; } elseif ( $ searchValues == '$$' ) { $ sql .= ' ' . $ andOr . ' (' . $ classname . '.' . $ searchField . ' IS NOT NULL' ; $ sql .= ' OR ' . $ classname . '.' . $ searchField . ' != ""' ; if ( $ this -> model -> $ searchField === 0 ) { $ sql .= ' OR ' . $ classname . '.' . $ searchField . ' != 0' ; } $ sql .= ')' ; } else { if ( strpos ( $ searchValues , '|' ) ) { $ searchValues = explode ( '|' , $ searchValues ) ; } else { $ searchValues = [ $ searchValues ] ; } foreach ( $ searchValues as $ vKey => $ value ) { if ( ( in_array ( $ searchField , $ textFields ) && preg_match ( '#^%[^%]+%|%[^%]+|[^%]+%$#i' , $ value ) ) || $ value == '%%' ) { $ operator = 'LIKE' ; } if ( ! $ vKey ) { $ sql .= ' ' . $ andOr . ' (' . $ classname . '.' . $ searchField . ' ' . $ operator . ' :f' . $ searchField . $ fKey . $ vKey ; } else { $ sql .= ' OR ' . $ classname . '.' . $ searchField . ' ' . $ operator . ' :f' . $ searchField . $ fKey . $ vKey ; } $ this -> bindParamsKeys [ ] = 'f' . $ searchField . $ fKey . $ vKey ; $ this -> bindParamsValues [ ] = $ value ; } $ sql .= ')' ; } } return $ sql ; }
Prepare the SQL for a normal search.

@param array $searchCriteria
@param string $classname
@param string $andOr
@param int $fKey

@return string
Prepare the SQL for a normal search .