Merge pull request #22458 from eileenmcnaughton/test
[civicrm-core.git] / CRM / Event / BAO / Participant.php
index f32cef2b59fa0f09f1aa799083e6ac4f5075417a..ed4ef1e67ebc7f84aee60a712ee477ef92851628 100644 (file)
@@ -44,12 +44,6 @@ class CRM_Event_BAO_Participant extends CRM_Event_DAO_Participant {
     'Pending from approval' => ['Registered', 'Cancelled'],
   ];
 
-  /**
-   */
-  public function __construct() {
-    parent::__construct();
-  }
-
   /**
    * Takes an associative array and creates a participant object.
    *
@@ -798,7 +792,7 @@ WHERE  civicrm_participant.id = {$participantId}
    *
    * @param array $defaults
    * @param string $property
-   * @param string $lookup
+   * @param string[] $lookup
    * @param bool $reverse
    *
    * @return bool
@@ -1197,7 +1191,6 @@ UPDATE  civicrm_participant
 
     //pull required participants, contacts, events  data, if not in hand
     static $eventDetails = [];
-    static $domainValues = [];
     static $contactDetails = [];
 
     $contactIds = $eventIds = $participantDetails = [];
@@ -1235,31 +1228,9 @@ UPDATE  civicrm_participant
       }
     }
 
-    //get the domain values.
-    if (empty($domainValues)) {
-      // making all tokens available to templates.
-      $domain = CRM_Core_BAO_Domain::getDomain();
-      $tokens = [
-        'domain' => ['name', 'phone', 'address', 'email'],
-        'contact' => CRM_Core_SelectValues::contactTokens(),
-      ];
-
-      foreach ($tokens['domain'] as $token) {
-        $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
-      }
-    }
-
     //get all required contacts detail.
     if (!empty($contactIds)) {
-      // get the contact details.
-      list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL,
-        FALSE, FALSE, NULL,
-        [],
-        'CRM_Event_BAO_Participant'
-      );
-      foreach ($currentContactDetails as $contactId => $contactValues) {
-        $contactDetails[$contactId] = $contactValues;
-      }
+      $contactDetails += civicrm_api3('Contact', 'get', ['id' => ['IN' => $contactIds, 'return' => 'display_name']])['values'];
     }
 
     //get all required events detail.
@@ -1327,8 +1298,7 @@ UPDATE  civicrm_participant
             $mail = self::sendTransitionParticipantMail($additionalId,
               $participantDetails[$additionalId],
               $eventDetails[$participantDetails[$additionalId]['event_id']],
-              $contactDetails[$participantDetails[$additionalId]['contact_id']],
-              $domainValues,
+              NULL,
               $emailType
             );
 
@@ -1347,8 +1317,7 @@ UPDATE  civicrm_participant
         $mail = self::sendTransitionParticipantMail($participantId,
           $participantValues,
           $eventDetails[$participantValues['event_id']],
-          $contactDetails[$participantValues['contact_id']],
-          $domainValues,
+          NULL,
           $emailType
         );
 
@@ -1394,8 +1363,6 @@ UPDATE  civicrm_participant
    *   Required event details.
    * @param array $contactDetails
    *   Required contact details.
-   * @param array $domainValues
-   *   Required domain values.
    * @param string $mailType
    *   (eg 'approval', 'confirm', 'expired' ).
    *
@@ -1406,12 +1373,17 @@ UPDATE  civicrm_participant
     $participantValues,
     $eventDetails,
     $contactDetails,
-    &$domainValues,
     $mailType
   ) {
     //send emails.
     $mailSent = FALSE;
 
+    if (!$contactDetails) {
+      $contactDetails = civicrm_api3('Contact', 'getsingle', [
+        'id' => $participantValues['contact_id'],
+        'return' => ['email', 'display_name'],
+      ]);
+    }
     //don't send confirmation mail to additional
     //since only primary able to confirm registration.
     if (!empty($participantValues['registered_by_id']) &&
@@ -1443,21 +1415,19 @@ UPDATE  civicrm_participant
         $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>';
       }
 
-      list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
+      list($mailSent, $subject) = CRM_Core_BAO_MessageTemplate::sendTemplate(
         [
-          'groupName' => 'msg_tpl_workflow_event',
-          'valueName' => 'participant_' . strtolower($mailType),
+          'workflow' => 'participant_' . strtolower($mailType),
           'contactId' => $contactId,
+          'tokenContext' => ['participantId' => $participantId],
           'tplParams' => [
-            'contact' => $contactDetails,
-            'domain' => $domainValues,
             'participant' => $participantValues,
             'event' => $eventDetails,
             'paidEvent' => $eventDetails['is_monetary'] ?? NULL,
             'isShowLocation' => $eventDetails['is_show_location'] ?? NULL,
             'isAdditional' => $participantValues['registered_by_id'],
-            'isExpired' => $mailType == 'Expired',
-            'isConfirm' => $mailType == 'Confirm',
+            'isExpired' => $mailType === 'Expired',
+            'isConfirm' => $mailType === 'Confirm',
             'checksumValue' => $checksumValue,
           ],
           'from' => $receiptFrom,
@@ -1501,7 +1471,7 @@ UPDATE  civicrm_participant
    *
    * @return string
    */
-  public function updateStatusMessage($participantId, $statusChangeTo, $fromStatusId) {
+  public static function updateStatusMessage($participantId, $statusChangeTo, $fromStatusId) {
     $statusMsg = NULL;
     $results = self::transitionParticipants([$participantId],
       $statusChangeTo, $fromStatusId, TRUE
@@ -1620,8 +1590,7 @@ UPDATE  civicrm_participant
    * @param int $newStatusId
    *   New status.
    *
-   * @return bool
-   *   true if allowed
+   * @return array
    */
   public static function getValidAdditionalIds($participantId, $oldStatusId, $newStatusId) {