Prado\Data\DataGateway\TSqlCriteria::setCondition PHP Method

setCondition() public method

Sets the search conditions to be placed after the WHERE clause in the SQL.
public setCondition ( $value )
    public function setCondition($value)
    {
        if (empty($value)) {
            // reset the condition
            $this->_condition = null;
            return;
        }
        // supporting the following SELECT-syntax:
        // [ORDER BY {col_name | expr | position}
        //      [ASC | DESC], ...]
        //    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
        // See: http://dev.mysql.com/doc/refman/5.0/en/select.html
        if (preg_match('/ORDER\\s+BY\\s+(.*?)(?=LIMIT)|ORDER\\s+BY\\s+(.*?)$/i', $value, $matches) > 0) {
            // condition contains ORDER BY
            $value = str_replace($matches[0], '', $value);
            if (strlen($matches[1]) > 0) {
                $this->setOrdersBy($matches[1]);
            } else {
                if (strlen($matches[2]) > 0) {
                    $this->setOrdersBy($matches[2]);
                }
            }
        }
        if (preg_match('/LIMIT\\s+([\\d\\s,]+)/i', $value, $matches) > 0) {
            // condition contains limit
            $value = str_replace($matches[0], '', $value);
            // remove limit from query
            if (strpos($matches[1], ',')) {
                // both offset and limit given
                list($offset, $limit) = explode(',', $matches[1]);
                $this->_limit = (int) $limit;
                $this->_offset = (int) $offset;
            } else {
                // only limit given
                $this->_limit = (int) $matches[1];
            }
        }
        if (preg_match('/OFFSET\\s+(\\d+)/i', $value, $matches) > 0) {
            // condition contains offset
            $value = str_replace($matches[0], '', $value);
            // remove offset from query
            $this->_offset = (int) $matches[1];
            // set offset in criteria
        }
        $this->_condition = trim($value);
    }