return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $id, 'label');
}
+ /**
+ * @param string $context
+ * @return array|bool
+ */
+ public function getOptions($context = 'get') {
+ CRM_Core_DAO::buildOptionsContext($context);
+ $options = FALSE;
+
+ if (!$this->id) {
+ return FALSE;
+ }
+ if (!$this->data_type || !$this->custom_group_id) {
+ $this->find(TRUE);
+ }
+
+ if (!empty($this->option_group_id)) {
+ $options = CRM_Core_OptionGroup::valuesByID(
+ $this->option_group_id,
+ FALSE,
+ FALSE,
+ FALSE,
+ 'label',
+ !($context == 'validate' || $context == 'get')
+ );
+ }
+ else {
+ if ($this->data_type === 'StateProvince') {
+ $options = CRM_Core_Pseudoconstant::stateProvince();
+ }
+ elseif ($this->data_type === 'Country') {
+ $options = $context == 'validate' ? CRM_Core_Pseudoconstant::countryIsoCode() : CRM_Core_Pseudoconstant::country();
+ }
+ elseif ($this->data_type === 'Boolean') {
+ $options = $context == 'validate' ? array(0, 1) : CRM_Core_SelectValues::boolean();
+ }
+ }
+ CRM_Utils_Hook::customFieldOptions($this->id, $options, FALSE);
+ $entity = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->custom_group_id, 'extends');
+ $entity = in_array($entity, array('Individual', 'Household', 'Organization')) ? 'Contact' : $entity;
+ CRM_Utils_Hook::fieldOptions($entity, "custom_{$this->id}", $options, array('context' => $context));
+ return $options;
+ }
+
/**
* Store and return an array of all active custom fields.
*
$attributes = &$option['attributes'];
$html_type = $attributes['html_type'];
$data_type = $attributes['data_type'];
+ // set $id as $fieldID if not passed in the params.
+ if (empty($fieldID)) {
+ $fieldID = $id;
+ }
return self::getDisplayValueCommon($value,
$option,
$customFields[$customFieldId]['html_type'] == 'AdvMulti-Select'
) {
if ($value) {
- // Note that only during merge this is not an array,
- // and you can directly use value, CRM-4385
- if (is_array($value)) {
- $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
- array_values($value)
- ) . CRM_Core_DAO::VALUE_SEPARATOR;
- }
+ $value = CRM_Utils_Array::implodePadded($value);
}
else {
$value = '';
* @param int $entityID
* @param string $customFieldExtends
* @param bool $inline
+ * @param bool $checkPermissions
*
* @return array
*/
&$params,
$entityID,
$customFieldExtends,
- $inline = FALSE
+ $inline = FALSE,
+ $checkPermissions = TRUE
) {
$customData = array();
$customFieldExtends,
$customFieldInfo[1],
$entityID,
- $inline
+ $inline,
+ $checkPermissions
);
}
}
}
/**
- * Build option.
*
- * @param array $field
- * @param array $options
- *
- * @throws Exception
*/
- public static function buildOption($field, &$options) {
- // Fixme - adding anything but options to the $options array is a bad idea
- // What if an option had the key 'attributes'?
- $options['attributes'] = array(
- 'label' => $field['label'],
- 'data_type' => $field['data_type'],
- 'html_type' => $field['html_type'],
- );
-
- $optionGroupID = NULL;
- if (($field['html_type'] == 'CheckBox' ||
- $field['html_type'] == 'Radio' ||
- $field['html_type'] == 'Select' ||
- $field['html_type'] == 'AdvMulti-Select' ||
- $field['html_type'] == 'Multi-Select' ||
- ($field['html_type'] == 'Autocomplete-Select' && $field['data_type'] != 'ContactReference')
- )
- ) {
- if ($field['option_group_id']) {
- $optionGroupID = $field['option_group_id'];
- }
- elseif ($field['data_type'] != 'Boolean') {
- CRM_Core_Error::fatal();
- }
- }
-
- // build the cache for custom values with options (label => value)
- if ($optionGroupID != NULL) {
- $query = "
-SELECT label, value
- FROM civicrm_option_value
- WHERE option_group_id = $optionGroupID
-";
-
- $dao = CRM_Core_DAO::executeQuery($query);
- while ($dao->fetch()) {
- if ($field['data_type'] == 'Int' || $field['data_type'] == 'Float') {
- $num = round($dao->value, 2);
- $options["$num"] = $dao->label;
- }
- else {
- $options[$dao->value] = $dao->label;
- }
- }
-
- CRM_Utils_Hook::customFieldOptions($field['id'], $options);
- }
- }
/**
* Get custom field ID.