Move replace merge tokens to processor class
authoreileen <emcnaughton@wikimedia.org>
Thu, 11 Jul 2019 21:02:43 +0000 (09:02 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 11 Jul 2019 21:02:43 +0000 (09:02 +1200)
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php

index 57f5ba5f0903f8ed9064d8cce89fba758477de2d..d27e2a36002a0f8ce17e0c6163df7fb093a8fd29 100644 (file)
@@ -690,43 +690,6 @@ WHERE  id IN ( $deleteIDString )
     }
   }
 
-  /**
-   * @param int $contactId
-   * @param array $exportParams
-   *
-   * @return array
-   */
-  public static function _replaceMergeTokens($contactId, $exportParams) {
-    $greetings = [];
-    $contact = NULL;
-
-    $greetingFields = [
-      'postal_greeting',
-      'addressee',
-    ];
-    foreach ($greetingFields as $greeting) {
-      if (!empty($exportParams[$greeting])) {
-        $greetingLabel = $exportParams[$greeting];
-        if (empty($contact)) {
-          $values = [
-            'id' => $contactId,
-            'version' => 3,
-          ];
-          $contact = civicrm_api('contact', 'get', $values);
-
-          if (!empty($contact['is_error'])) {
-            return $greetings;
-          }
-          $contact = $contact['values'][$contact['id']];
-        }
-
-        $tokens = ['contact' => $greetingLabel];
-        $greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
-      }
-    }
-    return $greetings;
-  }
-
   /**
    * @param \CRM_Export_BAO_ExportProcessor $processor
    * @param $sql
@@ -753,7 +716,7 @@ WHERE  id IN ( $deleteIDString )
 
       if (!$sharedAddress) {
         if (!isset($contactGreetingTokens[$dao->master_contact_id])) {
-          $contactGreetingTokens[$dao->master_contact_id] = self::_replaceMergeTokens($dao->master_contact_id, $exportParams);
+          $contactGreetingTokens[$dao->master_contact_id] = $processor->replaceMergeTokens($dao->master_contact_id, $exportParams);
         }
         $masterPostalGreeting = CRM_Utils_Array::value('postal_greeting',
           $contactGreetingTokens[$dao->master_contact_id], $dao->master_postal_greeting
@@ -763,7 +726,7 @@ WHERE  id IN ( $deleteIDString )
         );
 
         if (!isset($contactGreetingTokens[$dao->copy_contact_id])) {
-          $contactGreetingTokens[$dao->copy_contact_id] = self::_replaceMergeTokens($dao->copy_contact_id, $exportParams);
+          $contactGreetingTokens[$dao->copy_contact_id] = $processor->replaceMergeTokens($dao->copy_contact_id, $exportParams);
         }
         $copyPostalGreeting = CRM_Utils_Array::value('postal_greeting',
           $contactGreetingTokens[$dao->copy_contact_id], $dao->copy_postal_greeting
index e8dce0468f2500e04930d0dcb5afc4cc6e0306b3..f407ead7ab7cfac662002c1b2446b31f247553ee 100644 (file)
@@ -1609,6 +1609,43 @@ class CRM_Export_BAO_ExportProcessor {
     return $returnProperties;
   }
 
+  /**
+   * @param int $contactId
+   * @param array $exportParams
+   *
+   * @return array
+   */
+  public function replaceMergeTokens($contactId, $exportParams) {
+    $greetings = [];
+    $contact = NULL;
+
+    $greetingFields = [
+      'postal_greeting',
+      'addressee',
+    ];
+    foreach ($greetingFields as $greeting) {
+      if (!empty($exportParams[$greeting])) {
+        $greetingLabel = $exportParams[$greeting];
+        if (empty($contact)) {
+          $values = [
+            'id' => $contactId,
+            'version' => 3,
+          ];
+          $contact = civicrm_api('contact', 'get', $values);
+
+          if (!empty($contact['is_error'])) {
+            return $greetings;
+          }
+          $contact = $contact['values'][$contact['id']];
+        }
+
+        $tokens = ['contact' => $greetingLabel];
+        $greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
+      }
+    }
+    return $greetings;
+  }
+
   /**
    * The function unsets static part of the string, if token is the dynamic part.
    *