$this->setOutputMode();
if ($this->_outputMode == 'copy') {
- $this->_createNew = ($this->_outputMode == 'copy');
+ $this->_createNew = TRUE;
$this->_params = $this->_formValues;
$this->_params['view_mode'] = 'criteria';
$this->_params['title'] = ts('(copy)') . $this->getTitle();
return;
}
- $customFields = $fieldValueMap = array();
- $customFieldCols = array(
- 'column_name',
- 'data_type',
- 'html_type',
- 'option_group_id',
- 'id',
- );
-
// skip for type date and ContactReference since date format is already handled
$query = "
-SELECT cg.table_name, cf." . implode(", cf.", $customFieldCols) . ", ov.value, ov.label
+SELECT cg.table_name, cf.id
FROM civicrm_custom_field cf
INNER JOIN civicrm_custom_group cg ON cg.id = cf.custom_group_id
-LEFT JOIN civicrm_option_value ov ON cf.option_group_id = ov.option_group_id
WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
cg.is_active = 1 AND
cf.is_active = 1 AND
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
- foreach ($customFieldCols as $key) {
- $customFields[$dao->table_name . '_custom_' .
- $dao->id][$key] = $dao->$key;
- }
- if ($dao->option_group_id) {
- $fieldValueMap[$dao->option_group_id][$dao->value] = $dao->label;
- }
+ $customFields[$dao->table_name . '_custom_' . $dao->id] = $dao->id;
}
$dao->free();
foreach ($rows as $rowNum => $row) {
foreach ($row as $tableCol => $val) {
if (array_key_exists($tableCol, $customFields)) {
- $rows[$rowNum][$tableCol] = $this->formatCustomValues($val, $customFields[$tableCol], $fieldValueMap);
+ $rows[$rowNum][$tableCol] = CRM_Core_BAO_CustomField::displayValue($val, $customFields[$tableCol]);
$entryFound = TRUE;
}
}
}
}
- /**
- * Format custom values.
- *
- * @param mixed $value
- * @param array $customField
- * @param array $fieldValueMap
- *
- * @return float|string|void
- */
- public function formatCustomValues($value, $customField, $fieldValueMap) {
- if (CRM_Utils_System::isNull($value)) {
- return NULL;
- }
-
- $htmlType = $customField['html_type'];
-
- switch ($customField['data_type']) {
- case 'Boolean':
- if ($value == '1') {
- $retValue = ts('Yes');
- }
- else {
- $retValue = ts('No');
- }
- break;
-
- case 'Link':
- $retValue = CRM_Utils_System::formatWikiURL($value);
- break;
-
- case 'File':
- $retValue = $value;
- break;
-
- case 'Memo':
- $retValue = $value;
- break;
-
- case 'Float':
- if ($htmlType == 'Text') {
- $retValue = (float) $value;
- break;
- }
- case 'Money':
- if ($htmlType == 'Text') {
- $retValue = CRM_Utils_Money::format($value, NULL, '%a');
- break;
- }
- case 'String':
- case 'Int':
- if (in_array($htmlType, array(
- 'Text',
- 'TextArea',
- ))) {
- $retValue = $value;
- break;
- }
- case 'StateProvince':
- case 'Country':
-
- switch ($htmlType) {
- case 'Multi-Select Country':
- $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
- $customData = array();
- foreach ($value as $val) {
- if ($val) {
- $customData[] = CRM_Core_PseudoConstant::country($val, FALSE);
- }
- }
- $retValue = implode(', ', $customData);
- break;
-
- case 'Select Country':
- $retValue = CRM_Core_PseudoConstant::country($value, FALSE);
- break;
-
- case 'Select State/Province':
- $retValue = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
- break;
-
- case 'Multi-Select State/Province':
- $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
- $customData = array();
- foreach ($value as $val) {
- if ($val) {
- $customData[] = CRM_Core_PseudoConstant::stateProvince($val, FALSE);
- }
- }
- $retValue = implode(', ', $customData);
- break;
-
- case 'Select':
- case 'Radio':
- case 'Autocomplete-Select':
- $retValue = $fieldValueMap[$customField['option_group_id']][$value];
- break;
-
- case 'CheckBox':
- case 'AdvMulti-Select':
- case 'Multi-Select':
- $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
- $customData = array();
- foreach ($value as $val) {
- if ($val) {
- $customData[] = $fieldValueMap[$customField['option_group_id']][$val];
- }
- }
- $retValue = implode(', ', $customData);
- break;
-
- default:
- $retValue = $value;
- }
- break;
-
- default:
- $retValue = $value;
- }
-
- return $retValue;
- }
-
/**
* Remove duplicate rows.
*
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('filters', $table)) {
foreach ($table['filters'] as $fieldName => $field) {
- if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE &&
+ if ((CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE ||
+ CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_TIME) &&
CRM_Utils_Array::value('operatorType', $field) !=
CRM_Report_Form::OP_MONTH
) {
$this->_columns[$curTable]['grouping'] = $customDAO->table_name;
$this->_columns[$curTable]['group_title'] = $customDAO->title;
- foreach (array(
- 'fields',
- 'filters',
- 'group_bys',
- ) as $colKey) {
+ foreach (array('fields', 'filters', 'group_bys') as $colKey) {
if (!array_key_exists($colKey, $this->_columns[$curTable])) {
$this->_columns[$curTable][$colKey] = array();
}
case 'Boolean':
$curFilters[$fieldName]['operatorType'] = CRM_Report_Form::OP_SELECT;
- $curFilters[$fieldName]['options'] = array(
- '' => ts('- select -'),
- 1 => ts('Yes'),
- 0 => ts('No'),
- );
+ $curFilters[$fieldName]['options'] = array('' => ts('- select -'))
+ + CRM_Core_PseudoConstant::get('CRM_Core_BAO_CustomField', 'custom_' . $customDAO->cf_id, array(), 'search');
$curFilters[$fieldName]['type'] = CRM_Utils_Type::T_INT;
break;
break;
case 'String':
- $curFilters[$fieldName]['type'] = CRM_Utils_Type::T_STRING;
-
- if (!empty($customDAO->option_group_id)) {
- if (in_array($customDAO->html_type, array(
- 'Multi-Select',
- 'AdvMulti-Select',
- 'CheckBox',
- ))) {
- $curFilters[$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT_SEPARATOR;
- }
- else {
- $curFilters[$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT;
- }
- if ($this->_customGroupFilters) {
- $curFilters[$fieldName]['options'] = array();
- $ogDAO = CRM_Core_DAO::executeQuery("SELECT ov.value, ov.label FROM civicrm_option_value ov WHERE ov.option_group_id = %1 ORDER BY ov.weight", array(
- 1 => array(
- $customDAO->option_group_id,
- 'Integer',
- ),
- ));
- while ($ogDAO->fetch()) {
- $curFilters[$fieldName]['options'][$ogDAO->value] = $ogDAO->label;
- }
- CRM_Utils_Hook::customFieldOptions($customDAO->cf_id, $curFilters[$fieldName]['options'], FALSE);
- }
- }
- break;
-
case 'StateProvince':
- if (in_array($customDAO->html_type, array(
- 'Multi-Select State/Province',
- ))) {
- $curFilters[$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT_SEPARATOR;
- }
- else {
- $curFilters[$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT;
- }
- $curFilters[$fieldName]['options'] = CRM_Core_PseudoConstant::stateProvince();
- break;
-
case 'Country':
- if (in_array($customDAO->html_type, array(
- 'Multi-Select Country',
- ))) {
- $curFilters[$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT_SEPARATOR;
- }
- else {
- $curFilters[$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT;
+ $curFilters[$fieldName]['type'] = CRM_Utils_Type::T_STRING;
+
+ $options = CRM_Core_PseudoConstant::get('CRM_Core_BAO_CustomField', 'custom_' . $customDAO->cf_id, array(), 'search');
+ if ($options !== FALSE) {
+ $curFilters[$fieldName]['operatorType'] = CRM_Core_BAO_CustomField::isSerialized($customDAO) ? CRM_Report_Form::OP_MULTISELECT_SEPARATOR : CRM_Report_Form::OP_MULTISELECT;
+ $curFilters[$fieldName]['options'] = $options;
}
- $curFilters[$fieldName]['options'] = CRM_Core_PseudoConstant::country();
break;
case 'ContactReference':