SelectQuery
in package
Query builder for civicrm_api_basic_get.
Fetches an entity based on specified params for the "where" clause, return properties for the "select" clause, as well as limit and order.
Automatically joins on custom fields to return or filter by them.
Supports an additional sql fragment which the calling api can provide.
Table of Contents
Constants
- MAIN_TABLE_ALIAS = 'a'
- MAX_JOINS = 4
Properties
- $isFillUniqueFields : bool
- $limit : mixed
- $offset : mixed
- $orderBy : mixed
- $select : mixed
- $where : mixed
- $aclFields : array<string|int, mixed>
- $apiFieldSpec : array<string|int, mixed>
- $apiVersion : mixed
- $checkPermissions : string|bool
- $entity : string
- $entityFieldNames : array<string|int, mixed>
- $joins : array<string|int, mixed>
- $query : CRM_Utils_SQL_Select
- $selectFields : array<string|int, mixed>
Methods
- __construct() : mixed
- getAclClause() : array<string|int, mixed>
- Get acl clause for an entity
- join() : mixed
- merge() : SelectQuery
- run() : array<string|int, mixed>|int
- Build & execute the query and return results array
- addCustomField() : array<string|int, mixed>
- Joins onto a custom field
- addFkField() : array<string|int, mixed>|null
- Joins onto an fk field
- buildOrderBy() : mixed
- Orders the query by one or more fields
- buildSelectFields() : mixed
- Populate $this->selectFields
- buildWhereClause() : mixed
- Populate where clauses
- checkPermissionToJoin() : bool
- Check permission to join onto another api entity
- getField() : array<string|int, mixed>|null
- Fetch a field from the getFields list
- getFields() : array<string|int, mixed>
- Load entity fields
- getJoinInfo() : mixed
- Get join info for dynamically-joined fields (e.g. "entity_id", "option_group")
- validateNestedInput() : mixed
- Perform input validation on params that use the join syntax
Constants
MAIN_TABLE_ALIAS
public
mixed
MAIN_TABLE_ALIAS
= 'a'
MAX_JOINS
public
mixed
MAX_JOINS
= 4
Properties
$isFillUniqueFields
public
bool
$isFillUniqueFields
= FALSE
$limit
public
mixed
$limit
$offset
public
mixed
$offset
$orderBy
public
mixed
$orderBy
= []
$select
public
mixed
$select
= []
$where
public
mixed
$where
= []
$aclFields
protected
array<string|int, mixed>
$aclFields
= []
$apiFieldSpec
protected
array<string|int, mixed>
$apiFieldSpec
$apiVersion
protected
mixed
$apiVersion
$checkPermissions
protected
string|bool
$checkPermissions
$entity
protected
string
$entity
$entityFieldNames
protected
array<string|int, mixed>
$entityFieldNames
= []
$joins
protected
array<string|int, mixed>
$joins
= []
$query
protected
CRM_Utils_SQL_Select
$query
$selectFields
protected
array<string|int, mixed>
$selectFields
= []
Methods
__construct()
public
__construct(string $entity, bool $checkPermissions) : mixed
Parameters
- $entity : string
- $checkPermissions : bool
Tags
getAclClause()
Get acl clause for an entity
public
getAclClause(string $tableAlias, CRM_Core_DAO|string $baoName[, array<string|int, mixed> $stack = [] ]) : array<string|int, mixed>
Parameters
- $tableAlias : string
- $baoName : CRM_Core_DAO|string
- $stack : array<string|int, mixed> = []
Return values
array<string|int, mixed>join()
public
join(string $side, string $tableName, string $tableAlias, array<string|int, mixed> $conditions) : mixed
Parameters
- $side : string
- $tableName : string
- $tableAlias : string
- $conditions : array<string|int, mixed>
merge()
public
merge(CRM_Utils_SQL_Select $sqlFragment) : SelectQuery
Parameters
- $sqlFragment : CRM_Utils_SQL_Select
Return values
SelectQueryrun()
Build & execute the query and return results array
public
run() : array<string|int, mixed>|int
Tags
Return values
array<string|int, mixed>|intaddCustomField()
Joins onto a custom field
protected
addCustomField(array<string|int, mixed> $customField, string $side[, string $baseTable = self::MAIN_TABLE_ALIAS ]) : array<string|int, mixed>
Adds a join to the query to make this field available for use in a clause.
Parameters
- $customField : array<string|int, mixed>
- $side : string
- $baseTable : string = self::MAIN_TABLE_ALIAS
Return values
array<string|int, mixed> —Returns the table and field name for adding this field to a SELECT or WHERE clause
addFkField()
Joins onto an fk field
protected
addFkField(mixed $fkFieldName, mixed $side) : array<string|int, mixed>|null
Adds one or more joins to the query to make this field available for use in a clause.
Enforces permissions at the api level and by appending the acl clause for that entity to the join.
Parameters
- $fkFieldName : mixed
- $side : mixed
Tags
Return values
array<string|int, mixed>|null —Returns the table and field name for adding this field to a SELECT or WHERE clause
buildOrderBy()
Orders the query by one or more fields
protected
buildOrderBy() : mixed
Tags
buildSelectFields()
Populate $this->selectFields
protected
buildSelectFields() : mixed
Tags
buildWhereClause()
Populate where clauses
protected
abstract buildWhereClause() : mixed
Tags
checkPermissionToJoin()
Check permission to join onto another api entity
protected
checkPermissionToJoin(string $entity, array<string|int, mixed> $fieldStack) : bool
Parameters
- $entity : string
- $fieldStack : array<string|int, mixed>
-
The stack of fields leading up to this join
Return values
boolgetField()
Fetch a field from the getFields list
protected
abstract getField(string $fieldName) : array<string|int, mixed>|null
Parameters
- $fieldName : string
Return values
array<string|int, mixed>|nullgetFields()
Load entity fields
protected
abstract getFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getJoinInfo()
Get join info for dynamically-joined fields (e.g. "entity_id", "option_group")
protected
getJoinInfo(mixed &$fkField, mixed $stack) : mixed
Parameters
- $fkField : mixed
- $stack : mixed
validateNestedInput()
Perform input validation on params that use the join syntax
protected
validateNestedInput(mixed $fieldName, mixed &$value) : mixed
Arguably this should be done at the api wrapper level, but doing it here provides a bit more consistency in that api permissions to perform the join are checked first.
Parameters
- $fieldName : mixed
- $value : mixed