Merge pull request #1373 from ravishnair/CRM-13037
[civicrm-core.git] / CRM / Export / BAO / Export.php
index 57e4ad7a2767e4cbfd9ff4aa547636101548fa3c..99436550e003cc5819f23527eb368839a7f8b5f0 100644 (file)
@@ -483,15 +483,17 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
               $component = 'civicrm_pledge';
               break;
 
-            case CRM_Export_Form_Select::CASE_EXPORT:
-              $component = 'civicrm_case';
-              break;
-
             case CRM_Export_Form_Select::GRANT_EXPORT:
               $component = 'civicrm_grant';
               break;
           }
-          $relIDs = CRM_Core_DAO::getContactIDsFromComponent($ids, $component);
+
+          if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
+            $relIDs = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($ids);
+          }
+          else {
+            $relIDs = CRM_Core_DAO::getContactIDsFromComponent($ids, $component);
+          }
         }
 
         $relationshipJoin = $relationshipClause = '';
@@ -630,6 +632,9 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
         $count++;
         $row = array();
 
+        //convert the pseudo constants
+        $query->convertToPseudoNames($dao);
+
         //first loop through returnproperties so that we return what is required, and in same order.
         $relationshipField = 0;
         foreach ($returnProperties as $field => $value) {
@@ -785,6 +790,9 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
             $row[$field] = $dao->contact_id;
             // special case for calculated field
           }
+          elseif ($field == 'source_contact_id') {
+            $row[$field] = $dao->contact_id;
+          }
           elseif ($field == 'pledge_balance_amount') {
             $row[$field] = $dao->pledge_amount - $dao->pledge_total_paid;
             // special case for calculated field
@@ -792,6 +800,17 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
           elseif ($field == 'pledge_next_pay_amount') {
             $row[$field] = $dao->pledge_next_pay_amount + $dao->pledge_outstanding_amount;
           }
+          elseif ($field == 'prefix_id' || $field == 'suffix_id' || $field == 'gender_id') {
+            if ($field == 'prefix_id') {
+              $row[$field] = $dao->individual_prefix;
+            }
+            elseif ($field == 'suffix_id') {
+              $row[$field] = $dao->individual_suffix;
+            }
+            else {
+              $row[$field] = $dao->gender;
+            }
+          }
           elseif (is_array($value) && $field == 'location') {
             // fix header for location type case
             foreach ($value as $ltype => $val) {
@@ -1230,7 +1249,6 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
     if (isset($query->_fields[$field]['type'])) {
       switch ($query->_fields[$field]['type']) {
         case CRM_Utils_Type::T_INT:
-        case CRM_Utils_Type::T_BOOL:
         case CRM_Utils_Type::T_BOOLEAN:
           $sqlColumns[$fieldName] = "$fieldName varchar(16)";
           break;