$allCampaigns = array();
$exportCampaign = FALSE;
- $phoneTypes = CRM_Core_PseudoConstant::phoneType();
- $imProviders = CRM_Core_PseudoConstant::IMProvider();
+ $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
+ $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
$contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(
NULL,
NULL,
NULL,
NULL,
TRUE,
- 'label',
+ 'name',
FALSE
);
$queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
}
if ($fields) {
//construct return properties
- $locationTypes = CRM_Core_PseudoConstant::locationType();
+ $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$locationTypeFields = array(
'street_address',
'supplemental_address_1',
$returnProperties['event_title'] = 1;
}
else if (
- $exportMode == CRM_Export_Form_Select::EVENT_EXPORT &&
+ $exportMode == CRM_Export_Form_Select::EVENT_EXPORT &&
array_key_exists( $fieldName, self::componentPaymentFields())
- ) {
+ ) {
$selectedPaymentFields = true;
$paymentTableId = 'participant_id';
- $returnProperties[$fieldName] = 1;
+ $returnProperties[$fieldName] = 1;
}
else {
$returnProperties[$fieldName] = 1;
$relIDs = $ids;
}
elseif ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) {
- $query = "SELECT source_contact_id FROM civicrm_activity
- WHERE id IN ( " . implode(',', $ids) . ")";
+ $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+ $query = "SELECT contact_id FROM civicrm_activity_contact
+ WHERE activity_id IN ( " . implode(',', $ids) . ") AND
+ record_type_id = {$sourceID}";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
- $relIDs[] = $dao->source_contact_id;
+ $relIDs[] = $dao->contact_id;
}
}
else {
$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 = '';
// get payment related in for event and members
$paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids);
//get all payment headers.
+ // If we haven't selected specific payment fields, load in all the
+ // payment headers.
if (!$selectedPaymentFields) {
$paymentHeaders = self::componentPaymentFields();
if (!empty($paymentDetails)) {
$addPaymentHeader = TRUE;
}
}
+ // If we have seleted specific payment fields, leave the payment headers
+ // as an empty array; the headers for each selected field will be added
+ // elsewhere.
+ else {
+ $paymentHeaders = array();
+ }
$nullContributionDetails = array_fill_keys(array_keys($paymentHeaders), NULL);
}
$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) {
$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
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) {
foreach (array_keys($paymentHeaders) as $paymentHdr) {
self::sqlColumnDefn($query, $sqlColumns, $paymentHdr);
}
- $addPaymentHeader = FALSE;
}
if ($setHeader) {
$setHeader = FALSE;
// If specific payment fields have been selected for export, payment
- // data will already be in $row. Otherwise, add payment related
+ // data will already be in $row. Otherwise, add payment related
// information, if appropriate.
- if (!$selectedPaymentFields) {
- if ($paymentFields) {
- $paymentData = CRM_Utils_Array::value($row[$paymentTableId], $paymentDetails);
- if (!is_array($paymentData) || empty($paymentData)) {
- $paymentData = $nullContributionDetails;
+ if ($addPaymentHeader) {
+ if (!$selectedPaymentFields) {
+ if ($paymentFields) {
+ $paymentData = CRM_Utils_Array::value($row[$paymentTableId], $paymentDetails);
+ if (!is_array($paymentData) || empty($paymentData)) {
+ $paymentData = $nullContributionDetails;
+ }
+ $row = array_merge($row, $paymentData);
+ }
+ elseif (!empty($paymentDetails)) {
+ $row = array_merge($row, $nullContributionDetails);
}
- $row = array_merge($row, $paymentData);
- }
- elseif (!empty($paymentDetails)) {
- $row = array_merge($row, $nullContributionDetails);
}
}
-
//remove organization name for individuals if it is set for current employer
if (CRM_Utils_Array::value('contact_type', $row) &&
$row['contact_type'] == 'Individual' && array_key_exists('organization_name', $row)
*
* @return string name of the file
*/
- function getExportFileName($output = 'csv', $mode = CRM_Export_Form_Select::CONTACT_EXPORT) {
+ static function getExportFileName($output = 'csv', $mode = CRM_Export_Form_Select::CONTACT_EXPORT) {
switch ($mode) {
case CRM_Export_Form_Select::CONTACT_EXPORT:
return ts('CiviCRM Contact Search');
}
static function sqlColumnDefn(&$query, &$sqlColumns, $field) {
- if (substr($field, -4) == '_a_b' ||
- substr($field, -4) == '_b_a'
- ) {
+ if (substr($field, -4) == '_a_b' || substr($field, -4) == '_b_a') {
return;
}
$fieldName = 'civicrm_primary_id';
}
+ // early exit for master_id, CRM-12100
+ // in the DB it is an ID, but in the export, we retrive the display_name of the master record
+ if ($fieldName == 'master_id') {
+ $sqlColumns[$fieldName] = "$fieldName varchar(128)";
+ return;
+ }
+
// set the sql columns
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;