Class for generating SQL clauses to filter a user query by xprofile data.

since 2.2.0
package BuddyPress

 Methods

Constructor.

__construct(array $xprofile_query) 
since 2.2.0

Parameters

$xprofile_query

array

{ Array of xprofile query clauses.

@type string $relation Optional. The MySQL keyword used to join the clauses of the query.
                       Accepts 'AND', or 'OR'. Default 'AND'.
@type array {
    Optional. An array of first-order clause parameters, or another fully-formed xprofile query.

    @type string|int $field   XProfile field to filter by. Accepts a field name or ID.
    @type string     $value   XProfile value to filter by.
    @type string     $compare MySQL operator used for comparing the $value. Accepts '=', '!=', '>',
                              '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN',
                              'NOT BETWEEN', 'REGEXP', 'NOT REGEXP', or 'RLIKE'. Default is 'IN'
                              when `$value` is an array, '=' otherwise.
    @type string     $type    MySQL data type that the `value` column will be CAST to for comparisons.
                              Accepts 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL',
                              'SIGNED', 'TIME', or 'UNSIGNED'. Default is 'CHAR'.
}

}

Return the appropriate alias for the given field type if applicable.

get_cast_for_type(string $type = '') : string
since 2.2.0

Parameters

$type

string

MySQL type to cast value.

Returns

stringMySQL type.

Generates SQL clauses to be appended to a main query.

get_sql(string $primary_table, string $primary_id_column) : array
since 2.2.0

Parameters

$primary_table

string

Database table where the object being filtered is stored (eg wp_users).

$primary_id_column

string

ID column for the filtered object in $primary_table.

Returns

array{ Array containing JOIN and WHERE SQL clauses to append to the main query. @type string $join SQL fragment to append to the main JOIN clause. @type string $where SQL fragment to append to the main WHERE clause. }

Generate SQL JOIN and WHERE clauses for a first-order query clause.

get_sql_for_clause(array $clause, array $parent_query) : array

"First-order" means that it's an array with a 'field' or 'value'.

since 2.2.0
global wpdb $wpdb WordPress database object.

Parameters

$clause

array

Query clause.

$parent_query

array

Parent query array.

Returns

array{ Array containing JOIN and WHERE SQL clauses to append to a first-order query. @type string $join SQL fragment to append to the main JOIN clause. @type string $where SQL fragment to append to the main WHERE clause. }

Ensure the `xprofile_query` argument passed to the class constructor is well-formed.

sanitize_query(array $queries) : array

Eliminates empty items and ensures that a 'relation' is set.

since 2.2.0

Parameters

$queries

array

Array of query clauses.

Returns

arraySanitized array of query clauses.

Identify an existing table alias that is compatible with the current query clause.

find_compatible_table_alias(array $clause, array $parent_query) : string | boolean

We avoid unnecessary table joins by allowing each clause to look for an existing table alias that is compatible with the query that it needs to perform. An existing alias is compatible if (a) it is a sibling of $clause (ie, it's under the scope of the same relation), and (b) the combination of operator and relation between the clauses allows for a shared table join. In the case of BP_XProfile_Query, this * only applies to IN clauses that are connected by the relation OR.

since 2.2.0

Parameters

$clause

array

Query clause.

$parent_query

array

Parent query of $clause.

Returns

stringbooleanTable alias if found, otherwise false.

Generate SQL clauses to be appended to a main query.

get_sql_clauses() : array

Called by the public \BP_XProfile_Query::get_sql(), this method is abstracted out to maintain parity with WP's Query classes.

since 2.2.0

Returns

array{ Array containing JOIN and WHERE SQL clauses to append to the main query. @type string $join SQL fragment to append to the main JOIN clause. @type string $where SQL fragment to append to the main WHERE clause. }

Generate SQL clauses for a single query array.

get_sql_for_query(array $query, integer $depth = 0) : array

If nested subqueries are found, this method recurses the tree to produce the properly nested SQL.

since 2.2.0

Parameters

$query

array

Query to parse. Passed by reference.

$depth

integer

Optional. Number of tree levels deep we currently are. Used to calculate indentation.

Returns

array{ Array containing JOIN and WHERE SQL clauses to append to a single query array. @type string $join SQL fragment to append to the main JOIN clause. @type string $where SQL fragment to append to the main WHERE clause. }

Determine whether a query clause is first-order.

is_first_order_clause(array $query) : boolean

A first-order query clause is one that has either a 'key' or a 'value' array key.

since 2.2.0

Parameters

$query

array

XProfile query arguments.

Returns

booleanWhether the query clause is a first-order clause.

 Properties

 

Column in primary_table that represents the ID of the object.

$primary_id_column : string

Default

since 2.2.0
 

Database table that where the metadata's objects are stored (eg $wpdb->users).

$primary_table : string

Default

since 2.2.0
 

Array of xprofile queries.

$queries : array

Default

array()

See \WP_XProfile_Query::__construct() for information on parameters.

since 2.2.0
 

A flat list of table aliases used in JOIN clauses.

$table_aliases : array

Default

array()
since 2.2.0