From: eileen Date: Sat, 9 Jun 2018 07:24:31 +0000 (+1200) Subject: Further minor function extraction on Export class X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=814065a3a177a4e59993eac9d9e63b066a188a62;p=civicrm-core.git Further minor function extraction on Export class --- diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 0ac6d402a2..cbc1c91644 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -620,31 +620,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $contactA = 'contact_id_b'; $contactB = 'contact_id_a'; } - if ($exportMode == CRM_Export_Form_Select::CONTACT_EXPORT) { - $relIDs = $ids; - } - elseif ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) { - $sourceID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Source'); - $dao = CRM_Core_DAO::executeQuery(" - SELECT contact_id FROM civicrm_activity_contact - WHERE activity_id IN ( " . implode(',', $ids) . ") AND - record_type_id = {$sourceID} - "); - - while ($dao->fetch()) { - $relIDs[] = $dao->contact_id; - } - } - else { - $component = self::exportComponent($exportMode); - - if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) { - $relIDs = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($ids); - } - else { - $relIDs = CRM_Core_DAO::getContactIDsFromComponent($ids, $component); - } - } + $relIDs = self::getIDsForRelatedContact($ids, $exportMode); $relationshipJoin = $relationshipClause = ''; if (!$selectAll && $componentTable) { @@ -2186,4 +2162,40 @@ WHERE {$whereClause}"; } } + /** + * Get the ids that we want to get related contact details for. + * + * @param array $ids + * @param int $exportMode + * + * @return array + */ + protected static function getIDsForRelatedContact($ids, $exportMode) { + if ($exportMode == CRM_Export_Form_Select::CONTACT_EXPORT) { + return $ids; + } + if ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) { + $relIDs = []; + $sourceID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Source'); + $dao = CRM_Core_DAO::executeQuery(" + SELECT contact_id FROM civicrm_activity_contact + WHERE activity_id IN ( " . implode(',', $ids) . ") AND + record_type_id = {$sourceID} + "); + + while ($dao->fetch()) { + $relIDs[] = $dao->contact_id; + } + return $relIDs; + } + $component = self::exportComponent($exportMode); + + if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) { + return CRM_Case_BAO_Case::retrieveContactIdsByCaseId($ids); + } + else { + return CRM_Core_DAO::getContactIDsFromComponent($ids, $component); + } + } + } diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 19a7bc8262..496a9e74bb 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -35,7 +35,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { protected $masterAddressID; public function tearDown() { - $this->quickCleanup(['civicrm_contact', 'civicrm_email', 'civicrm_address']); + $this->quickCleanup(['civicrm_contact', 'civicrm_email', 'civicrm_address', 'civicrm_relationship']); $this->quickCleanUpFinancialEntities(); parent::tearDown(); }