private function parseWhereParameter($key, $value, $fieldtype = false)
    {
        $value = trim($value);

        // check if we need to split.
        if (strpos($value, " || ") !== false) {
            $values = explode(" || ", $value);
            foreach ($values as $index => $value) {
                $values[$index] = $this->parseWhereParameter($key, $value, $fieldtype);
            }

            return "( " . implode(" OR ", $values) . " )";
        } elseif (strpos($value, " && ") !== false) {
            $values = explode(" && ", $value);
            foreach ($values as $index => $value) {
                $values[$index] = $this->parseWhereParameter($key, $value, $fieldtype);
            }

            return "( " . implode(" AND ", $values) . " )";
        }

        // Set the correct operator for the where clause
        $operator = "=";

        $first = substr($value, 0, 1);

        if ($first == "!") {
            $operator = "!=";
            $value = substr($value, 1);
        } elseif (substr($value, 0, 2) == "<=") {
            $operator = "<=";
            $value = substr($value, 2);
        } elseif (substr($value, 0, 2) == ">=") {
            $operator = ">=";
            $value = substr($value, 2);
        } elseif ($first == "<") {
            $operator = "<";
            $value = substr($value, 1);
        } elseif ($first == ">") {
            $operator = ">";
            $value = substr($value, 1);
        } elseif ($first == "%" || substr($value, -1) == "%") {
            $operator = "LIKE";
        }

        // Use strtotime to allow selections like "< last monday" or "this year"
        if (in_array($fieldtype, ['date', 'datetime']) && ($timestamp = strtotime($value)) !== false) {
            $value = date('Y-m-d H:i:s', $timestamp);
        }

        $parameter = sprintf("%s %s %s", $this->app['db']->quoteIdentifier($key), $operator, $this->app['db']->quote($value));

        return $parameter;
    }
private function parseWhereParameter($key, $value, $fieldtype = false)
    {
        $value = trim($value);

        // check if we need to split.
        if (strpos($value, " || ") !== false) {
            $values = explode(" || ", $value);
            foreach ($values as $index => $value) {
                $values[$index] = $this->parseWhereParameter($key, $value, $fieldtype);
            }

            return "( " . implode(" OR ", $values) . " )";
        } elseif (strpos($value, " && ") !== false) {
            $values = explode(" && ", $value);
            foreach ($values as $index => $value) {
                $values[$index] = $this->parseWhereParameter($key, $value, $fieldtype);
            }

            return "( " . implode(" AND ", $values) . " )";
        }

        // Set the correct operator for the where clause
        $operator = "=";

        $first = substr($value, 0, 1);

        if ($first == "!") {
            $operator = "!=";
            $value = substr($value, 1);
        } elseif (substr($value, 0, 2) == "<=") {
            $operator = "<=";
            $value = substr($value, 2);
        } elseif (substr($value, 0, 2) == ">=") {
            $operator = ">=";
            $value = substr($value, 2);
        } elseif ($first == "<") {
            $operator = "<";
            $value = substr($value, 1);
        } elseif ($first == ">") {
            $operator = ">";
            $value = substr($value, 1);
        } elseif ($first == "%" || substr($value, -1) == "%") {
            $operator = "LIKE";
        }

        // Use strtotime to allow selections like "< last monday" or "this year"
        if (in_array($fieldtype, ['date', 'datetime']) && ($timestamp = strtotime($value)) !== false) {
            $value = date('Y-m-d H:i:s', $timestamp);
        }

        $parameter = sprintf("%s %s %s", $this->app['db']->quoteIdentifier($key), $operator, $this->app['db']->quote($value));

        return $parameter;
    }
private function parseWhereParameter ( $ key , $ value , $ fieldtype = false ) { $ value = trim ( $ value ) ; // check if we need to split. if ( strpos ( $ value , " || " ) !== false ) { $ values = explode ( " || " , $ value ) ; foreach ( $ values as $ index => $ value ) { $ values [ $ index ] = $ this -> parseWhereParameter ( $ key , $ value , $ fieldtype ) ; } return "( " . implode ( " OR " , $ values ) . " )" ; } elseif ( strpos ( $ value , " && " ) !== false ) { $ values = explode ( " && " , $ value ) ; foreach ( $ values as $ index => $ value ) { $ values [ $ index ] = $ this -> parseWhereParameter ( $ key , $ value , $ fieldtype ) ; } return "( " . implode ( " AND " , $ values ) . " )" ; } // Set the correct operator for the where clause $ operator = "=" ; $ first = substr ( $ value , 0 , 1 ) ; if ( $ first == "!" ) { $ operator = "!=" ; $ value = substr ( $ value , 1 ) ; } elseif ( substr ( $ value , 0 , 2 ) == "<=" ) { $ operator = "<=" ; $ value = substr ( $ value , 2 ) ; } elseif ( substr ( $ value , 0 , 2 ) == ">=" ) { $ operator = ">=" ; $ value = substr ( $ value , 2 ) ; } elseif ( $ first == "<" ) { $ operator = "<" ; $ value = substr ( $ value , 1 ) ; } elseif ( $ first == ">" ) { $ operator = ">" ; $ value = substr ( $ value , 1 ) ; } elseif ( $ first == "%" || substr ( $ value , - 1 ) == "%" ) { $ operator = "LIKE" ; } // Use strtotime to allow selections like "< last monday" or "this year" if ( in_array ( $ fieldtype , [ 'date' , 'datetime' ] ) && ( $ timestamp = strtotime ( $ value ) ) !== false ) { $ value = date ( 'Y-m-d H:i:s' , $ timestamp ) ; } $ parameter = sprintf ( "%s %s %s" , $ this -> app [ 'db' ] -> quoteIdentifier ( $ key ) , $ operator , $ this -> app [ 'db' ] -> quote ( $ value ) ) ; return $ parameter ; }
Helper function to set the proper 'where' parameter,
when getting values like '<2012' or '!bob'.

@param string $key
@param string $value
@param mixed  $fieldtype

@return string
Helper function to set the proper where parameter when getting values like <2012 or !bob .