From 106e51b494406d2c0416c3af9c928228c4a25338 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 14 Dec 2015 14:56:55 -0500 Subject: [PATCH] CRM-17646 - Refactor CRM_Report_Form to use standard custom field option retrieval --- CRM/Report/Form.php | 67 ++++++--------------------------------------- 1 file changed, 9 insertions(+), 58 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index afe13b7cee..9abc9facaa 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -3629,11 +3629,7 @@ ORDER BY cg.weight, cf.weight"; $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(); } @@ -3673,11 +3669,8 @@ ORDER BY cg.weight, cf.weight"; 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; @@ -3697,57 +3690,15 @@ ORDER BY cg.weight, cf.weight"; 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': -- 2.25.1