src/QueryParser.php
protected function prepareSearch(array $unparsed, bool $isSearch = false, $hasSubquery = false): array
    {
        $statement = [
            'conditions' => "1 = 1",
            'bind' => [],
        ];

        if ($isSearch) {
            $mapped = $this->parseSearchParameters($unparsed['params']);
            $conditions = '1 = 1';

            $tmpMapped = $mapped;

            foreach ($tmpMapped as $key => $value) {
                if (strpos($value, '~') !== false) {
                    unset($tmpMapped[$key]);
                    $betweenMap[$key] = explode('~', $value);
                }
            }

            $keys = array_keys($tmpMapped);
            $values = array_values($tmpMapped);

            $di = Di::getDefault();

            foreach ($keys as $key => $field) {
                if ($di->get('config')->database->adapter == 'Postgresql') {
	       	           $conditions .= " AND CAST({$field} AS TEXT) LIKE ?{$key}";
    	    	}
    	        else {
    	    	    $conditions .= " AND {$field} LIKE ?{$key}";
    	    	}
            }

            if (isset($betweenMap)) {
                foreach ($betweenMap as $key => $fields) {
                    $binds = count($values);
                    $conditions .= ' AND ' . $key . ' BETWEEN ?' . $binds . ' AND ?' . ($binds + 1);
                    $values = array_merge($values, $fields);
                }
            }

            if ($hasSubquery) {
                $subquery = $this->parseSubquery($unparsed['subquery']);
                $conditions .= ' AND ' . $subquery['firstField'] . ' ' . $subquery['action'] . ' (select ' . $subquery['secondField'] . ' FROM ' . $subquery['model'] . ')';
            }

            $statement = [
                'conditions' => $conditions,
                'bind' => $values,
            ];
        }

        return $statement;
    }
protected function prepareSearch(array $unparsed, bool $isSearch = false, $hasSubquery = false): array
    {
        $statement = [
            'conditions' => "1 = 1",
            'bind' => [],
        ];

        if ($isSearch) {
            $mapped = $this->parseSearchParameters($unparsed['params']);
            $conditions = '1 = 1';

            $tmpMapped = $mapped;

            foreach ($tmpMapped as $key => $value) {
                if (strpos($value, '~') !== false) {
                    unset($tmpMapped[$key]);
                    $betweenMap[$key] = explode('~', $value);
                }
            }

            $keys = array_keys($tmpMapped);
            $values = array_values($tmpMapped);

            $di = Di::getDefault();

            foreach ($keys as $key => $field) {
                if ($di->get('config')->database->adapter == 'Postgresql') {
	       	           $conditions .= " AND CAST({$field} AS TEXT) LIKE ?{$key}";
    	    	}
    	        else {
    	    	    $conditions .= " AND {$field} LIKE ?{$key}";
    	    	}
            }

            if (isset($betweenMap)) {
                foreach ($betweenMap as $key => $fields) {
                    $binds = count($values);
                    $conditions .= ' AND ' . $key . ' BETWEEN ?' . $binds . ' AND ?' . ($binds + 1);
                    $values = array_merge($values, $fields);
                }
            }

            if ($hasSubquery) {
                $subquery = $this->parseSubquery($unparsed['subquery']);
                $conditions .= ' AND ' . $subquery['firstField'] . ' ' . $subquery['action'] . ' (select ' . $subquery['secondField'] . ' FROM ' . $subquery['model'] . ')';
            }

            $statement = [
                'conditions' => $conditions,
                'bind' => $values,
            ];
        }

        return $statement;
    }
protected function prepareSearch ( array $ unparsed , bool $ isSearch = false , $ hasSubquery = false ) : array { $ statement = [ 'conditions' => "1 = 1" , 'bind' => [ ] , ] ; if ( $ isSearch ) { $ mapped = $ this -> parseSearchParameters ( $ unparsed [ 'params' ] ) ; $ conditions = '1 = 1' ; $ tmpMapped = $ mapped ; foreach ( $ tmpMapped as $ key => $ value ) { if ( strpos ( $ value , '~' ) !== false ) { unset ( $ tmpMapped [ $ key ] ) ; $ betweenMap [ $ key ] = explode ( '~' , $ value ) ; } } $ keys = array_keys ( $ tmpMapped ) ; $ values = array_values ( $ tmpMapped ) ; $ di = Di :: getDefault ( ) ; foreach ( $ keys as $ key => $ field ) { if ( $ di -> get ( 'config' ) -> database -> adapter == 'Postgresql' ) { $ conditions .= " AND CAST({$field} AS TEXT) LIKE ?{$key}" ; } else { $ conditions .= " AND {$field} LIKE ?{$key}" ; } } if ( isset ( $ betweenMap ) ) { foreach ( $ betweenMap as $ key => $ fields ) { $ binds = count ( $ values ) ; $ conditions .= ' AND ' . $ key . ' BETWEEN ?' . $ binds . ' AND ?' . ( $ binds + 1 ) ; $ values = array_merge ( $ values , $ fields ) ; } } if ( $ hasSubquery ) { $ subquery = $ this -> parseSubquery ( $ unparsed [ 'subquery' ] ) ; $ conditions .= ' AND ' . $ subquery [ 'firstField' ] . ' ' . $ subquery [ 'action' ] . ' (select ' . $ subquery [ 'secondField' ] . ' FROM ' . $ subquery [ 'model' ] . ')' ; } $ statement = [ 'conditions' => $ conditions , 'bind' => $ values , ] ; } return $ statement ; }
Prepare conditions to search in record

@param  string $unparsed
@return array
Prepare conditions to search in record