Skip to content

Commit

Permalink
Further minor function extraction on Export class
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jun 9, 2018
1 parent ca952de commit 814065a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
62 changes: 37 additions & 25 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,31 +620,7 @@ public static function exportComponents(
$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) {
Expand Down Expand Up @@ -2186,4 +2162,40 @@ private static function fetchRelationshipDetails($relDAO, $value, $field, &$row)
}
}

/**
* 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);
}
}

}
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 814065a

Please sign in to comment.