<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
+ | CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
*/
/**
* Business objects for managing custom data fields.
- *
*/
class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
/**
- * Array for valid combinations of data_type & descriptions
+ * Array for valid combinations of data_type & descriptions.
*
* @var array
*/
public static $_dataType = NULL;
/**
- * Array for valid combinations of data_type & html_type
+ * Array for valid combinations of data_type & html_type.
*
* @var array
*/
}
/**
+ * Get data to html array.
+ *
+ * (Does this caching achieve anything?)
+ *
* @return array
*/
public static function dataToHtml() {
* Value we want to set the is_active field.
*
* @return Object
- * DAO object on sucess, null otherwise
- *
+ * DAO object on success, null otherwise
*/
public static function setIsActive($id, $is_active) {
*
* @return string
* name
- *
*/
public static function getTitle($id) {
return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $id, 'label');
*
* @return array
* an array of active custom fields.
- *
*/
public static function &getFields(
$customDataType = 'Individual',
* @param bool $withMultiple
*
* @return array
- *
- *
*/
- public static function &getFieldsForImport(
+ public static function getFieldsForImport(
$contactType = 'Individual',
$showAll = FALSE,
$onlyParent = FALSE,
* The key to parse.
*
* @param bool $all
+ *
* @return int|null
* The id (if exists)
*/
* True if used for search else false.
* @param string $label
* Label for custom field.
- *
*/
public static function addQuickFormElement(
&$qf,
$label = $field->label;
}
- /**
- * at some point in time we might want to split the below into small functions
- **/
+ // at some point in time we might want to split the below into small functions
switch ($widget) {
case 'Text':
if ($field->text_length) {
$attributes['maxlength'] = $field->text_length;
}
- $qf->addWysiwyg($elementName, $label, $attributes, $search);
+ $qf->add('wysiwyg', $elementName, $label, $attributes, $search);
break;
case 'Autocomplete-Select':
break;
case 'Link':
- $element->setAttribute('onfocus', "if (!this.value) {this.value='http://';}");
- $element->setAttribute('onblur', "if (this.value == 'http://') {this.value='';}");
$element->setAttribute('class', "url");
- $qf->addRule($elementName, ts('Enter a valid Website.'), 'wikiURL');
+ $qf->addRule($elementName, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'wikiURL');
break;
}
if ($field->is_view && !$search) {
}
/**
- * Given a custom field value, its id and the set of options
- * find the display value for this field
+ * Find the display value for this field.
*
* @param mixed $value
* The custom field value.
*
* @return string
* the display value
- *
*/
public static function getDisplayValue($value, $id, &$options, $contactID = NULL, $fieldID = NULL) {
$option = &$options[$id];
$attributes = &$option['attributes'];
$html_type = $attributes['html_type'];
$data_type = $attributes['data_type'];
- $format = CRM_Utils_Array::value('format', $attributes);
return self::getDisplayValueCommon($value,
$option,
$html_type,
$data_type,
- $format,
$contactID,
$fieldID
);
}
/**
- * @param $value
- * @param $option
- * @param $html_type
- * @param $data_type
- * @param null $format
+ * Get display value.
+ *
+ * @param string $value
+ * @param array $option
+ * @param string $html_type
+ * @param string $data_type
* @param int $contactID
* @param int $fieldID
*
&$option,
$html_type,
$data_type,
- $format = NULL,
$contactID = NULL,
$fieldID = NULL
) {
switch ($html_type) {
case 'Radio':
if ($data_type == 'Boolean') {
- $option = array('No', 'Yes');
+ $options = array('No', 'Yes');
+ }
+ else {
+ $options = $option;
}
if (is_array($value)) {
$display = NULL;
foreach ($value as $data) {
- $display .= $display ? ', ' . $option[$data] : $option[$data];
+ $display .= $display ? ', ' . $options[$data] : $options[$data];
}
}
else {
- $display = CRM_Utils_Array::value($value, $option);
+ $display = CRM_Utils_Array::value($value, $options);
}
break;
case 'AdvMulti-Select':
case 'Multi-Select':
if (is_array($value)) {
+ if ($html_type == 'CheckBox') {
+ // CRM-12989 fix
+ CRM_Utils_Array::formatArrayKeys($value);
+ }
+
$checkedData = $value;
}
else {
* @param mixed $value
* If passed - dont fetch value from db,.
* just format the given value
- *
*/
public static function setProfileDefaults(
$customFieldId,
}
/**
- * @param int $contactID
- * @param int $cfID
- * @param int $fileID
- * @param bool $absolute
+ * Get file url.
*
- * @return array
- */
- /**
* @param int $contactID
* @param int $cfID
* @param int $fileID
* @param bool $absolute
*
+ * @param string $multiRecordWhereClause
+ *
* @return array
*/
public static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE, $multiRecordWhereClause = NULL) {
* Custom field id.
* @param array $customFormatted
* Formatted array.
- * @param mix $value
+ * @param mixed $value
* Value of custom field.
* @param string $customFieldExtend
* Custom field extends.
$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 = '';
}
/**
+ * Get default custom table schema.
+ *
* @param array $params
*
* @return array
*/
- public static function &defaultCustomTableSchema(&$params) {
+ public static function defaultCustomTableSchema($params) {
// add the id and extends_id
$table = array(
'name' => $params['name'],
}
/**
- * @param $field
- * @param $operation
+ * Create custom field.
+ *
+ * @param CRM_Core_DAO_CustomField $field
+ * @param string $operation
* @param bool $indexExist
* @param bool $triggerRebuild
*/
}
/**
- * Move a custom data field from one group (table) to another
+ * Move a custom data field from one group (table) to another.
*
* @param int $fieldID
* FK to civicrm_custom_field.
* @param int $newGroupID
* FK to civicrm_custom_group.
- *
- * @return void
*/
public static function moveField($fieldID, $newGroupID) {
$validation = self::_moveFieldValidate($fieldID, $newGroupID);
* Get custom option groups.
*
* @param array $includeFieldIds
- * Ids of custom fields for which.
- * option groups must be included.
+ * Ids of custom fields for which option groups must be included.
*
* Currently this is required in the cases where option groups are to be included
* for inactive fields : CRM-5369
*
- *
* @return mixed
*/
- public static function &customOptionGroup($includeFieldIds = NULL) {
+ public static function customOptionGroup($includeFieldIds = NULL) {
static $customOptionGroup = NULL;
$cacheKey = (empty($includeFieldIds)) ? 'onlyActive' : 'force';
* Custom field id.
* @param int $optionGroupId
* Option group id.
- *
- * @return void
*/
public static function fixOptionGroups($customFieldId, $optionGroupId) {
// check if option group belongs to any custom Field else delete
}
/**
- * Check if option group is related to more than one
- * custom field
+ * Check if option group is related to more than one custom field.
*
* @param int $optionGroupId
* Option group id.
- *
- * @return void
*/
public static function checkOptionGroup($optionGroupId) {
$query = "
}
/**
+ * Get option group default.
+ *
* @param int $optionGroupId
- * @param $htmlType
+ * @param string $htmlType
*
* @return null|string
*/
}
/**
+ * Post process function.
+ *
* @param array $params
- * @param $customFields
* @param int $entityID
- * @param $customFieldExtends
+ * @param string $customFieldExtends
* @param bool $inline
*
* @return array
*/
public static function postProcess(
&$params,
- &$customFields,
$entityID,
$customFieldExtends,
$inline = FALSE
}
/**
- * @param $field
- * @param $options
+ * Build option.
+ *
+ * @param array $field
+ * @param array $options
*
* @throws Exception
*/
}
/**
- * @param $fieldLabel
+ * Get custom field ID.
+ *
+ * @param string $fieldLabel
* @param null $groupTitle
*
- * @return null
+ * @return int|null
*/
public static function getCustomFieldID($fieldLabel, $groupTitle = NULL) {
$params = array(1 => array($fieldLabel, 'String'));
}
/**
+ * Is this field a multi record field.
+ *
* @param int $customId
*
* @return bool
/**
* Does this field store a serialized string?
- * @param CRM_Core_DAO_CustomField|array $field
+ *
+ * @param array $field
+ *
* @return bool
*/
public static function isSerialized($field) {
}
/**
+ * Get options for field.
+ *
* @param array $field
* @param string|null $optionGroupName
*/