Move construction of headers to ExportProcessor
authoreileen <emcnaughton@wikimedia.org>
Mon, 19 Nov 2018 03:13:40 +0000 (16:13 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 20 Nov 2018 02:35:10 +0000 (15:35 +1300)
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php

index ddf2190eed184caaa711b60d62fd3c6da3458d2e..f8b0dc44112c93caf4abcd5dbe5351bc887b9841 100644 (file)
@@ -1243,7 +1243,7 @@ WHERE  {$whereClause}";
     foreach ($returnProperties as $key => $value) {
       if (($key != 'location' || !is_array($value)) && !$processor->isRelationshipTypeKey($key)) {
         $outputColumns[$key] = $value;
-        $processor->addOutputSpecification($key, $processor->getHeaderForRow($key));
+        $processor->addOutputSpecification($key);
         self::sqlColumnDefn($processor, $sqlColumns, $key);
       }
       elseif ($processor->isRelationshipTypeKey($key)) {
@@ -1254,7 +1254,7 @@ WHERE  {$whereClause}";
           if (isset($queryFields[$relationField]['title'])) {
             if (!$processor->isHouseholdMergeRelationshipTypeKey($field)) {
               // Do not add to header row if we are only generating for merge reasons.
-              $processor->addOutputSpecification($relationField, $processor->getHeaderForRow($relationField), $key);
+              $processor->addOutputSpecification($relationField, $key);
             }
             self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $relationField);
           }
@@ -1274,7 +1274,7 @@ WHERE  {$whereClause}";
                     $hdr .= "-" . CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_IM', 'provider_id', $type[1]);
                   }
                 }
-                $processor->addOutputSpecification($field, $hdr, $key);
+                $processor->addOutputSpecification($field, $key, $ltype, CRM_Utils_Array::value(1, $type));
                 self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $hdr);
               }
             }
@@ -1304,7 +1304,7 @@ WHERE  {$whereClause}";
               $metadata[$daoFieldName]['pseudoconstant']['var'] = 'imProviders';
             }
             self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName);
-            $processor->addOutputSpecification($outputFieldName, $processor->getHeaderForRow($outputFieldName));
+            $processor->addOutputSpecification($outputFieldName, NULL, $locationType, CRM_Utils_Array::value(1, $type));
             self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName);
             if ($actualDBFieldName == 'country' || $actualDBFieldName == 'world_region') {
               $metadata[$daoFieldName] = array('context' => 'country');
index c87b8dc99a01c62857356b0d7fb0082830b16bc8..72f99b32a74ecac33806c3efbdb2ed6edf50149a 100644 (file)
@@ -443,16 +443,33 @@ class CRM_Export_BAO_ExportProcessor {
 
   /**
    * Add a row to the specification for how to output data.
+   *
    * @param string $key
-   * @param string $label
    * @param string $relationshipType
+   * @param string $locationType
+   * @param int $entityTypeID phone_type_id or provider_id for phone or im fields.
    */
-  public function addOutputSpecification($key, $label, $relationshipType = NULL) {
-    $labelPrefix = '';
+  public function addOutputSpecification($key, $relationshipType = NULL, $locationType = NULL, $entityTypeID = NULL) {
+    $label = $this->getHeaderForRow($key);
+    $labelPrefix = $fieldPrefix = [];
     if ($relationshipType) {
-      $labelPrefix = $this->getRelationshipTypes()[$relationshipType] . '-';
+      $labelPrefix[] = $this->getRelationshipTypes()[$relationshipType];
+      $fieldPrefix[] = $relationshipType;
+    }
+    if ($locationType) {
+      $labelPrefix[] = $fieldPrefix[] = $locationType;
+    }
+    if ($entityTypeID) {
+      if ($key === 'phone') {
+        $labelPrefix[] = $fieldPrefix[] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Phone', 'phone_type_id', $entityTypeID);
+      }
+      if ($key === 'im') {
+        $labelPrefix[] = $fieldPrefix[] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_IM', 'provider_id', $entityTypeID);
+      }
     }
-    $this->outputSpecification[$key]['header'] = $labelPrefix . $label;
+    $index = ($fieldPrefix ? (implode('-', $fieldPrefix)  . '-') : '') . $key;
+    $this->outputSpecification[$index]['header'] = ($labelPrefix ? (implode('-', $labelPrefix) . '-') : '') . $label;
+
   }
 
   /**