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',
$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 && empty($params['option_group_id'])) {
// first create an option group for this custom group
$optionGroup = new CRM_Core_DAO_OptionGroup();
$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;
}
}
*
* @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');
*
* @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
$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;
*
* @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, ' "');
* @static
*/
public static function getDisplayValue($value, $id, &$options, $contactID = NULL, $fieldID = NULL) {
- $option = &$options[$id];
+ $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,
*
* @return array|mixed|null|string
*/
- static function getDisplayValueCommon($value,
+ 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');
}
}
*
* @static
*/
- static function setProfileDefaults($customFieldId,
+ 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;
* @return array $customFormatted formatted custom field array
* @static
*/
- static function formatCustomField($customFieldId, &$customFormatted, $value,
+ static function formatCustomField(
+ $customFieldId, &$customFormatted, $value,
$customFieldExtend, $customValueId = NULL,
$entityId = NULL,
$inline = FALSE,
$checkPermission = TRUE,
- $includeViewOnly = false
+ $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 (!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 {
* FK to civicrm_custom_group.
*
* @return array(
- string) or TRUE
+ * string) or TRUE
*/
public static function _moveFieldValidate($fieldID, $newGroupID) {
$errors = array();
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'),
);
* @static
*/
public static function getTableColumnGroup($fieldID, $force = FALSE) {
- $cacheKey = "CRM_Core_DAO_CustomField_CustomGroup_TableColumn_{$fieldID}";
- $cache = CRM_Utils_Cache::singleton();
+ $cacheKey = "CRM_Core_DAO_CustomField_CustomGroup_TableColumn_{$fieldID}";
+ $cache = CRM_Utils_Cache::singleton();
$fieldValues = $cache->get($cacheKey);
if (empty($fieldValues) || $force) {
$query = "
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) {
*
* @return array
*/
- static function postProcess(&$params,
+ static function postProcess(
+ &$params,
&$customFields,
$entityID,
$customFieldExtends,
$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'];
}
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()) {
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;
}
$state = NULL,
$action = CRM_Core_Action::NONE,
$method = 'post',
- $name = NULL
+ $name = NULL
) {
if ($name) {
*
* @return HTML_QuickForm_Element could be an error object
*/
- function &add($type, $name, $label = '',
+ function &add(
+ $type, $name, $label = '',
$attributes = '', $required = FALSE, $extra = NULL
) {
if ($type == 'select' && is_array($extra)) {
* @return void
*
*/
- public function preProcess() {}
+ public function preProcess() {
+ }
/**
* This function is called after the form is validated. Any
* @return void
*
*/
- public function postProcess() {}
+ public function postProcess() {
+ }
/**
* This function is just a wrapper, so that we can call all the hook functions
* @return void
*
*/
- public function buildQuickForm() {}
+ public function buildQuickForm() {
+ }
/**
* This virtual function is used to set the default values of
* @return array reference to the array of default values
*
*/
- public function setDefaultValues() {}
+ public function setDefaultValues() {
+ }
/**
* This is a virtual function that adds group and global rules to
* @return void
*
*/
- public function addRules() {}
+ public function addRules() {
+ }
/**
* Performs the server side validation
$this->addRules();
//Set html data-attribute to enable warning user of unsaved changes
- if ($this->unsavedChangesWarn === true
+ if ($this->unsavedChangesWarn === TRUE
|| (!isset($this->unsavedChangesWarn)
&& ($this->_action & CRM_Core_Action::ADD || $this->_action & CRM_Core_Action::UPDATE)
)
) {
- $this->setAttribute('data-warn-changes', 'true');
+ $this->setAttribute('data-warn-changes', 'true');
}
}
* The value to append.
* @param bool $merge
*/
- public function append($tpl_var, $value=NULL, $merge=FALSE) {
+ public function append($tpl_var, $value = NULL, $merge = FALSE) {
self::$_template->append($tpl_var, $value, $merge);
}
*
* @return array
*/
- public function get_template_vars($name=null) {
+ public function get_template_vars($name = NULL) {
return self::$_template->get_template_vars($name);
}
* @param string $separator
* @param bool $flipValues
*/
- function addCheckBox($id, $title, $values, $other = NULL,
- $attributes = NULL, $required = NULL,
+ function addCheckBox(
+ $id, $title, $values, $other = NULL,
+ $attributes = NULL, $required = NULL,
$javascriptMethod = NULL,
- $separator = '<br />', $flipValues = FALSE
+ $separator = '<br />', $flipValues = FALSE
) {
$options = array();
/**
* Add a currency and money element to the form
*/
- function addMoney($name,
+ function addMoney(
+ $name,
$label,
- $required = FALSE,
- $attributes = NULL,
- $addCurrency = TRUE,
- $currencyName = 'currency',
+ $required = FALSE,
+ $attributes = NULL,
+ $addCurrency = TRUE,
+ $currencyName = 'currency',
$defaultCurrency = NULL,
- $freezeCurrency = FALSE
+ $freezeCurrency = FALSE
) {
$element = $this->add('text', $name, $label, $attributes, $required);
$this->addRule($name, ts('Please enter a valid amount.'), 'money');
/**
* Add currency element to the form
*/
- function addCurrency($name = 'currency',
- $label = NULL,
- $required = TRUE,
+ function addCurrency(
+ $name = 'currency',
+ $label = NULL,
+ $required = TRUE,
$defaultCurrency = NULL,
- $freezeCurrency = FALSE
+ $freezeCurrency = FALSE
) {
$currencies = CRM_Core_OptionGroup::values('currencies_enabled');
$options = array('class' => 'crm-select2 eight');
* perform specific action on cancel action
*
*/
- public function cancelAction() {}
+ public function cancelAction() {
+ }
/**
* Helper function to verify that required fields have been filled
return $userID;
}
- /**
- * Get the contact id of the logged in user
- */
+ /**
+ * Get the contact id of the logged in user
+ */
public function getLoggedInUserContactID() {
// check if the user is logged in and has a contact ID
$session = CRM_Core_Session::singleton();
public function canUseAjaxContactLookups() {
if (0 < (civicrm_api3('contact', 'getcount', array('check_permissions' => 1))) &&
CRM_Core_Permission::check(array(array('access AJAX API', 'access CiviCRM')))) {
- return TRUE;
- }
+ return TRUE;
+ }
}
/**
case CRM_Core_Action::ADD:
CRM_Utils_System::setTitle(ts('New %1', array(1 => $entityLabel)));
break;
+
case CRM_Core_Action::UPDATE:
CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $entityLabel)));
break;
+
case CRM_Core_Action::VIEW:
case CRM_Core_Action::PREVIEW:
CRM_Utils_System::setTitle(ts('View %1', array(1 => $entityLabel)));
break;
+
case CRM_Core_Action::DELETE:
CRM_Utils_System::setTitle(ts('Delete %1', array(1 => $entityLabel)));
break;
private function validateChainSelectFields() {
foreach ($this->_chainSelectFields as $control => $target) {
if ($this->elementExists($control)) {
- $controlValue = (array)$this->getElementValue($control);
+ $controlValue = (array) $this->getElementValue($control);
$targetField = $this->getElement($target);
$controlType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'stateProvince' : 'country';
- $targetValue = array_filter((array)$targetField->getValue());
+ $targetValue = array_filter((array) $targetField->getValue());
if ($targetValue || $this->getElementError($target)) {
$options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
if ($targetValue) {