Merge pull request #2352 from colemanw/4.4
[civicrm-core.git] / CRM / Core / BAO / UFGroup.php
index ba9703f6ec56d1f200a781bedbeea9501ec6a9a1..05fd61d48e280fcdbdaa39587dd3e771b310327e 100644 (file)
@@ -949,10 +949,9 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
       // hack for CRM-665
       if (isset($details->$name) || $name == 'group' || $name == 'tag') {
         // to handle gender / suffix / prefix
-        if (in_array(substr($name, -6), array('gender', 'prefix', 'suffix'))) {
-          $values[$index] = $details->$name;
-          $idColumn = "{$name}_id";
-          $params[$index] = $details->$idColumn;
+        if (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix'))) {
+          $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', $name, $details->$name);
+          $params[$index] = $details->$name;
         }
         elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) {
           $dname          = $name . '_display';
@@ -1179,9 +1178,8 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
           }
           elseif ($fieldName == 'im') {
             $providerId = $detailName . '-provider_id';
-            $providerName = $imProviders[$details->$providerId];
-            if ($providerName) {
-              $values[$index] = $details->$detailName . " (" . $providerName . ")";
+            if (isset($imProviders[$details->$providerId])) {
+              $values[$index] = $details->$detailName . " (" . $imProviders[$details->$providerId] . ")";
             }
             else {
               $values[$index] = $details->$detailName;
@@ -1587,7 +1585,12 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @static
    */
   public static function getModuleUFGroup($moduleName = NULL, $count = 0, $skipPermission = TRUE, $op = CRM_Core_Permission::VIEW, $returnFields = NULL) {
-    $selectFields = array('id', 'title', 'created_id', 'description', 'is_active', 'is_reserved', 'group_type');
+    $selectFields = array('id', 'title', 'created_id', 'is_active', 'is_reserved', 'group_type');
+
+    if (!CRM_Core_Config::isUpgradeMode()) {
+      // CRM-13555, since description field was added later (4.4), and to avoid any problems with upgrade
+      $selectFields[] = 'description';
+    }
 
     if (!empty($returnFields)) {
       $selectFields = array_merge($returnFields, array_diff($selectFields, $returnFields));
@@ -1857,7 +1860,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
           '' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required
       );
     }
-    elseif ($fieldName === 'gender') {
+    elseif ($fieldName === 'gender_id') {
       $genderOptions = array();
       $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
       foreach ($gender as $key => $var) {
@@ -1868,16 +1871,10 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
         $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
       }
     }
-    elseif ($fieldName === 'individual_prefix') {
-      $form->add('select', $name, $title,
-        array(
-          '' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'), $required
-      );
-    }
-    elseif ($fieldName === 'individual_suffix') {
+    elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
       $form->add('select', $name, $title,
         array(
-          '' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'), $required
+          '' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Contact_BAO_Contact', $fieldName), $required
       );
     }
     elseif ($fieldName === 'contact_sub_type') {
@@ -2363,13 +2360,15 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
                         $defaults[$fldName] = $value['county_id'];
                       }
                       elseif ($fieldName == 'country') {
-                        $defaults[$fldName] = $value['country_id'];
                         if (!isset($value['country_id']) || !$value['country_id']) {
                           $config = CRM_Core_Config::singleton();
                           if ($config->defaultContactCountry) {
                             $defaults[$fldName] = $config->defaultContactCountry;
                           }
                         }
+                        else {
+                          $defaults[$fldName] = $value['country_id'];
+                        }
                       }
                       elseif ($fieldName == 'phone') {
                         if ($phoneTypeId) {
@@ -2823,6 +2822,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
         }
       }
       else {
+        // TODO: prefix, suffix and gender translation may no longer be necessary - check inputs
         if ($key === 'individual_suffix') {
           $data['suffix_id'] = $value;
         }
@@ -3055,7 +3055,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    *
    * @return void.
    */
-  function setComponentDefaults(&$fields, $componentId, $component, &$defaults, $isStandalone = FALSE) {
+  public static function setComponentDefaults(&$fields, $componentId, $component, &$defaults, $isStandalone = FALSE) {
     if (!$componentId ||
       !in_array($component, array('Contribute', 'Membership', 'Event', 'Activity'))
     ) {