Documentation

QueryGenerator
in package

Query generator class.

Tags
copyright

YetiForce Sp. z o.o

license

YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)

author

Mariusz Krzaczkowski m.krzaczkowski@yetiforce.com

author

Radosław Skrzypczak r.skrzypczak@yetiforce.com

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
$advFilterList  : mixed
$buildedQuery  : Query
$concatColumn  : mixed
$conditions  : mixed
$conditionsAnd  : array<string|int, mixed>
$conditionsOr  : array<string|int, mixed>
$customColumns  : mixed
$cvColumns  : 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>
Search fields for duplicates.
$sourceRecord  : mixed
$stateCondition  : int
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.
getColumnName()  : string
Get column name by field name.
getCustomViewQueryById()  : Query
Get custom view query by id.
getDefaultCustomViewQuery()  : Query
Get default custom view query.
getEntityDefaultTableList()  : type
Get entity default table list.
getEntityModel()  : CRMEntity
Get CRMEntity Model.
getFields()  : array<string|int, Vtiger_Field_Model>
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()  : bool|Vtiger_Field_Model
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()  : bool|Vtiger_Field_Model
Get field in related module.
getRelatedModuleFields()  : array<string|int, Vtiger_Field_Model>
Get fields module.
initForCustomViewById()  : mixed
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()  : bool
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.
setConcatColumn()  : self
Set concat column.
setConditions()  : mixed
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.
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']

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

$conditionsAnd

private array<string|int, mixed> $conditionsAnd = []

Required conditions

$conditionsOr

private array<string|int, mixed> $conditionsOr = []

Optional conditions

$fieldsModel

private array<string|int, Vtiger_Field_Model> $fieldsModel

$relatedFieldsModel

private array<string|int, Vtiger_Field_Model> $relatedFieldsModel

$searchFieldsForDuplicates

Search fields for duplicates.

private array<string|int, mixed> $searchFieldsForDuplicates = []

$stateCondition

State records to display 0 - Active 1 - Trash 2 - Archived.

private int $stateCondition = 0

$tablesList

private array<string|int, string> $tablesList = []

Tables list

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
see
Condition::ADVANCED_FILTER_OPTIONS
see
Condition::DATE_OPERATORS
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>
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

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

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, Vtiger_Field_Model>
Return values
array<string|int, Vtiger_Field_Model>

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) : bool|Vtiger_Field_Model
Parameters
$fieldName : string
Return values
bool|Vtiger_Field_Model

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

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
throws
AppException
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) : bool|Vtiger_Field_Model
Parameters
$fieldName : string
$moduleName : string
Return values
bool|Vtiger_Field_Model

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>

initForCustomViewById()

Get custom view by id.

public initForCustomViewById(mixed $viewId[, bool $onlyFields = false ]) : mixed
Parameters
$viewId : mixed
$onlyFields : bool = false
Return values
mixed

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 ]) : bool
Parameters
$advFilterList : mixed = false
Return values
bool

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>

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) : mixed
Parameters
$conditions : array<string|int, mixed>
Return values
mixed

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|array<string|int, string> $fields) : self
Parameters
$fields : string|array<string|int, 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
throws
AppException
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
throws
AppException
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

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
Tags
throws
AppException
Return values
array<string|int, mixed>

        

Search results