From f34f5143d8022471d786e406c6f5a343aab6094d Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 28 Aug 2015 00:01:27 +0000 Subject: [PATCH] Split up some of CRM_Export_BAO_Export::ExportComponents into smaller tighter functions --- CRM/Export/BAO/Export.php | 193 +++++++++++++++++++++++--------------- 1 file changed, 115 insertions(+), 78 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 0d4326b65d..aa8c662724 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -43,6 +43,117 @@ class CRM_Export_BAO_Export { // CRM-7675 const EXPORT_ROW_COUNT = 10000; + /** + * Get Querymode based on ExportMode + * + * @param int $exportMode + * Export mode. + * + * return string Querymode + */ + public function getQueryMode($exportMode) { + 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 returnProperties + */ + function defultReturnProperty($exportMode) { + // 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; + } + return $returnProperties; + } + + /** + * Get Export component + * + * @param int $exportMode + * Export mode. + * + * return string component + */ + public 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. * @@ -106,35 +217,8 @@ class CRM_Export_BAO_Export { ); $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; - } + $queryMode = self::getQueryMode($exportMode); + if ($fields) { //construct return properties $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); @@ -247,34 +331,7 @@ class CRM_Export_BAO_Export { } } } - - // 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; - } - } + self::defultReturnProperty($exportMode); else { $primary = TRUE; $fields = CRM_Contact_BAO_Contact::exportableFields('All', TRUE, TRUE); @@ -473,27 +530,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c } } 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; - } + self::exportComponent($exportMode); if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) { $relIDs = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($ids); -- 2.25.1