<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
+ | CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
// CRM-7675
const EXPORT_ROW_COUNT = 10000;
+ /**
+ * Get Querymode based on ExportMode
+ *
+ * @param int $exportMode
+ * Export mode.
+ *
+ * return string Querymode
+ */
+ public static function getQueryMode($exportMode) {
+ $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
+
+ switch ($exportMode) {
+ case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
+ $queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
+ break;
+
+ case CRM_Export_Form_Select::EVENT_EXPORT:
+ $queryMode = CRM_Contact_BAO_Query::MODE_EVENT;
+ break;
+
+ case CRM_Export_Form_Select::MEMBER_EXPORT:
+ $queryMode = CRM_Contact_BAO_Query::MODE_MEMBER;
+ break;
+
+ case CRM_Export_Form_Select::PLEDGE_EXPORT:
+ $queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE;
+ break;
+
+ case CRM_Export_Form_Select::CASE_EXPORT:
+ $queryMode = CRM_Contact_BAO_Query::MODE_CASE;
+ break;
+
+ case CRM_Export_Form_Select::GRANT_EXPORT:
+ $queryMode = CRM_Contact_BAO_Query::MODE_GRANT;
+ break;
+
+ case CRM_Export_Form_Select::ACTIVITY_EXPORT:
+ $queryMode = CRM_Contact_BAO_Query::MODE_ACTIVITY;
+ break;
+ }
+ return $queryMode;
+ }
+
+ /**
+ * Get default return property for export based on mode
+ *
+ * @param int $exportMode
+ * Export mode.
+ *
+ * return string $property
+ */
+ public static function defaultReturnProperty($exportMode) {
+ // hack to add default returnproperty based on export mode
+ if ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
+ $property = 'contribution_id';
+ }
+ elseif ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
+ $property = 'participant_id';
+ }
+ elseif ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
+ $property = 'membership_id';
+ }
+ elseif ($exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
+ $property = 'pledge_id';
+ }
+ elseif ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
+ $property = 'case_id';
+ }
+ elseif ($exportMode == CRM_Export_Form_Select::GRANT_EXPORT) {
+ $property = 'grant_id';
+ }
+ elseif ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) {
+ $property = 'activity_id';
+ }
+ return $property;
+ }
+
+ /**
+ * Get Export component
+ *
+ * @param int $exportMode
+ * Export mode.
+ *
+ * return string component
+ */
+ public static function exportComponent($exportMode) {
+ switch ($exportMode) {
+ case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
+ $component = 'civicrm_contribution';
+ break;
+
+ case CRM_Export_Form_Select::EVENT_EXPORT:
+ $component = 'civicrm_participant';
+ break;
+
+ case CRM_Export_Form_Select::MEMBER_EXPORT:
+ $component = 'civicrm_membership';
+ break;
+
+ case CRM_Export_Form_Select::PLEDGE_EXPORT:
+ $component = 'civicrm_pledge';
+ break;
+
+ case CRM_Export_Form_Select::GRANT_EXPORT:
+ $component = 'civicrm_grant';
+ break;
+ }
+ return $component;
+ }
+
/**
* Get the list the export fields.
*
'name',
FALSE
);
- $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
-
- switch ($exportMode) {
- case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
- $queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
- break;
-
- case CRM_Export_Form_Select::EVENT_EXPORT:
- $queryMode = CRM_Contact_BAO_Query::MODE_EVENT;
- break;
-
- case CRM_Export_Form_Select::MEMBER_EXPORT:
- $queryMode = CRM_Contact_BAO_Query::MODE_MEMBER;
- break;
-
- case CRM_Export_Form_Select::PLEDGE_EXPORT:
- $queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE;
- break;
- case CRM_Export_Form_Select::CASE_EXPORT:
- $queryMode = CRM_Contact_BAO_Query::MODE_CASE;
- break;
+ $queryMode = self::getQueryMode($exportMode);
- case CRM_Export_Form_Select::GRANT_EXPORT:
- $queryMode = CRM_Contact_BAO_Query::MODE_GRANT;
- break;
-
- case CRM_Export_Form_Select::ACTIVITY_EXPORT:
- $queryMode = CRM_Contact_BAO_Query::MODE_ACTIVITY;
- break;
- }
if ($fields) {
//construct return properties
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
if (!$fieldName) {
continue;
}
- // get phoneType id and IM service provider id seperately
+ // get phoneType id and IM service provider id separately
if ($fieldName == 'phone') {
$phoneTypeId = CRM_Utils_Array::value(3, $value);
}
}
}
}
-
- // hack to add default returnproperty based on export mode
- if ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
- $returnProperties['contribution_id'] = 1;
- }
- elseif ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
- $returnProperties['participant_id'] = 1;
- if (!empty($returnProperties['participant_role'])) {
- unset($returnProperties['participant_role']);
- $returnProperties['participant_role_id'] = 1;
- }
- }
- elseif ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
- $returnProperties['membership_id'] = 1;
- }
- elseif ($exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
- $returnProperties['pledge_id'] = 1;
- }
- elseif ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
- $returnProperties['case_id'] = 1;
- }
- elseif ($exportMode == CRM_Export_Form_Select::GRANT_EXPORT) {
- $returnProperties['grant_id'] = 1;
- }
- elseif ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) {
- $returnProperties['activity_id'] = 1;
- }
+ $returnProperties[self::defaultReturnProperty($exportMode)] = 1;
}
else {
$primary = TRUE;
}
}
else {
- switch ($exportMode) {
- case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
- $component = 'civicrm_contribution';
- break;
-
- case CRM_Export_Form_Select::EVENT_EXPORT:
- $component = 'civicrm_participant';
- break;
-
- case CRM_Export_Form_Select::MEMBER_EXPORT:
- $component = 'civicrm_membership';
- break;
-
- case CRM_Export_Form_Select::PLEDGE_EXPORT:
- $component = 'civicrm_pledge';
- break;
-
- case CRM_Export_Form_Select::GRANT_EXPORT:
- $component = 'civicrm_grant';
- break;
- }
+ $component = self::exportComponent($exportMode);
if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
$relIDs = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($ids);
$excludeTrashed = FALSE;
}
}
- if (empty($where) && $excludeTrashed) {
- $where = "WHERE contact_a.is_deleted != 1";
+ $trashClause = $excludeTrashed ? "contact_a.is_deleted != 1" : "( 1 )";
+
+ if (empty($where)) {
+ $where = "WHERE $trashClause";
}
- elseif ($excludeTrashed) {
- $where .= " AND contact_a.is_deleted != 1";
+ else {
+ $where .= " AND $trashClause";
}
$queryString = "$select $from $where $having";
elseif ($field == 'provider_id' || $field == 'im_provider') {
$fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
}
- elseif ($field == 'participant_role_id') {
- $participantRoles = CRM_Event_PseudoConstant::participantRole();
- $sep = CRM_Core_DAO::VALUE_SEPARATOR;
- $viewRoles = array();
- foreach (explode($sep, $iterationDAO->$field) as $k => $v) {
- $viewRoles[] = $participantRoles[$v];
- }
- $fieldValue = implode(',', $viewRoles);
- }
elseif ($field == 'master_id') {
$masterAddressId = NULL;
if (isset($iterationDAO->master_id)) {
$errorFileName = $parserName::errorFileName($type);
$saveFileName = $parserName::saveFileName($type);
if (!empty($errorFileName) && !empty($saveFileName)) {
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Content-Description: File Transfer');
- header('Content-Type: text/csv');
- header('Content-Length: ' . filesize($errorFileName));
- header('Content-Disposition: attachment; filename=' . $saveFileName);
+ CRM_Utils_System::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
+ CRM_Utils_System::setHttpHeader('Content-Description', 'File Transfer');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv');
+ CRM_Utils_System::setHttpHeader('Content-Length', filesize($errorFileName));
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . $saveFileName);
readfile($errorFileName);
}
else {
if (substr($fieldName, -3, 3) == '_id') {
// for trxn_id and its variants use a longer buffer
- // to accomodate different systems - CRM-13739
+ // to accommodate different systems - CRM-13739
static $notRealIDFields = NULL;
if ($notRealIDFields == NULL) {
$notRealIDFields = array('trxn_id', 'componentpaymentfield_transaction_id');
$componentPaymentFields = array(
'componentPaymentField_total_amount' => ts('Total Amount'),
'componentPaymentField_contribution_status' => ts('Contribution Status'),
- 'componentPaymentField_received_date' => ts('Received Date'),
- 'componentPaymentField_payment_instrument' => ts('Payment Instrument'),
+ 'componentPaymentField_received_date' => ts('Date Received'),
+ 'componentPaymentField_payment_instrument' => ts('Payment Method'),
'componentPaymentField_transaction_id' => ts('Transaction ID'),
);
}