<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* Array for valid combinations of data_type & descriptions
*
* @var array
- * @static
*/
public static $_dataType = NULL;
* Array for valid combinations of data_type & html_type
*
* @var array
- * @static
*/
public static $_dataToHtml = NULL;
* Array to hold (formatted) fields for import
*
* @var array
- * @static
*/
public static $_importFields = NULL;
/**
- * Build and retrieve the list of data types and descriptions
- *
- * @param NULL
+ * Build and retrieve the list of data types and descriptions.
*
- * @return array Data type => Description
- * @access public
- * @static
+ * @return array
+ * Data type => Description
*/
- static function &dataType() {
+ public static function &dataType() {
if (!(self::$_dataType)) {
self::$_dataType = array(
'String' => ts('Alphanumeric'),
/**
* @return array
*/
- static function dataToHtml() {
+ public static function dataToHtml() {
if (!self::$_dataToHtml) {
self::$_dataToHtml = array(
array(
- 'Text' => 'Text', 'Select' => 'Select',
- 'Radio' => 'Radio', 'CheckBox' => 'CheckBox',
+ 'Text' => 'Text',
+ 'Select' => 'Select',
+ 'Radio' => 'Radio',
+ 'CheckBox' => 'CheckBox',
'Multi-Select' => 'Multi-Select',
'AdvMulti-Select' => 'AdvMulti-Select',
'Autocomplete-Select' => 'Autocomplete-Select',
}
/**
- * takes an associative array and creates a custom field object
+ * Takes an associative array and creates a custom field object.
*
* This function is invoked from within the web form layer and also from the api layer
*
- * @param array $params (reference) an assoc array of name/value pairs
+ * @param array $params
+ * (reference) an assoc array of name/value pairs.
*
- * @return CRM_Core_DAO_CustomField object
- * @access public
- * @static
+ * @return CRM_Core_DAO_CustomField
*/
- static function create(&$params) {
+ public static function create(&$params) {
$origParams = array_merge(array(), $params);
if (!isset($params['id'])) {
$indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable');
}
- switch (CRM_Utils_Array::value('html_type', $params)){
+ switch (CRM_Utils_Array::value('html_type', $params)) {
case 'Select Date':
- if(empty($params['date_format'])){
+ if (empty($params['date_format'])) {
$config = CRM_Core_Config::singleton();
$params['date_format'] = $config->dateInputFormat;
}
break;
+
case 'CheckBox':
case 'AdvMulti-Select':
case 'Multi-Select':
$params['default_value'] = $params['option_value'][$params['default_option']];
}
}
- break;
+ break;
}
$transaction = new CRM_Core_Transaction();
// create any option group & values if required
if ($params['html_type'] != 'Text' &&
in_array($params['data_type'], array(
- 'String', 'Int', 'Float', 'Money'))
+ 'String',
+ 'Int',
+ 'Float',
+ 'Money',
+ ))
) {
$tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
'table_name'
);
-
- if ($params['option_type'] == 1) {
+ if ($params['option_type'] == 1 && empty($params['option_group_id'])) {
// first create an option group for this custom group
$optionGroup = new CRM_Core_DAO_OptionGroup();
$optionGroup->name = "{$columnName}_" . date('YmdHis');
$optionGroup->is_active = 1;
$optionGroup->save();
$params['option_group_id'] = $optionGroup->id;
- if(!empty($params['option_value']) && is_array($params['option_value'])){
+ if (!empty($params['option_value']) && is_array($params['option_value'])) {
foreach ($params['option_value'] as $k => $v) {
if (strlen(trim($v))) {
$optionValue = new CRM_Core_DAO_OptionValue();
);
if (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR,
- $defaultValue
- ))) {
+ $defaultValue
+ ))
+ ) {
$params['default_value'] = $defaultValue;
}
}
$customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, FALSE);
$customField->in_selector = CRM_Utils_Array::value('in_selector', $params, FALSE);
$customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, FALSE);
- $customField->is_active = CRM_Utils_Array::value('is_active', $params, FALSE);
+ //CRM-15792 - Custom field gets disabled if is_active not set
+ $customField->is_active = CRM_Utils_Array::value('is_active', $params, TRUE);
$customField->is_view = CRM_Utils_Array::value('is_view', $params, FALSE);
$customField->save();
}
/**
- * Takes a bunch of params that are needed to match certain criteria and
- * retrieves the relevant objects. Typically the valid params are only
- * contact_id. We'll tweak this function to be more full featured over a period
- * of time. This is the inverse function of create. It also stores all the retrieved
- * values in the default array
+ * Fetch object based on array of properties.
*
- * @param array $params (reference ) an assoc array of name/value pairs
- * @param array $defaults (reference ) an assoc array to hold the flattened values
+ * @param array $params
+ * (reference ) an assoc array of name/value pairs.
+ * @param array $defaults
+ * (reference ) an assoc array to hold the flattened values.
*
- * @return object CRM_Core_DAO_CustomField object
- * @access public
- * @static
+ * @return CRM_Core_DAO_CustomField
*/
- static function retrieve(&$params, &$defaults) {
+ public static function retrieve(&$params, &$defaults) {
return CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
}
/**
- * update the is_active flag in the db
+ * Update the is_active flag in the db.
*
- * @param int $id Id of the database record
- * @param boolean $is_active Value we want to set the is_active field
+ * @param int $id
+ * Id of the database record.
+ * @param bool $is_active
+ * Value we want to set the is_active field.
*
- * @return Object DAO object on sucess, null otherwise
+ * @return Object
+ * DAO object on sucess, null otherwise
*
- * @access public
- * @static
*/
- static function setIsActive($id, $is_active) {
+ public static function setIsActive($id, $is_active) {
CRM_Utils_System::flushCache();
/**
* Get the field title.
*
- * @param int $id id of field.
+ * @param int $id
+ * Id of field.
*
- * @return string name
- *
- * @access public
- * @static
+ * @return string
+ * name
*
*/
public static function getTitle($id) {
/**
* Store and return an array of all active custom fields.
*
- * @param string $customDataType type of Custom Data; empty is a synonym for "all contact data types"
- * @param boolean $showAll If true returns all fields (includes disabled fields)
- * @param boolean $inline If true returns all inline fields (includes disabled fields)
- * @param int $customDataSubType Custom Data sub type value
- * @param int $customDataSubName Custom Data sub name value
- * @param boolean $onlyParent return only top level custom data, for eg, only Participant and ignore subname and subtype
- * @param boolean $onlySubType return only custom data for subtype
- * @param boolean $checkPermission if false, do not include permissioning clause
+ * @param string $customDataType
+ * Type of Custom Data; empty is a synonym for "all contact data types".
+ * @param bool $showAll
+ * If true returns all fields (includes disabled fields).
+ * @param bool $inline
+ * If true returns all inline fields (includes disabled fields).
+ * @param int $customDataSubType
+ * Custom Data sub type value.
+ * @param int $customDataSubName
+ * Custom Data sub name value.
+ * @param bool $onlyParent
+ * Return only top level custom data, for eg, only Participant and ignore subname and subtype.
+ * @param bool $onlySubType
+ * Return only custom data for subtype.
+ * @param bool $checkPermission
+ * If false, do not include permissioning clause.
*
- * @return array $fields - an array of active custom fields.
+ * @return array
+ * an array of active custom fields.
*
- * @access public
- * @static
*/
- public static function &getFields($customDataType = 'Individual',
- $showAll = FALSE,
- $inline = FALSE,
- $customDataSubType = NULL,
- $customDataSubName = NULL,
- $onlyParent = FALSE,
- $onlySubType = FALSE,
- $checkPermission = TRUE
+ public static function &getFields(
+ $customDataType = 'Individual',
+ $showAll = FALSE,
+ $inline = FALSE,
+ $customDataSubType = NULL,
+ $customDataSubName = NULL,
+ $onlyParent = FALSE,
+ $onlySubType = FALSE,
+ $checkPermission = TRUE
) {
if (empty($customDataType)) {
$customDataType = array('Contact', 'Individual', 'Organization', 'Household');
* Return the field ids and names (with groups) for import purpose.
*
* @param int|string $contactType Contact type
- * @param boolean $showAll If true returns all fields (includes disabled fields)
- * @param boolean $onlyParent return fields ONLY related to basic types
- * @param boolean $search when called from search and multiple records need to be returned
- * @param boolean $checkPermission if false, do not include permissioning clause
+ * @param bool $showAll
+ * If true returns all fields (includes disabled fields).
+ * @param bool $onlyParent
+ * Return fields ONLY related to basic types.
+ * @param bool $search
+ * When called from search and multiple records need to be returned.
+ * @param bool $checkPermission
+ * If false, do not include permissioning clause.
*
* @param bool $withMultiple
*
- * @return array $fields -
+ * @return array
+ *
*
- * @access public
- * @static
*/
- public static function &getFieldsForImport($contactType = 'Individual',
- $showAll = FALSE,
- $onlyParent = FALSE,
- $search = FALSE,
+ public static function &getFieldsForImport(
+ $contactType = 'Individual',
+ $showAll = FALSE,
+ $onlyParent = FALSE,
+ $search = FALSE,
$checkPermission = TRUE,
- $withMultiple = FALSE
+ $withMultiple = FALSE
) {
// Note: there are situations when we want getFieldsForImport() return fields related
// ONLY to basic contact types, but NOT subtypes. And thats where $onlyParent is helpful
}
/**
- * Get the field id from an import key
+ * Get the field id from an import key.
*
- * @param string $key The key to parse
+ * @param string $key
+ * The key to parse.
*
* @param bool $all
- * @return int|null The id (if exists)
- * @access public
- * @static
+ * @return int|null
+ * The id (if exists)
*/
public static function getKeyID($key, $all = FALSE) {
$match = array();
}
/**
- * Use the cache to get all values of a specific custom field
+ * Use the cache to get all values of a specific custom field.
*
- * @param int $fieldID the custom field ID
+ * @param int $fieldID
+ * The custom field ID.
*
- * @return CRM_Core_DAO_CustomField $field the field object
- * @static
- * public
+ * @return CRM_Core_DAO_CustomField
+ * The field object.
*/
- static function getFieldObject($fieldID) {
+ public static function getFieldObject($fieldID) {
$field = new CRM_Core_DAO_CustomField();
// check if we can get the field values from the system cache
- $cacheKey = "CRM_Core_DAO_CustomField_{$fieldID}";
- $cache = CRM_Utils_Cache::singleton();
+ $cacheKey = "CRM_Core_DAO_CustomField_{$fieldID}";
+ $cache = CRM_Utils_Cache::singleton();
$fieldValues = $cache->get($cacheKey);
if (empty($fieldValues)) {
$field->id = $fieldID;
}
/**
- * This function for building custom fields
- *
- * @param CRM_Core_Form $qf form object (reference)
- * @param string $elementName name of the custom field
- * @param $fieldId
- * @param boolean $inactiveNeeded -deprecated
+ * This function for building custom fields.
+ *
+ * @param CRM_Core_Form $qf
+ * Form object (reference).
+ * @param string $elementName
+ * Name of the custom field.
+ * @param int $fieldId
+ * @param bool $inactiveNeeded
+ * -deprecated.
* @param bool $useRequired
- * @param boolean $search true if used for search else false
- * @param string $label label for custom field
+ * True if required else false.
+ * @param bool $search
+ * True if used for search else false.
+ * @param string $label
+ * Label for custom field.
*
- * @internal param bool $userRequired true if required else false
- * @access public
- * @static
*/
- public static function addQuickFormElement(&$qf,
+ public static function addQuickFormElement(
+ &$qf,
$elementName,
$fieldId,
$inactiveNeeded = FALSE,
- $useRequired = TRUE,
- $search = FALSE,
- $label = NULL
+ $useRequired = TRUE,
+ $search = FALSE,
+ $label = NULL
) {
$field = self::getFieldObject($fieldId);
$widget = $field->html_type;
// Custom field HTML should indicate group+field name
$groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id);
- $dataCrmCustomVal = $groupName.':'.$field->name;
- $dataCrmCustomAttr = 'data-crm-custom="'.$dataCrmCustomVal.'"';
+ $dataCrmCustomVal = $groupName . ':' . $field->name;
+ $dataCrmCustomAttr = 'data-crm-custom="' . $dataCrmCustomVal . '"';
$field->attributes .= $dataCrmCustomAttr;
// Fixed for Issue CRM-2183
$placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
// FIXME: Why are select state/country separate widget types?
- $isSelect = (in_array($widget, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country', 'AdvMulti-Select', 'CheckBox', 'Radio')));
+ $isSelect = (in_array($widget, array(
+ 'Select',
+ 'Multi-Select',
+ 'Select State/Province',
+ 'Multi-Select State/Province',
+ 'Select Country',
+ 'Multi-Select Country',
+ 'AdvMulti-Select',
+ 'CheckBox',
+ 'Radio',
+ )));
if ($isSelect) {
- $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array('field' => "custom_$fieldId", 'context' => $search ? 'search' : 'create'), array()));
+ $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array(
+ 'field' => "custom_$fieldId",
+ 'context' => $search ? 'search' : 'create',
+ ), array()));
// Consolidate widget types to simplify the below switch statement
if ($search || ($widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE)) {
// Add data for popup link. Normally this is handled by CRM_Core_Form->addSelect
if ($field->option_group_id && !$search && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) {
$selectAttributes += array(
- 'data-api-entity' => 'contact', // FIXME: This works because the getoptions api isn't picky about custom fields, but it's WRONG
+ 'data-api-entity' => 'contact',
+ // FIXME: This works because the getoptions api isn't picky about custom fields, but it's WRONG
'data-api-field' => 'custom_' . $field->id,
'data-option-edit-path' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id),
);
$qf->addDate($elementName, $label, $required, array(
'format' => $field->date_format,
- 'timeFormat' => $field->time_format,
- 'startOffset' => $field->start_date_years,
- 'endOffset' => $field->end_date_years,
- 'data-crm-custom' => $dataCrmCustomVal,
- ));
+ 'timeFormat' => $field->time_format,
+ 'startOffset' => $field->start_date_years,
+ 'endOffset' => $field->end_date_years,
+ 'data-crm-custom' => $dataCrmCustomVal,
+ ));
}
break;
case 'Radio':
$choice = array();
foreach ($options as $v => $l) {
- $choice[] = $qf->createElement('radio', NULL, '', $l, (string)$v, $field->attributes);
+ $choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes);
}
$group = $qf->addGroup($choice, $elementName, $label);
if ($useRequired && !$search) {
break;
case 'RichTextEditor':
- $attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal);
+ $attributes = array(
+ 'rows' => $field->note_rows,
+ 'cols' => $field->note_columns,
+ 'data-crm-custom' => $dataCrmCustomVal,
+ );
if ($field->text_length) {
$attributes['maxlength'] = $field->text_length;
}
// Fixme: why is this a string in the first place??
$attributes = array();
if ($field->attributes) {
- foreach(explode(' ', $field->attributes) as $at) {
+ foreach (explode(' ', $field->attributes) as $at) {
if (strpos($at, '=')) {
list($k, $v) = explode('=', $at);
$attributes[$k] = trim($v, ' "');
/**
* Delete the Custom Field.
*
- * @param object $field - the field object
- *
- * @return boolean
- *
- * @access public
- * @static
- *
+ * @param object $field
+ * The field object.
*/
public static function deleteField($field) {
CRM_Utils_System::flushCache();
$field->delete();
CRM_Core_BAO_UFField::delUFField($field->id);
CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_CustomField');
-
- return;
}
/**
* Given a custom field value, its id and the set of options
* find the display value for this field
*
- * @param mixed $value the custom field value
- * @param int $id the custom field id
- * @param int $options the assoc array of option name/value pairs
+ * @param mixed $value
+ * The custom field value.
+ * @param int $id
+ * The custom field id.
+ * @param int $options
+ * The assoc array of option name/value pairs.
*
- * @param null $contactID
- * @param null $fieldID
+ * @param int $contactID
+ * @param int $fieldID
*
- * @return string the display value
+ * @return string
+ * the display value
*
- * @static
- * @access public
*/
- static function getDisplayValue($value, $id, &$options, $contactID = NULL, $fieldID = NULL) {
- $option = &$options[$id];
+ 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);
+ $html_type = $attributes['html_type'];
+ $data_type = $attributes['data_type'];
+ $format = CRM_Utils_Array::value('format', $attributes);
return self::getDisplayValueCommon($value,
$option,
* @param $html_type
* @param $data_type
* @param null $format
- * @param null $contactID
- * @param null $fieldID
+ * @param int $contactID
+ * @param int $fieldID
*
* @return array|mixed|null|string
*/
- static function getDisplayValueCommon($value,
+ public static function getDisplayValueCommon(
+ $value,
&$option,
$html_type,
$data_type,
- $format = NULL,
+ $format = NULL,
$contactID = NULL,
- $fieldID = NULL
+ $fieldID = NULL
) {
$display = $value;
if ($value) {
$display = ts('Yes');
}
- elseif ((string)$value === '0') {
+ elseif ((string) $value === '0') {
$display = ts('No');
}
}
break;
case 'File':
- if ($contactID) {
- $url = self::getFileURL($contactID, $fieldID, $value);
- if ($url) {
- $display = $url['file_url'];
- }
+ if ($value) {
+ $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value);
+ $display = $icons[$value];
}
break;
}
/**
- * Function to set default values for custom data used in profile
- *
- * @params int $customFieldId custom field id
- * @params string $elementName custom field name
- * @params array $defaults associated array of fields
- * @params int $contactId contact id
- * @param $customFieldId
- * @param $elementName
- * @param $defaults
- * @param null $contactId
- * @param int $mode profile mode
- * @param mixed $value if passed - dont fetch value from db,
+ * Set default values for custom data used in profile.
+ *
+ * @param int $customFieldId
+ * Custom field id.
+ * @param string $elementName
+ * Custom field name.
+ * @param array $defaults
+ * Associated array of fields.
+ * @param int $contactId
+ * Contact id.
+ * @param int $mode
+ * Profile mode.
+ * @param mixed $value
+ * If passed - dont fetch value from db,.
* just format the given value
*
- * @static
- * @access public
*/
- static function setProfileDefaults($customFieldId,
+ public static function setProfileDefaults(
+ $customFieldId,
$elementName,
&$defaults,
$contactId = NULL,
}
else {
if (!isset($value)) {
- $info = self::getTableColumnGroup($customFieldId);
- $query = "SELECT {$info[0]}.{$info[1]} as value FROM {$info[0]} WHERE {$info[0]}.entity_id = {$contactId}";
+ $info = self::getTableColumnGroup($customFieldId);
+ $query = "SELECT {$info[0]}.{$info[1]} as value FROM {$info[0]} WHERE {$info[0]}.entity_id = {$contactId}";
$result = CRM_Core_DAO::executeQuery($query);
if ($result->fetch()) {
$value = $result->value;
}
/**
- * @param $contactID
- * @param $cfID
- * @param null $fileID
+ * @param int $contactID
+ * @param int $cfID
+ * @param int $fileID
* @param bool $absolute
*
* @return array
*/
/**
- * @param $contactID
- * @param $cfID
- * @param null $fileID
+ * @param int $contactID
+ * @param int $cfID
+ * @param int $fileID
* @param bool $absolute
*
* @return array
*/
- static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE) {
+ public static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE, $multiRecordWhereClause = NULL) {
if ($contactID) {
if (!$fileID) {
$params = array('id' => $cfID);
);
//query to fetch id from civicrm_file
- $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}";
+ if ($multiRecordWhereClause) {
+ $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID} AND {$multiRecordWhereClause}";
+ }
+ else {
+ $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}";
+ }
$fileID = CRM_Core_DAO::singleValueQuery($query);
}
}
/**
- * Format custom fields before inserting
- *
- * @param int $customFieldId custom field id
- * @param array $customFormatted formatted array
- * @param mix $value value of custom field
- * @param string $customFieldExtend custom field extends
- * @param int $customValueId custom option value id
- * @param int $entityId entity id (contribution, membership...)
- * @param boolean $inline consider inline custom groups only
- * @param boolean $checkPermission if false, do not include permissioning clause
- *
- * @return array $customFormatted formatted custom field array
- * @static
+ * Format custom fields before inserting.
+ *
+ * @param int $customFieldId
+ * Custom field id.
+ * @param array $customFormatted
+ * Formatted array.
+ * @param mix $value
+ * Value of custom field.
+ * @param string $customFieldExtend
+ * Custom field extends.
+ * @param int $customValueId
+ * Custom option value id.
+ * @param int $entityId
+ * Entity id (contribution, membership...).
+ * @param bool $inline
+ * Consider inline custom groups only.
+ * @param bool $checkPermission
+ * If false, do not include permissioning clause.
+ * @param bool $includeViewOnly
+ * If true, fields marked 'View Only' are included. Required for APIv3.
+ *
+ * @return array|NULL
+ * formatted custom field array
*/
- static function formatCustomField($customFieldId, &$customFormatted, $value,
+ public static function formatCustomField(
+ $customFieldId, &$customFormatted, $value,
$customFieldExtend, $customValueId = NULL,
$entityId = NULL,
$inline = FALSE,
- $checkPermission = TRUE
+ $checkPermission = TRUE,
+ $includeViewOnly = FALSE
) {
//get the custom fields for the entity
//subtype and basic type
}
if (in_array($customFieldExtend,
- CRM_Contact_BAO_ContactType::subTypes()
- )) {
+ CRM_Contact_BAO_ContactType::subTypes()
+ )) {
// This is the case when getFieldsForImport() requires fields
// of subtype and its parent.CRM-5143
$customDataSubType = $customFieldExtend;
);
if (!array_key_exists($customFieldId, $customFields)) {
- return;
+ return NULL;
}
// return if field is a 'code' field
- if (!empty($customFields[$customFieldId]['is_view'])) {
- return;
+ if (!$includeViewOnly && !empty($customFields[$customFieldId]['is_view'])) {
+ return NULL;
}
list($tableName, $columnName, $groupID) = self::getTableColumnGroup($customFieldId);
}
if (!empty($selectedValues)) {
$value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
- $selectedValues
- ) . CRM_Core_DAO::VALUE_SEPARATOR;
+ $selectedValues
+ ) . CRM_Core_DAO::VALUE_SEPARATOR;
}
else {
$value = '';
// 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;
+ array_values($value)
+ ) . CRM_Core_DAO::VALUE_SEPARATOR;
}
}
else {
}
/**
- * @param $params
+ * @param array $params
*
* @return array
*/
- static function &defaultCustomTableSchema(&$params) {
+ public static function &defaultCustomTableSchema(&$params) {
// add the id and extends_id
$table = array(
'name' => $params['name'],
* @param bool $indexExist
* @param bool $triggerRebuild
*/
- static function createField($field, $operation, $indexExist = FALSE, $triggerRebuild = TRUE) {
+ public static function createField($field, $operation, $indexExist = FALSE, $triggerRebuild = TRUE) {
$tableName = CRM_Core_DAO::getFieldValue(
'CRM_Core_DAO_CustomGroup',
$field->custom_group_id,
$params['fk_field_name'] = 'id';
$params['fk_attributes'] = 'ON DELETE SET NULL';
}
- if ($field->default_value) {
+ if (isset($field->default_value)) {
$params['default'] = "'{$field->default_value}'";
}
}
/**
- * Determine whether it would be safe to move a field
+ * Determine whether it would be safe to move a field.
*
- * @param int $fieldID FK to civicrm_custom_field
- * @param int $newGroupID FK to civicrm_custom_group
+ * @param int $fieldID
+ * FK to civicrm_custom_field.
+ * @param int $newGroupID
+ * FK to civicrm_custom_group.
*
- * @return array(
- string) or TRUE
+ * @return array
+ * array(string) or TRUE
*/
- static function _moveFieldValidate($fieldID, $newGroupID) {
+ public static function _moveFieldValidate($fieldID, $newGroupID) {
$errors = array();
$field = new CRM_Core_DAO_CustomField();
FROM civicrm_custom_group
WHERE id IN ( %1, %2 )
";
- $params = array(1 => array($oldGroup->id, 'Integer'),
+ $params = array(
+ 1 => array($oldGroup->id, 'Integer'),
2 => array($newGroup->id, 'Integer'),
);
/**
* 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
+ * @param int $fieldID
+ * FK to civicrm_custom_field.
+ * @param int $newGroupID
+ * FK to civicrm_custom_group.
*
* @return void
*/
- static function moveField($fieldID, $newGroupID) {
+ public static function moveField($fieldID, $newGroupID) {
$validation = self::_moveFieldValidate($fieldID, $newGroupID);
if (TRUE !== $validation) {
CRM_Core_Error::fatal(implode(' ', $validation));
}
/**
- * Get the database table name and column name for a custom field
+ * Get the database table name and column name for a custom field.
*
- * @param int $fieldID - the fieldID of the custom field
- * @param boolean $force - force the sql to be run again (primarily used for tests)
+ * @param int $fieldID
+ * The fieldID of the custom field.
+ * @param bool $force
+ * Force the sql to be run again (primarily used for tests).
*
- * @return array - fatal is fieldID does not exists, else array of tableName, columnName
- * @static
- * @public
+ * @return array
+ * fatal is fieldID does not exists, else array of tableName, columnName
*/
- static function getTableColumnGroup($fieldID, $force = FALSE) {
- $cacheKey = "CRM_Core_DAO_CustomField_CustomGroup_TableColumn_{$fieldID}";
- $cache = CRM_Utils_Cache::singleton();
+ public static function getTableColumnGroup($fieldID, $force = FALSE) {
+ $cacheKey = "CRM_Core_DAO_CustomField_CustomGroup_TableColumn_{$fieldID}";
+ $cache = CRM_Utils_Cache::singleton();
$fieldValues = $cache->get($cacheKey);
if (empty($fieldValues) || $force) {
$query = "
}
/**
- * Function to get custom option groups
+ * Get custom option groups.
*
- * @params array $includeFieldIds ids of custom fields for which
- * option groups must be included.
+ * @param array $includeFieldIds
+ * 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
*
- * @access public
*
- * @param null $includeFieldIds
- *
- * @return mixed $customOptionGroup@static
+ * @return mixed
*/
public static function &customOptionGroup($includeFieldIds = NULL) {
static $customOptionGroup = NULL;
}
/**
- * Function to fix orphan groups
- *
- * @params int $customFieldId custom field id
- * @params int $optionGroupId option group id
+ * Fix orphan groups.
*
- * @access public
- *
- * @param $customFieldId
- * @param $optionGroupId
+ * @param int $customFieldId
+ * Custom field id.
+ * @param int $optionGroupId
+ * Option group id.
*
* @return void
- * @static
*/
- static function fixOptionGroups($customFieldId, $optionGroupId) {
+ public static function fixOptionGroups($customFieldId, $optionGroupId) {
// check if option group belongs to any custom Field else delete
// get the current option group
$currentOptionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
}
/**
- * Function to check if option group is related to more than one
+ * Check if option group is related to more than one
* custom field
*
- * @params int $optionGroupId option group id
- *
- * @param $optionGroupId
+ * @param int $optionGroupId
+ * Option group id.
*
* @return void
- @static
*/
- static function checkOptionGroup($optionGroupId) {
+ public static function checkOptionGroup($optionGroupId) {
$query = "
SELECT count(*)
FROM civicrm_custom_field
}
/**
- * @param $optionGroupId
+ * @param int $optionGroupId
* @param $htmlType
*
* @return null|string
*/
- static function getOptionGroupDefault($optionGroupId, $htmlType) {
+ public static function getOptionGroupDefault($optionGroupId, $htmlType) {
$query = "
SELECT default_value, html_type
FROM civicrm_custom_field
AND default_value IS NOT NULL
ORDER BY html_type";
- $dao = CRM_Core_DAO::executeQuery($query);
- $defaultValue = NULL;
+ $dao = CRM_Core_DAO::executeQuery($query);
+ $defaultValue = NULL;
$defaultHTMLType = NULL;
while ($dao->fetch()) {
if ($dao->html_type == $htmlType) {
}
/**
- * @param $params
+ * @param array $params
* @param $customFields
- * @param $entityID
+ * @param int $entityID
* @param $customFieldExtends
* @param bool $inline
*
* @return array
*/
- static function postProcess(&$params,
+ public static function postProcess(
+ &$params,
&$customFields,
$entityID,
$customFieldExtends,
*
* @throws Exception
*/
- static function buildOption($field, &$options) {
+ 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(
$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')
- )) {
+ $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'];
}
*
* @return null
*/
- static function getCustomFieldID($fieldLabel, $groupTitle = NULL) {
+ public static function getCustomFieldID($fieldLabel, $groupTitle = NULL) {
$params = array(1 => array($fieldLabel, 'String'));
if ($groupTitle) {
$params[2] = array($groupTitle, 'String');
/**
* Given ID of a custom field, return its name as well as the name of the custom group it belongs to.
- *
*/
- static function getNameFromID($ids) {
+ public static function getNameFromID($ids) {
if (is_array($ids)) {
$ids = implode(',', $ids);
}
INNER JOIN civicrm_custom_group g ON f.custom_group_id = g.id
WHERE f.id IN ($ids)";
-
$dao = CRM_Core_DAO::executeQuery($sql);
$result = array();
while ($dao->fetch()) {
/**
* Validate custom data.
*
- * @param array $params custom data submitted.
- * ie array( 'custom_1' => 'validate me' );
+ * @param array $params
+ * Custom data submitted.
+ * ie array( 'custom_1' => 'validate me' );
*
- * @return array $errors validation errors.
- * @static
+ * @return array
+ * validation errors.
*/
- static function validateCustomData($params) {
+ public static function validateCustomData($params) {
$errors = array();
if (!is_array($params) || empty($params)) {
return $errors;
}
-
//pick up profile fields.
$profileFields = array();
$ufGroupId = CRM_Utils_Array::value('ufGroupId', $params);
$dataType = $field->data_type;
$profileField = CRM_Utils_Array::value($key, $profileFields, array());
- $fieldTitle = CRM_Utils_Array::value('title', $profileField);
- $isRequired = CRM_Utils_Array::value('is_required', $profileField);
+ $fieldTitle = CRM_Utils_Array::value('title', $profileField);
+ $isRequired = CRM_Utils_Array::value('is_required', $profileField);
if (!$fieldTitle) {
$fieldTitle = $field->label;
}
}
/**
- * @param $customId
+ * @param int $customId
*
* @return bool
*/
- static function isMultiRecordField($customId) {
+ public static function isMultiRecordField($customId) {
$isMultipleWithGid = FALSE;
if (!is_numeric($customId)) {
$customId = self::getKeyID($customId);
* @param CRM_Core_DAO_CustomField|array $field
* @return bool
*/
- static function isSerialized($field) {
+ public static function isSerialized($field) {
// Fields retrieved via api are an array, or from the dao are an object. We'll accept either.
$field = (array) $field;
// FIXME: Currently the only way to know if data is serialized is by looking at the html_type. It would be cleaner to decouple this.
return ($field['html_type'] == 'CheckBox' || strpos($field['html_type'], 'Multi') !== FALSE);
}
-}
+}