3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 use Civi\Api4\Contribution
;
21 * This class provides the functionality to email a group of contacts.
23 class CRM_Contribute_Form_Task_Email
extends CRM_Contribute_Form_Task
{
24 use CRM_Contact_Form_Task_EmailTrait
;
27 * Get selected contribution IDs.
31 * @throws \CRM_Core_Exception
33 protected function getContributionIDs(): array {
34 return $this->getIDs();
38 * Get the result rows to email.
42 * @throws \API_Exception
43 * @throws \CRM_Core_Exception
45 protected function getRows(): array {
46 $contributionDetails = Contribution
::get(FALSE)
47 ->setSelect(['contact_id', 'id'])
48 ->addWhere('id', 'IN', $this->getContributionIDs())
50 // Note that this indexing means that only the last
51 // contribution per contact is resolved to tokens.
52 // this is long-standing functionality, albeit possibly
53 // not thought through.
54 ->indexBy('contact_id');
56 // format contact details array to handle multiple emails from same contact
57 $formattedContactDetails = [];
58 foreach ($this->getEmails() as $details) {
59 $formattedContactDetails[$details['contact_id'] . '::' . $details['email']] = $details;
60 if (!empty($contributionDetails[$details['contact_id']])) {
61 $formattedContactDetails[$details['contact_id'] . '::' . $details['email']]['schema'] = ['contributionId' => $contributionDetails[$details['contact_id']]['id']];
65 return $formattedContactDetails;