CRM_Core_OptionGroup
in package
Tags
Table of Contents
Properties
- $_cache : mixed
- $_domainIDGroups : array<string|int, mixed>
- $_domainIDGroups array maintains the list of option groups for whom domainID is to be considered.
- $_values : mixed
Methods
- createAssoc() : int
- Creates a new option group with the passed in values.
- deleteAssoc() : mixed
- flush() : mixed
- Wrapper for calling values with fresh set to true to empty the given value.
- flushAll() : mixed
- Flush all the places where option values are cached.
- getAssoc() : mixed
- getDefaultValue() : string
- Get option_value.value from default option_value row for an option group
- getRowValues() : array<string|int, mixed>
- isDomainOptionGroup() : bool
- lookupValues() : mixed
- Lookup titles OR ids for a set of option_value populated fields. The retrieved value is assigned a new field name by id or id's by title (each within a specified option_group).
- values() : array<string|int, mixed>
- This function retrieves all the values for the specific option group by name this is primarily used to create various html based form elements (radio, select, checkbox etc). OptionGroups for most cases have the 'label' in the label column and the 'id' or 'name' in the value column
- valuesByID() : array<string|int, mixed>
- This function retrieves all the values for the specific option group by id.
- valuesCommon() : array<string|int, mixed>
- createCacheKey() : string
- flushValues() : mixed
- Counterpart to values() which removes the item from the cache
Properties
$_cache
public
static mixed
$_cache
= []
$_domainIDGroups
$_domainIDGroups array maintains the list of option groups for whom domainID is to be considered.
public
static array<string|int, mixed>
$_domainIDGroups
= ['from_email_address', 'grant_type']
FIXME: Hardcoded list = bad. It would be better to make this a column in the civicrm_option_group table
$_values
public
static mixed
$_values
= []
Methods
createAssoc()
Creates a new option group with the passed in values.
public
static createAssoc(string $groupName, array<string|int, mixed> &$values, int &$defaultID[, null $groupTitle = NULL ]) : int
Parameters
- $groupName : string
-
The name of the option group - make sure there is no conflict.
- $values : array<string|int, mixed>
-
The associative array that has information on the option values. the keys of this array are: string 'title' (required) string 'value' (required) string 'name' (optional) string 'description' (optional) int 'weight' (optional) - the order in which the value are displayed bool 'is_default' (optional) - is this the default one to display when rendered in form bool 'is_active' (optional) - should this element be rendered
- $defaultID : int
-
(reference) - the option value ID of the default element (if set) is returned else 'null'.
- $groupTitle : null = NULL
-
The optional label of the option group else set to group name.
Return values
int —the option group ID
deleteAssoc()
public
static deleteAssoc(string $groupName[, string $operator = "=" ]) : mixed
Parameters
- $groupName : string
- $operator : string = "="
flush()
Wrapper for calling values with fresh set to true to empty the given value.
public
static flush(string $name[, array<string|int, mixed> $params = [] ]) : mixed
Since there appears to be some inconsistency (@todo remove inconsistency) around the pseudoconstant operations (for example CRM_Contribution_Pseudoconstant::paymentInstrument doesn't specify isActive which is part of the cache key will do a couple of variations & aspire to someone cleaning it up later
Parameters
- $name : string
- $params : array<string|int, mixed> = []
flushAll()
Flush all the places where option values are cached.
public
static flushAll() : mixed
Note that this is called from CRM_Core_PseudoConstant::flush() so we should resist the intuitive urge to flush that class.
getAssoc()
public
static getAssoc(string $groupName, mixed &$values[, bool $flip = FALSE ][, string $field = 'name' ]) : mixed
Parameters
- $groupName : string
- $values : mixed
- $flip : bool = FALSE
- $field : string = 'name'
getDefaultValue()
Get option_value.value from default option_value row for an option group
public
static getDefaultValue(string $groupName) : string
Parameters
- $groupName : string
-
The name of the option group.
Return values
string —the value from the row where is_default = true
getRowValues()
public
static getRowValues(string $groupName, mixed $fieldValue[, string $field = 'name' ][, string $fieldType = 'String' ][, bool $active = TRUE ][, bool $localize = FALSE ]) : array<string|int, mixed>
Parameters
- $groupName : string
- $fieldValue : mixed
- $field : string = 'name'
- $fieldType : string = 'String'
- $active : bool = TRUE
- $localize : bool = FALSE
-
if true, localize the results before returning.
Return values
array<string|int, mixed>isDomainOptionGroup()
public
static isDomainOptionGroup(mixed $groupName) : bool
Parameters
- $groupName : mixed
Return values
boollookupValues()
Lookup titles OR ids for a set of option_value populated fields. The retrieved value is assigned a new field name by id or id's by title (each within a specified option_group).
public
static lookupValues(array<string|int, mixed> &$params, array<string|int, mixed> $names[, bool $flip = FALSE ]) : mixed
Parameters
- $params : array<string|int, mixed>
-
Reference array of values submitted by the form. Based on. $flip, creates new elements in $params for each field in the $names array. If $flip = false, adds root field name => title If $flip = true, adds actual field name => id
- $names : array<string|int, mixed>
-
Array of field names we want transformed. Array key = 'postName' (field name submitted by form in $params). Array value = array('newName' => $newName, 'groupName' => $groupName).
- $flip : bool = FALSE
values()
This function retrieves all the values for the specific option group by name this is primarily used to create various html based form elements (radio, select, checkbox etc). OptionGroups for most cases have the 'label' in the label column and the 'id' or 'name' in the value column
public
static & values(string $name[, bool $flip = FALSE ][, bool $grouping = FALSE ][, bool $localize = FALSE ][, string $condition = NULL ][, string $labelColumnName = 'label' ][, bool $onlyActive = TRUE ][, bool $fresh = FALSE ][, string $keyColumnName = 'value' ][, string $orderBy = 'weight' ]) : array<string|int, mixed>
Parameters
- $name : string
-
name of the option group.
- $flip : bool = FALSE
-
results are return in id => label format if false. if true, the results are reversed
- $grouping : bool = FALSE
-
if true, return the value in 'grouping' column.
- $localize : bool = FALSE
-
if true, localize the results before returning.
- $condition : string = NULL
-
add another condition to the sql query.
- $labelColumnName : string = 'label'
-
the column to use for 'label'.
- $onlyActive : bool = TRUE
-
return only the action option values.
- $fresh : bool = FALSE
-
ignore cache entries and go back to DB.
- $keyColumnName : string = 'value'
-
the column to use for 'key'.
- $orderBy : string = 'weight'
-
the column to use for ordering.
Return values
array<string|int, mixed> —The values as specified by the params
valuesByID()
This function retrieves all the values for the specific option group by id.
public
static & valuesByID(int $id[, bool $flip = FALSE ][, bool $grouping = FALSE ][, bool $localize = FALSE ][, string $labelColumnName = 'label' ][, bool $onlyActive = TRUE ][, bool $fresh = FALSE ]) : array<string|int, mixed>
this is primarily used to create various html based form elements (radio, select, checkbox etc). OptionGroups for most cases have the 'label' in the label column and the 'id' or 'name' in the value column
Parameters
- $id : int
-
id of the option group.
- $flip : bool = FALSE
-
results are return in id => label format if false. if true, the results are reversed
- $grouping : bool = FALSE
-
if true, return the value in 'grouping' column.
- $localize : bool = FALSE
-
if true, localize the results before returning.
- $labelColumnName : string = 'label'
-
the column to use for 'label'.
- $onlyActive : bool = TRUE
- $fresh : bool = FALSE
Tags
Return values
array<string|int, mixed> —Array of values as specified by the above params
valuesCommon()
public
static & valuesCommon(CRM_Core_DAO $dao[, bool $flip = FALSE ][, bool $grouping = FALSE ][, bool $localize = FALSE ][, string $valueColumnName = 'label' ]) : array<string|int, mixed>
Parameters
- $dao : CRM_Core_DAO
- $flip : bool = FALSE
- $grouping : bool = FALSE
- $localize : bool = FALSE
- $valueColumnName : string = 'label'
Return values
array<string|int, mixed>createCacheKey()
protected
static createCacheKey(mixed $id) : string
Parameters
- $id : mixed
Return values
stringflushValues()
Counterpart to values() which removes the item from the cache
protected
static flushValues(string $name, mixed $flip, mixed $grouping, mixed $localize, mixed $condition, string $labelColumnName, mixed $onlyActive[, string $keyColumnName = 'value' ]) : mixed
Parameters
- $name : string
- $flip : mixed
- $grouping : mixed
- $localize : mixed
- $condition : mixed
- $labelColumnName : string
- $onlyActive : mixed
- $keyColumnName : string = 'value'