CRM-14264 : start using xml for gender / suffix / prefix
authorDonald A. Lobo <lobo@civicrm.org>
Wed, 1 May 2013 01:31:47 +0000 (18:31 -0700)
committerColeman Watts <coleman@civicrm.org>
Wed, 29 May 2013 21:57:17 +0000 (14:57 -0700)
----------------------------------------
* CRM-14264:
  http://issues.civicrm.org/jira/browse/CRM-14264

CRM/Contact/BAO/Contact.php
CRM/Contact/BAO/Query.php
CRM/Contact/Selector.php
CRM/Core/BAO/UFGroup.php
CRM/Core/OptionValue.php
CRM/UF/Form/Field.php
xml/schema/Contact/Contact.xml

index ba0816aae61254f92df57958d2a0305417687d16..16187e10e2000aec23b1d31408383d2483db4a34 100644 (file)
@@ -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',
             ),
           );
index acfd596bcdb8bca42c4b753d3b843715bc064645..03c72a933f8a10b43186ccdb30f4ad26fd105ec3 100644 (file)
@@ -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);
index a44c79f212be16c706f852c5b0c746163a60ab83..06c9a7ad568446548e29994a281cd4e888955e9d 100644 (file)
@@ -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 = '';
index 5828be16ba0ba45060244a3ae9fdc62cfee33b26..acbeff7fc660bd6ed596441ab47ca3a345128bac 100644 (file)
@@ -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,
     );
 
index cd3a892e54ea6e5f0fb88843fe1c4c212d182f06..c2d7f0f546a011f1dbaae379b95a5846d313c1a9 100644 (file)
@@ -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']);
index 811173c55e093ccabe48016f7a83abb83be4e882..ae941873df456e52b5074eb1427b467d75853922 100644 (file)
@@ -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
index 6f36583ba993f9ba543a7e23d4279e771819a7c9..5e8ae1089483c73dfa591c59d775601f829c311c 100644 (file)
       </pseudoconstant>
       <headerPattern>/^(prefix|title)/i</headerPattern>
       <dataPattern>/^(mr|ms|mrs|sir|dr)\.?$/i</dataPattern>
+      <import>true</import>
       <add>1.2</add>
   </field>
   <index>
       <pseudoconstant>
         <optionGroupName>individual_suffix</optionGroupName>
       </pseudoconstant>
+      <import>true</import>
       <comment>Suffix for name (Jr, Sr...). FK to suffix ID</comment>
       <headerPattern>/^suffix$/i</headerPattern>
       <dataPattern>/^(sr|jr)\.?|i{2,}$/</dataPattern>
       </pseudoconstant>
       <headerPattern>/^gender$/i</headerPattern>
       <comment>FK to gender ID</comment>
+      <import>true</import>
       <add>1.2</add>
   </field>
   <index>