QueryGenerator
in package
Query generator class.
Table of Contents
- COMMA_TYPES = ['picklist', 'multipicklist', 'owner', 'date', 'datetime', 'time', 'tree', 'sharedOwner', 'sharedOwner']
- DATE_TYPE = ['date', 'datetime']
- EQUALITY_TYPES = ['currency', 'percentage', 'double', 'integer', 'number']
- NUMERIC_TYPE = ['integer', 'double', 'currency', 'currencyInventory']
- STRING_TYPE = ['string', 'text', 'email', 'reference']
- $permissions : bool
- $advancedConditions : array<string|int, mixed>
- $advFilterList : mixed
- $buildedQuery : Query
- $concatColumn : mixed
- $conditions : mixed
- $conditionsAnd : array<string|int, mixed>
- $conditionsOr : array<string|int, mixed>
- $customColumns : mixed
- $distinct : string|null
- $entityModel : CRMEntity
- $fields : mixed
- $fieldsModel : array<string|int, Vtiger_Field_Model>
- $group : mixed
- $ignoreComma : bool
- $joins : array<string|int, mixed>
- $limit : int|null
- $moduleModel : Vtiger_Module_Model
- $moduleName : string
- $offset : int|null
- $order : mixed
- $ownerFields : mixed
- $query : Query
- $queryFields : mixed
- $referenceFields : mixed
- $relatedFields : mixed
- $relatedFieldsModel : array<string|int, Vtiger_Field_Model>
- $relatedQueryFields : mixed
- $searchFieldsForDuplicates : array<string|int, mixed>
- $sourceRecord : mixed
- $stateCondition : int|null
- State records to display 0 - Active 1 - Trash 2 - Archived.
- $tablesList : array<string|int, string>
- $user : User
- __construct() : mixed
- QueryGenerator construct.
- addCondition() : $this
- Set condition.
- addJoin() : $this
- Appends a JOIN part to the query.
- addNativeCondition() : mixed
- Add a mandatory condition.
- addRelatedCondition() : mixed
- Set condition on reference module fields.
- addRelatedField() : self
- Set related field.
- addRelatedJoin() : bool|Vtiger_Field_Model
- Set related field join.
- addTableToQuery() : mixed
- Add table to query.
- clearFields() : self
- Clear fields.
- createQuery() : Query
- Create query.
- getAdvancedConditions() : array<string|int, mixed>
- Get advanced conditions.
- getColumnName() : string
- Get column name by field name.
- getCustomViewQueryById() : Query
- Get custom view query by id.
- getDefaultCustomViewQuery() : Query
- Get default custom view query.
- getDistinct() : string|null
- Get distinct column.
- getEntityDefaultTableList() : type
- Get entity default table list.
- getEntityModel() : CRMEntity
- Get CRMEntity Model.
- getFields() : array<string|int, string>
- Get query fields.
- getIgnoreComma() : bool
- Get ignore comma.
- getLimit() : mixed
- Get query limit.
- getListViewFields() : array<string|int, Vtiger_Field_Model>
- Get list view query fields.
- getModule() : string
- Get module name.
- getModuleField() : Vtiger_Field_Model|bool
- Get field module.
- getModuleFields() : array<string|int, mixed>
- Get fields module.
- getModuleModel() : Vtiger_Module_Model
- Get module model.
- getQueryField() : BaseField
- Get query field instance.
- getQueryRelatedField() : BaseField
- Get query related field instance.
- getReference() : array<string|int, mixed>
- Get reference fields.
- getRelatedFields() : array<string|int, mixed>
- Returns related fields.
- getRelatedModuleField() : Vtiger_Field_Model|bool
- Get field in related module.
- getRelatedModuleFields() : array<string|int, Vtiger_Field_Model>
- Get fields module.
- getState() : string
- Get records state.
- initForCustomViewById() : $this
- Get custom view by id.
- initForDefaultCustomView() : mixed
- Init function for default custom view.
- loadFrom() : mixed
- Sets the FROM part of the query.
- loadGroup() : mixed
- Sets the GROUP BY part of the query.
- loadJoin() : mixed
- Sets the JOINs part of the query.
- loadListFields() : mixed
- Load base module list fields.
- loadOrder() : mixed
- Sets the ORDER BY part of the query.
- loadRelatedFields() : array<string|int, mixed>
- Returns related fields for section SELECT.
- loadSelect() : mixed
- Sets the SELECT part of the query.
- loadWhere() : mixed
- Sets the WHERE part of the query.
- parseAdvFilter() : $this
- Parsing advanced filters conditions.
- parseBaseSearchParamsToCondition() : array<string|int, mixed>
- Parse base search condition to db condition.
- parseSearchParams() : array<string|int, mixed>
- Parse search condition to standard condition.
- setAdvancedConditions() : $this
- Set advanced conditions.
- setConcatColumn() : self
- Set concat column.
- setConditions() : $this
- Sets conditions from ConditionBuilder.
- setCustomColumn() : self
- Set custom column.
- setCustomGroup() : self
- Set custom group.
- setDistinct() : self
- Set distinct column.
- setField() : self
- Set query field.
- setFields() : self
- Set query fields.
- setGroup() : self
- Set group.
- setIgnoreComma() : mixed
- Set ignore comma.
- setLimit() : self
- Set query limit.
- setOffset() : self
- Set query offset.
- setOrder() : self
- Set order.
- setRelatedOrder() : mixed
- Set order for related module.
- setSearchFieldsForDuplicates() : mixed
- Function sets the field for which the duplicated values will be searched.
- setSourceRecord() : $this
- Set source record.
- setStateCondition() : $this
- Set state condition.
- addCustomViewFields() : mixed
- Add custom view fields from column.
- getCondition() : array<string|int, mixed>|bool
- Returns condition for field in this module.
- getRelatedCondition() : array<string|int, mixed>|bool
- Returns condition for field in related module.
- getStateCondition() : array<string|int, mixed>|string
- Get conditions for records state.
- loadAdvancedConditions() : void
- Load advanced conditions to section where in query.
- parseConditions() : array<string|int, mixed>
- Parse conditions to section where in query.
Constants
COMMA_TYPES
public
mixed
COMMA_TYPES
= ['picklist', 'multipicklist', 'owner', 'date', 'datetime', 'time', 'tree', 'sharedOwner', 'sharedOwner']
DATE_TYPE
public
mixed
DATE_TYPE
= ['date', 'datetime']
EQUALITY_TYPES
public
mixed
EQUALITY_TYPES
= ['currency', 'percentage', 'double', 'integer', 'number']
NUMERIC_TYPE
public
mixed
NUMERIC_TYPE
= ['integer', 'double', 'currency', 'currencyInventory']
STRING_TYPE
public
mixed
STRING_TYPE
= ['string', 'text', 'email', 'reference']
Properties
$permissions
public
bool
$permissions
= true
Permissions conditions
$advancedConditions
private
array<string|int, mixed>
$advancedConditions
= []
Advanced conditions
$advFilterList
private
mixed
$advFilterList
$buildedQuery
private
Query
$buildedQuery
$concatColumn
private
mixed
$concatColumn
= []
$conditions
private
mixed
$conditions
$conditionsAnd
private
array<string|int, mixed>
$conditionsAnd
= []
Required conditions
$conditionsOr
private
array<string|int, mixed>
$conditionsOr
= []
Optional conditions
$customColumns
private
mixed
$customColumns
= []
$distinct
private
string|null
$distinct
Distinct field
$entityModel
private
CRMEntity
$entityModel
$fields
private
mixed
$fields
= []
$fieldsModel
private
array<string|int, Vtiger_Field_Model>
$fieldsModel
$group
private
mixed
$group
= []
$ignoreComma
private
bool
$ignoreComma
= false
$joins
private
array<string|int, mixed>
$joins
= []
Joins
$limit
private
int|null
$limit
Limit
$moduleModel
private
Vtiger_Module_Model
$moduleModel
$moduleName
private
string
$moduleName
Module name
$offset
private
int|null
$offset
Offset
$order
private
mixed
$order
= []
$ownerFields
private
mixed
$ownerFields
= []
$query
private
Query
$query
$queryFields
private
mixed
$queryFields
= []
$referenceFields
private
mixed
$referenceFields
= []
$relatedFields
private
mixed
$relatedFields
= []
$relatedFieldsModel
private
array<string|int, Vtiger_Field_Model>
$relatedFieldsModel
$relatedQueryFields
private
mixed
$relatedQueryFields
= []
$searchFieldsForDuplicates
private
array<string|int, mixed>
$searchFieldsForDuplicates
= []
Search fields for duplicates.
$sourceRecord
private
mixed
$sourceRecord
$stateCondition
State records to display 0 - Active 1 - Trash 2 - Archived.
private
int|null
$stateCondition
= 0
$tablesList
private
array<string|int, string>
$tablesList
= []
Tables list
$user
private
User
$user
Methods
__construct()
QueryGenerator construct.
public
__construct(string $moduleName[, mixed $userId = false ]) : mixed
Parameters
- $moduleName : string
- $userId : mixed = false
Return values
mixed —addCondition()
Set condition.
public
addCondition(string $fieldName, mixed $value, string $operator[, mixed $groupAnd = true ][, bool $userFormat = false ]) : $this
Parameters
- $fieldName : string
- $value : mixed
- $operator : string
- $groupAnd : mixed = true
- $userFormat : bool = false
Tags
Return values
$this —addJoin()
Appends a JOIN part to the query.
public
addJoin(array<string|int, mixed> $join) : $this
Parameters
- $join : array<string|int, mixed>
Tags
Return values
$this —addNativeCondition()
Add a mandatory condition.
public
addNativeCondition(array<string|int, mixed> $condition[, bool $groupAnd = true ]) : mixed
Parameters
- $condition : array<string|int, mixed>
- $groupAnd : bool = true
Return values
mixed —addRelatedCondition()
Set condition on reference module fields.
public
addRelatedCondition(array<string|int, mixed> $condition) : mixed
Parameters
- $condition : array<string|int, mixed>
Return values
mixed —addRelatedField()
Set related field.
public
addRelatedField(array<string|int, string> $field) : self
Parameters
- $field : array<string|int, string>
Return values
self —addRelatedJoin()
Set related field join.
public
addRelatedJoin(array<string|int, string> $fieldDetail) : bool|Vtiger_Field_Model
Parameters
- $fieldDetail : array<string|int, string>
Return values
bool|Vtiger_Field_Model —addTableToQuery()
Add table to query.
public
addTableToQuery(string $tableName) : mixed
Parameters
- $tableName : string
Return values
mixed —clearFields()
Clear fields.
public
clearFields() : self
Return values
self —createQuery()
Create query.
public
createQuery([mixed $reBuild = false ]) : Query
Parameters
- $reBuild : mixed = false
Return values
Query —getAdvancedConditions()
Get advanced conditions.
public
getAdvancedConditions() : array<string|int, mixed>
Return values
array<string|int, mixed> —getColumnName()
Get column name by field name.
public
getColumnName(string $fieldName) : string
Parameters
- $fieldName : string
Return values
string —getCustomViewQueryById()
Get custom view query by id.
public
getCustomViewQueryById(int|string $viewId) : Query
Parameters
- $viewId : int|string
Return values
Query —getDefaultCustomViewQuery()
Get default custom view query.
public
getDefaultCustomViewQuery() : Query
Return values
Query —getDistinct()
Get distinct column.
public
getDistinct() : string|null
Return values
string|null —getEntityDefaultTableList()
Get entity default table list.
public
getEntityDefaultTableList() : type
Return values
type —getEntityModel()
Get CRMEntity Model.
public
getEntityModel() : CRMEntity
Return values
CRMEntity —getFields()
Get query fields.
public
getFields() : array<string|int, string>
Return values
array<string|int, string> —getIgnoreComma()
Get ignore comma.
public
getIgnoreComma() : bool
Return values
bool —getLimit()
Get query limit.
public
getLimit() : mixed
Return values
mixed —getListViewFields()
Get list view query fields.
public
getListViewFields() : array<string|int, Vtiger_Field_Model>
Return values
array<string|int, Vtiger_Field_Model> —getModule()
Get module name.
public
getModule() : string
Return values
string —getModuleField()
Get field module.
public
getModuleField(string $fieldName) : Vtiger_Field_Model|bool
Parameters
- $fieldName : string
Return values
Vtiger_Field_Model|bool —getModuleFields()
Get fields module.
public
getModuleFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —getModuleModel()
Get module model.
public
getModuleModel() : Vtiger_Module_Model
Return values
Vtiger_Module_Model —getQueryField()
Get query field instance.
public
getQueryField(string $fieldName) : BaseField
Parameters
- $fieldName : string
Tags
Return values
BaseField —getQueryRelatedField()
Get query related field instance.
public
getQueryRelatedField(array<string|int, mixed>|string $relatedInfo[, Vtiger_Field_Model $field = null ]) : BaseField
Parameters
- $relatedInfo : array<string|int, mixed>|string
- $field : Vtiger_Field_Model = null
Tags
Return values
BaseField —getReference()
Get reference fields.
public
getReference(string $fieldName) : array<string|int, mixed>
Parameters
- $fieldName : string
Return values
array<string|int, mixed> —getRelatedFields()
Returns related fields.
public
getRelatedFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —getRelatedModuleField()
Get field in related module.
public
getRelatedModuleField(string $fieldName, string $moduleName) : Vtiger_Field_Model|bool
Parameters
- $fieldName : string
- $moduleName : string
Return values
Vtiger_Field_Model|bool —getRelatedModuleFields()
Get fields module.
public
getRelatedModuleFields(string $moduleName) : array<string|int, Vtiger_Field_Model>
Parameters
- $moduleName : string
Return values
array<string|int, Vtiger_Field_Model> —getState()
Get records state.
public
getState() : string
Return values
string —initForCustomViewById()
Get custom view by id.
public
initForCustomViewById(mixed $viewId[, bool $onlyFields = false ]) : $this
Parameters
- $viewId : mixed
- $onlyFields : bool = false
Return values
$this —initForDefaultCustomView()
Init function for default custom view.
public
initForDefaultCustomView([bool $noCache = false ][, bool $onlyFields = false ]) : mixed
Parameters
- $noCache : bool = false
- $onlyFields : bool = false
Return values
mixed —loadFrom()
Sets the FROM part of the query.
public
loadFrom() : mixed
Return values
mixed —loadGroup()
Sets the GROUP BY part of the query.
public
loadGroup() : mixed
Return values
mixed —loadJoin()
Sets the JOINs part of the query.
public
loadJoin() : mixed
Return values
mixed —loadListFields()
Load base module list fields.
public
loadListFields() : mixed
Return values
mixed —loadOrder()
Sets the ORDER BY part of the query.
public
loadOrder() : mixed
Return values
mixed —loadRelatedFields()
Returns related fields for section SELECT.
public
loadRelatedFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —loadSelect()
Sets the SELECT part of the query.
public
loadSelect() : mixed
Return values
mixed —loadWhere()
Sets the WHERE part of the query.
public
loadWhere() : mixed
Return values
mixed —parseAdvFilter()
Parsing advanced filters conditions.
public
parseAdvFilter([mixed $advFilterList = false ]) : $this
Parameters
- $advFilterList : mixed = false
Return values
$this —parseBaseSearchParamsToCondition()
Parse base search condition to db condition.
public
parseBaseSearchParamsToCondition(array<string|int, mixed> $searchParams) : array<string|int, mixed>
Parameters
- $searchParams : array<string|int, mixed>
-
Example: [[["firstname","a","Tom"]]]
Return values
array<string|int, mixed> —parseSearchParams()
Parse search condition to standard condition.
public
parseSearchParams(array<string|int, mixed> $searchParams) : array<string|int, mixed>
Parameters
- $searchParams : array<string|int, mixed>
Return values
array<string|int, mixed> —setAdvancedConditions()
Set advanced conditions.
public
setAdvancedConditions(array<string|int, mixed> $advancedConditions) : $this
Parameters
- $advancedConditions : array<string|int, mixed>
Return values
$this —setConcatColumn()
Set concat column.
public
setConcatColumn(string $fieldName, string $concat) : self
Parameters
- $fieldName : string
- $concat : string
Return values
self —setConditions()
Sets conditions from ConditionBuilder.
public
setConditions(array<string|int, mixed> $conditions) : $this
Parameters
- $conditions : array<string|int, mixed>
Return values
$this —setCustomColumn()
Set custom column.
public
setCustomColumn(string|array<string|int, string> $columns) : self
Parameters
- $columns : string|array<string|int, string>
Return values
self —setCustomGroup()
Set custom group.
public
setCustomGroup(array<string|int, mixed>|string $groups) : self
Parameters
- $groups : array<string|int, mixed>|string
Return values
self —setDistinct()
Set distinct column.
public
setDistinct(string $columnName) : self
Parameters
- $columnName : string
Return values
self —setField()
Set query field.
public
setField(string $fieldName) : self
Parameters
- $fieldName : string
Return values
self —setFields()
Set query fields.
public
setFields(array<string|int, string> $fields) : self
Parameters
- $fields : array<string|int, string>
Return values
self —setGroup()
Set group.
public
setGroup(string $fieldName) : self
Parameters
- $fieldName : string
Return values
self —setIgnoreComma()
Set ignore comma.
public
setIgnoreComma(bool $val) : mixed
Parameters
- $val : bool
Return values
mixed —setLimit()
Set query limit.
public
setLimit(int $limit) : self
Parameters
- $limit : int
Return values
self —setOffset()
Set query offset.
public
setOffset(int $offset) : self
Parameters
- $offset : int
Return values
self —setOrder()
Set order.
public
setOrder(string $fieldName[, string $order = false ]) : self
Parameters
- $fieldName : string
- $order : string = false
-
ASC/DESC
Return values
self —setRelatedOrder()
Set order for related module.
public
setRelatedOrder(array<string|int, string> $orderDetail) : mixed
Parameters
- $orderDetail : array<string|int, string>
Return values
mixed —setSearchFieldsForDuplicates()
Function sets the field for which the duplicated values will be searched.
public
setSearchFieldsForDuplicates(string $fieldName[, bool|int $ignoreEmptyValue = true ]) : mixed
Parameters
- $fieldName : string
- $ignoreEmptyValue : bool|int = true
Return values
mixed —setSourceRecord()
Set source record.
public
setSourceRecord(int $sourceRecord) : $this
Parameters
- $sourceRecord : int
Return values
$this —setStateCondition()
Set state condition.
public
setStateCondition(string $state) : $this
Parameters
- $state : string
Return values
$this —addCustomViewFields()
Add custom view fields from column.
private
addCustomViewFields(array<string|int, string> $cvColumn) : mixed
Parameters
- $cvColumn : array<string|int, string>
Return values
mixed —getCondition()
Returns condition for field in this module.
private
getCondition(string $fieldName, mixed $value, string $operator[, bool $userFormat = false ]) : array<string|int, mixed>|bool
Parameters
- $fieldName : string
- $value : mixed
- $operator : string
- $userFormat : bool = false
Tags
Return values
array<string|int, mixed>|bool —getRelatedCondition()
Returns condition for field in related module.
private
getRelatedCondition(array<string|int, mixed> $condition) : array<string|int, mixed>|bool
Parameters
- $condition : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>|bool —getStateCondition()
Get conditions for records state.
private
getStateCondition() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|string —loadAdvancedConditions()
Load advanced conditions to section where in query.
private
loadAdvancedConditions() : void
Return values
void —parseConditions()
Parse conditions to section where in query.
private
parseConditions(array<string|int, mixed>|null $conditions) : array<string|int, mixed>
Parameters
- $conditions : array<string|int, mixed>|null