Merge pull request #23800 from seamuslee001/ref_date_filter
[civicrm-core.git] / CRM / Contribute / Form / Task / Email.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
4f036b71
EM
18use Civi\Api4\Contribution;
19
6a488035 20/**
07f8d162 21 * This class provides the functionality to email a group of contacts.
6a488035
TO
22 */
23class CRM_Contribute_Form_Task_Email extends CRM_Contribute_Form_Task {
8a432af6 24 use CRM_Contact_Form_Task_EmailTrait;
6a488035 25
bc6e8992
EM
26 /**
27 * Get selected contribution IDs.
28 *
29 * @return array
30 *
31 * @throws \CRM_Core_Exception
32 */
33 protected function getContributionIDs(): array {
34 return $this->getIDs();
35 }
36
4f036b71
EM
37 /**
38 * Get the result rows to email.
39 *
40 * @return array
41 *
42 * @throws \API_Exception
43 * @throws \CRM_Core_Exception
44 */
45 protected function getRows(): array {
46 $contributionDetails = Contribution::get(FALSE)
47 ->setSelect(['contact_id', 'id'])
48 ->addWhere('id', 'IN', $this->getContributionIDs())
49 ->execute()
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');
55
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']];
62 }
63
64 }
65 return $formattedContactDetails;
66 }
67
6a488035 68}