protected function createCommonFindSql(array $criteria = array())
    {
        $params = array();

        $sql = 'FROM ' . $this->conn->quoteIdentifier($this->userTableName). ' ';
        // JOIN on custom fields, if needed.
        if (array_key_exists('customFields', $criteria)) {
            $i = 0;
            foreach ($criteria['customFields'] as $attribute => $value) {
                $i++;
                $alias = 'custom' . $i;
                $sql .= 'JOIN ' . $this->conn->quoteIdentifier($this->userCustomFieldsTableName). ' ' . $alias . ' ';
                $sql .= 'ON ' . $this->conn->quoteIdentifier($this->userTableName). '.' . $this->getUserColumns('id') . ' = ' . $alias . '.'. $this->getUserColumns('user_id').' ';
                $sql .= 'AND ' . $alias . '.'.$this->getUserColumns('attribute').' = :attribute' . $i . ' ';
                $sql .= 'AND ' . $alias . '.'.$this->getUserColumns('value').' = :value' . $i . ' ';
                $params['attribute' . $i] = $attribute;
                $params['value' . $i] = $value;
            }
        }

        $first_crit = true;
        foreach ($criteria as $key => $val) {
            if ($key == 'customFields') {
                continue;
            } else {
                $sql .= ($first_crit ? 'WHERE' : 'AND') . ' ' . $key . ' = :' . $key . ' ';
                $params[$key] = $val;
            }
            $first_crit = false;
        }

        return array ($sql, $params);
    }
protected function createCommonFindSql(array $criteria = array())
    {
        $params = array();

        $sql = 'FROM ' . $this->conn->quoteIdentifier($this->userTableName). ' ';
        // JOIN on custom fields, if needed.
        if (array_key_exists('customFields', $criteria)) {
            $i = 0;
            foreach ($criteria['customFields'] as $attribute => $value) {
                $i++;
                $alias = 'custom' . $i;
                $sql .= 'JOIN ' . $this->conn->quoteIdentifier($this->userCustomFieldsTableName). ' ' . $alias . ' ';
                $sql .= 'ON ' . $this->conn->quoteIdentifier($this->userTableName). '.' . $this->getUserColumns('id') . ' = ' . $alias . '.'. $this->getUserColumns('user_id').' ';
                $sql .= 'AND ' . $alias . '.'.$this->getUserColumns('attribute').' = :attribute' . $i . ' ';
                $sql .= 'AND ' . $alias . '.'.$this->getUserColumns('value').' = :value' . $i . ' ';
                $params['attribute' . $i] = $attribute;
                $params['value' . $i] = $value;
            }
        }

        $first_crit = true;
        foreach ($criteria as $key => $val) {
            if ($key == 'customFields') {
                continue;
            } else {
                $sql .= ($first_crit ? 'WHERE' : 'AND') . ' ' . $key . ' = :' . $key . ' ';
                $params[$key] = $val;
            }
            $first_crit = false;
        }

        return array ($sql, $params);
    }
protected function createCommonFindSql ( array $ criteria = array ( ) ) { $ params = array ( ) ; $ sql = 'FROM ' . $ this -> conn -> quoteIdentifier ( $ this -> userTableName ) . ' ' ; // JOIN on custom fields, if needed. if ( array_key_exists ( 'customFields' , $ criteria ) ) { $ i = 0 ; foreach ( $ criteria [ 'customFields' ] as $ attribute => $ value ) { $ i ++ ; $ alias = 'custom' . $ i ; $ sql .= 'JOIN ' . $ this -> conn -> quoteIdentifier ( $ this -> userCustomFieldsTableName ) . ' ' . $ alias . ' ' ; $ sql .= 'ON ' . $ this -> conn -> quoteIdentifier ( $ this -> userTableName ) . '.' . $ this -> getUserColumns ( 'id' ) . ' = ' . $ alias . '.' . $ this -> getUserColumns ( 'user_id' ) . ' ' ; $ sql .= 'AND ' . $ alias . '.' . $ this -> getUserColumns ( 'attribute' ) . ' = :attribute' . $ i . ' ' ; $ sql .= 'AND ' . $ alias . '.' . $ this -> getUserColumns ( 'value' ) . ' = :value' . $ i . ' ' ; $ params [ 'attribute' . $ i ] = $ attribute ; $ params [ 'value' . $ i ] = $ value ; } } $ first_crit = true ; foreach ( $ criteria as $ key => $ val ) { if ( $ key == 'customFields' ) { continue ; } else { $ sql .= ( $ first_crit ? 'WHERE' : 'AND' ) . ' ' . $ key . ' = :' . $ key . ' ' ; $ params [ $ key ] = $ val ; } $ first_crit = false ; } return array ( $ sql , $ params ) ; }
Get SQL query fragment common to both find and count querires.

@param array $criteria
@return array An array of SQL and query parameters, in the form array($sql, $params)
Get SQL query fragment common to both find and count querires .