From 0c145cc0c9dd9e51e03f7f0ef3612fce873a7503 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Tue, 30 Apr 2013 18:31:47 -0700 Subject: [PATCH] CRM-14264 : start using xml for gender / suffix / prefix ---------------------------------------- * CRM-14264: http://issues.civicrm.org/jira/browse/CRM-14264 --- CRM/Contact/BAO/Contact.php | 6 ++-- CRM/Contact/BAO/Query.php | 4 --- CRM/Contact/Selector.php | 62 ++++++++++++++++++++-------------- CRM/Core/BAO/UFGroup.php | 11 ++++-- CRM/Core/OptionValue.php | 35 ++----------------- CRM/UF/Form/Field.php | 1 + xml/schema/Contact/Contact.xml | 3 ++ 7 files changed, 54 insertions(+), 68 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index ba0816aae6..16187e10e2 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -1383,14 +1383,14 @@ WHERE id={$id}; "; 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date', 'current_employer', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', - 'individual_prefix', 'individual_suffix', 'gender', + 'prefix_id', 'suffix_id' ), 'Organization' => array( 'first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'household_name', 'email_greeting_custom', - 'postal_greeting_custom', 'individual_prefix', - 'individual_suffix', 'gender', 'addressee_custom', + 'postal_greeting_custom', 'prefix_id', + 'suffix_id', 'gender_id', 'addressee_custom', 'is_deceased', 'deceased_date', 'current_employer', ), ); diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index acfd596bcd..03c72a933f 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -587,10 +587,6 @@ class CRM_Contact_BAO_Query { continue; } - if (CRM_Utils_Array::value('pseudoconstant', $field)) { - continue; - } - // redirect to activity select clause if (substr($name, 0, 9) == 'activity_') { CRM_Activity_BAO_Query::select($this); diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index a44c79f212..06c9a7ad56 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -419,7 +419,6 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se $headers = self::$_columnHeaders; } elseif (!empty($this->_returnProperties)) { - self::$_columnHeaders = array(array('name' => ''), array( 'name' => ts('Name'), @@ -523,7 +522,8 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se $names = array(); static $skipFields = array('group', 'tag'); foreach ($this->_fields as $key => $field) { - if (CRM_Utils_Array::value('in_selector', $field) && + if ( + CRM_Utils_Array::value('in_selector', $field) && !in_array($key, $skipFields) ) { if (strpos($key, '-') !== FALSE) { @@ -575,17 +575,38 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se //check explicitly added contact to a Smart Group. $groupID = CRM_Utils_Array::key('1', $this->_formValues['group']); + $pseudoconstants = array(); + // get all the pseudoconstant values + foreach ($this->_fields as $name => $values) { + if (isset($this->_fields[$name]['pseudoconstant'])) { + $pseudoconstants[$name] = + array( + 'dbName' => $this->_fields[$name]['name'], + 'values' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $name), + ); + } + } + // for CRM-3157 purposes if (in_array('country', $names)) { - $countries = CRM_Core_PseudoConstant::country(); + $pseudoconstants['country'] = array( + 'dbName' => 'country_id', + 'values' => CRM_Core_PseudoConstant::country() + ); } if (in_array('state_province', $names)) { - $provinces = CRM_Core_PseudoConstant::stateProvince(); + $pseudoconstants['state_province'] = array( + 'dbName' => 'state_province_id', + 'values' => CRM_Core_PseudoConstant::stateProvince() + ); } if (in_array('world_region', $names)) { - $regions = CRM_Core_PseudoConstant::worldRegion(); + $pseudoconstants['world_region'] = array( + 'dbName' => 'world_region_id', + 'values' => CRM_Core_PseudoConstant::worldRegion() + ); } $seenIDs = array(); @@ -598,29 +619,21 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se continue; } if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) { - $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue($result->$property, + $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue( + $result->$property, $cfID, $this->_options, $result->contact_id ); } - elseif ($multipleSelectFields && + elseif ( + $multipleSelectFields && array_key_exists($property, $multipleSelectFields) ) { - //fix to display student checkboxes $key = $property; $paramsNew = array($key => $result->$property); + $name = array($key => array('newName' => $key, 'groupName' => $key)); - if ($key == 'test_tutoring') { - $name = array($key => array('newName' => $key, 'groupName' => 'test')); - // for readers group - } - elseif (substr($key, 0, 4) == 'cmr_') { - $name = array($key => array('newName' => $key, 'groupName' => substr($key, 0, -3))); - } - else { - $name = array($key => array('newName' => $key, 'groupName' => $key)); - } CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE); $row[$key] = $paramsNew[$key]; } @@ -638,14 +651,11 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se $greeting = $property . '_display'; $row[$property] = $result->$greeting; } - elseif ($property == 'country') { - $row[$property] = CRM_Utils_Array::value($result->country_id, $countries); - } - elseif ($property == 'state_province') { - $row[$property] = CRM_Utils_Array::value($result->state_province_id, $provinces); - } - elseif ($property == 'world_region') { - $row[$property] = CRM_Utils_Array::value($result->worldregion_id, $regions); + elseif (isset($pseudoconstants[$property])) { + $row[$property] = CRM_Utils_Array::value( + $result->{$pseudoconstants[$property]['dbName']}, + $pseudoconstants[$property]['values'] + ); } elseif (strpos($property, '-url') !== FALSE) { $websiteUrl = ''; diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 5828be16ba..acbeff7fc6 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -380,8 +380,6 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { $formattedFields = array(); foreach ($fieldArrs as $fieldArr) { - //$field = new CRM_Core_DAO_UFField(); - //$field->copyValues($fieldArr); // no... converts string('') to string('null') $field = (object) $fieldArr; if (!self::filterUFField($field, $searchable, $showAll, $visibility)) { continue; @@ -467,6 +465,15 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { 'add_captcha' => isset($group->add_captcha) ? $group->add_captcha : NULL, 'field_type' => $field->field_type, 'field_id' => $field->id, + 'pseudoconstant' => CRM_Utils_Array::value( + 'pseudoconstant', + CRM_Utils_Array::value($field->field_name, $importableFields) + ), + // obsolete this when we remove the name / dbName discrepancy with gender/suffix/prefix + 'dbName' => CRM_Utils_Array::value( + 'dbName', + CRM_Utils_Array::value($field->field_name, $importableFields) + ), 'skipDisplay' => 0, ); diff --git a/CRM/Core/OptionValue.php b/CRM/Core/OptionValue.php index cd3a892e54..c2d7f0f546 100644 --- a/CRM/Core/OptionValue.php +++ b/CRM/Core/OptionValue.php @@ -317,38 +317,7 @@ class CRM_Core_OptionValue { ); $nameTitle = array_merge($nameTitle, $title); } - - if ($contactType == 'Individual' || $contactType == 'All') { - $contactFields = CRM_Contact_DAO_Contact::fields(); - $title = array( - 'gender' => array( - 'name' => 'gender', - 'dbName' => 'gender_id', - 'title' => ts('Gender'), - 'headerPattern' => '/^gender$/i', - 'pseudoconstant' => $contactFields['gender_id']['pseudoconstant'], - 'where' => 'contact_a.gender_id', - ), - 'individual_prefix' => array( - 'name' => 'individual_prefix', - 'dbName' => 'prefix_id', - 'title' => ts('Individual Prefix'), - 'headerPattern' => '/^(prefix|title)/i', - 'pseudoconstant' => $contactFields['prefix_id']['pseudoconstant'], - 'where' => 'contact_a.prefix_id', - ), - 'individual_suffix' => array( - 'name' => 'individual_suffix', - 'dbName' => 'suffix_id', - 'title' => ts('Individual Suffix'), - 'headerPattern' => '/^suffix$/i', - 'pseudoconstant' => $contactFields['suffix_id']['pseudoconstant'], - 'where' => 'contact_a.suffix_id', - ), - ); - $nameTitle = array_merge($nameTitle, $title); - } - } + } if (is_array($nameTitle)) { foreach ($nameTitle as $name => $attribs) { @@ -375,7 +344,7 @@ class CRM_Core_OptionValue { if (!empty($query->_params) || !empty($query->_returnProperties)) { $field = self::getFields(); foreach ($field as $name => $values) { - if ($values['pseudoconstant']) { + if (CRM_Utils_Array::value('pseudoconstant', $values)) { continue; } list($tableName, $fieldName) = explode('.', $values['where']); diff --git a/CRM/UF/Form/Field.php b/CRM/UF/Form/Field.php index 811173c55e..ae941873df 100644 --- a/CRM/UF/Form/Field.php +++ b/CRM/UF/Form/Field.php @@ -407,6 +407,7 @@ class CRM_UF_Form_Field extends CRM_Core_Form { } } + // CRM_Core_Error::debug(array($sel1, $sel2, $sel3, $sel4)); $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); // proper interpretation of spec in CRM-8732 diff --git a/xml/schema/Contact/Contact.xml b/xml/schema/Contact/Contact.xml index 6f36583ba9..5e8ae10894 100644 --- a/xml/schema/Contact/Contact.xml +++ b/xml/schema/Contact/Contact.xml @@ -342,6 +342,7 @@ /^(prefix|title)/i /^(mr|ms|mrs|sir|dr)\.?$/i + true 1.2 @@ -356,6 +357,7 @@ individual_suffix + true Suffix for name (Jr, Sr...). FK to suffix ID /^suffix$/i /^(sr|jr)\.?|i{2,}$/ @@ -484,6 +486,7 @@ /^gender$/i FK to gender ID + true 1.2 -- 2.25.1