Export Move relationship type definition to processor class
authoreileen <emcnaughton@wikimedia.org>
Wed, 18 Jul 2018 11:47:29 +0000 (23:47 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 20 Jul 2018 21:37:16 +0000 (09:37 +1200)
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php

index 4a25bfbee3dd392b00e292ec94bd2af3dbeacd50..478942d0b1207775a675d071b74039dfb40605bb 100644 (file)
@@ -316,15 +316,7 @@ class CRM_Export_BAO_Export {
     // Warning - this imProviders var is used in a somewhat fragile way - don't rename it
     // without manually testing the export of IM provider still works.
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
-    self::$relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      TRUE,
-      'name',
-      FALSE
-    );
+    self::$relationshipTypes = $processor->getRelationshipTypes();
     //also merge Head of Household
     self::$memberOfHouseholdRelationshipKey = CRM_Utils_Array::key('Household Member of', self::$relationshipTypes);
     self::$headOfHouseholdRelationshipKey = CRM_Utils_Array::key('Head of Household for', self::$relationshipTypes);
@@ -357,7 +349,7 @@ class CRM_Export_BAO_Export {
           continue;
         }
 
-        if (array_key_exists($fieldName, self::$relationshipTypes) && (!empty($value[2]) || !empty($value[4]))) {
+        if ($processor->isRelationshipTypeKey($fieldName) && (!empty($value[2]) || !empty($value[4]))) {
           self::setRelationshipReturnProperties($value, $locationTypeFields, $fieldName);
           // @todo we can later not add this to this array but maintain a separate array.
           $returnProperties = array_merge($returnProperties, self::$relationshipReturnProperties);
@@ -471,7 +463,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
       }
 
       foreach ($returnProperties as $key => $value) {
-        if (!array_key_exists($key, self::$relationshipTypes)) {
+        if (!$processor->isRelationshipTypeKey($key)) {
           $returnProperties[self::$memberOfHouseholdRelationshipKey][$key] = $value;
           $returnProperties[self::$headOfHouseholdRelationshipKey][$key] = $value;
         }
@@ -631,7 +623,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
             }
           }
 
-          if (array_key_exists($field, self::$relationshipTypes)) {
+          if ($processor->isRelationshipTypeKey($field)) {
             $relDAO = CRM_Utils_Array::value($iterationDAO->contact_id, $allRelContactArray[$field]);
             $relationQuery[$field]->convertToPseudoNames($relDAO);
             self::fetchRelationshipDetails($relDAO, $value, $field, $row);
@@ -1638,7 +1630,7 @@ WHERE  {$whereClause}";
     elseif ($field == 'provider_id') {
       $headerRows[] = ts('IM Service Provider');
     }
-    elseif (array_key_exists($field, self::$relationshipTypes)) {
+    elseif ($processor->isRelationshipTypeKey($field)) {
       foreach ($value as $relationField => $relationValue) {
         // below block is same as primary block (duplicate)
         if (isset($relationQuery[$field]->_fields[$relationField]['title'])) {
index fe9b75fa882fe96f2807f5586e279521e1411d9e..cfdc0f5881d5dc93b2c2c5b4e49efcee20ad8304 100644 (file)
@@ -72,6 +72,15 @@ class CRM_Export_BAO_ExportProcessor {
    */
   protected $requestedFields;
 
+  /**
+   * Key representing the head of household in the relationship array.
+   *
+   * e.g. ['8_b_a' => 'Household Member Is', '8_a_b = 'Household Member Of'.....]
+   *
+   * @var
+   */
+  protected $relationshipTypes = [];
+
   /**
    * CRM_Export_BAO_ExportProcessor constructor.
    *
@@ -84,6 +93,7 @@ class CRM_Export_BAO_ExportProcessor {
     $this->setQueryMode();
     $this->setQueryOperator($queryOperator);
     $this->setRequestedFields($requestedFields);
+    $this->setRelationshipTypes();
   }
 
   /**
@@ -100,6 +110,36 @@ class CRM_Export_BAO_ExportProcessor {
     $this->requestedFields = $requestedFields;
   }
 
+  /**
+   * @return array
+   */
+  public function getRelationshipTypes() {
+    return $this->relationshipTypes;
+  }
+
+  /**
+   */
+  public function setRelationshipTypes() {
+    $this->relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(
+      NULL,
+      NULL,
+      NULL,
+      NULL,
+      TRUE,
+      'name',
+      FALSE
+    );
+  }
+
+
+  /**
+   * @param $fieldName
+   * @return bool
+   */
+  public function isRelationshipTypeKey($fieldName) {
+    return array_key_exists($fieldName, $this->relationshipTypes);
+  }
+
   /**
    * @return string
    */