X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FForm%2FTask%2FEmail.php;h=da4b638b3620fdd5b3ab39f2cd3792618351abad;hb=08fb3005072e1081bcc43b34ea2fb4cd2d983907;hp=7fb87e4c97f78ebd041c0e5320754e6bfe46b521;hpb=5523b6616a7413f5a7bbbea6c32896485041864b;p=civicrm-core.git diff --git a/CRM/Contribute/Form/Task/Email.php b/CRM/Contribute/Form/Task/Email.php index 7fb87e4c97..da4b638b36 100644 --- a/CRM/Contribute/Form/Task/Email.php +++ b/CRM/Contribute/Form/Task/Email.php @@ -15,6 +15,8 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\Contribution; + /** * This class provides the functionality to email a group of contacts. */ @@ -32,4 +34,35 @@ class CRM_Contribute_Form_Task_Email extends CRM_Contribute_Form_Task { return $this->getIDs(); } + /** + * Get the result rows to email. + * + * @return array + * + * @throws \API_Exception + * @throws \CRM_Core_Exception + */ + protected function getRows(): array { + $contributionDetails = Contribution::get(FALSE) + ->setSelect(['contact_id', 'id']) + ->addWhere('id', 'IN', $this->getContributionIDs()) + ->execute() + // Note that this indexing means that only the last + // contribution per contact is resolved to tokens. + // this is long-standing functionality, albeit possibly + // not thought through. + ->indexBy('contact_id'); + + // format contact details array to handle multiple emails from same contact + $formattedContactDetails = []; + foreach ($this->getEmails() as $details) { + $formattedContactDetails[$details['contact_id'] . '::' . $details['email']] = $details; + if (!empty($contributionDetails[$details['contact_id']])) { + $formattedContactDetails[$details['contact_id'] . '::' . $details['email']]['schema'] = ['contributionId' => $contributionDetails[$details['contact_id']]['id']]; + } + + } + return $formattedContactDetails; + } + }