Merge pull request #23976 from civicrm/5.52
[civicrm-core.git] / ext / flexmailer / src / FlexMailerTask.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11 namespace Civi\FlexMailer;
12
13 /**
14 * Class FlexMailerTask
15 * @package Civi\FlexMailer
16 *
17 * A FlexMailerTask describes an individual message that needs to be
18 * composed and delivered. Generally, it's used in three steps:
19 * - At the start, we instantiate the task with a few inputs
20 * (e.g. $contactId and $address).
21 * - During composition, we read those values and fill-in the
22 * message's content ($task->setMailParams(...));
23 * - During delivery, we read the message ($task->getMailParams())
24 * and send it.
25 */
26 class FlexMailerTask {
27
28 /**
29 * @var int
30 * A persistent record for this email delivery.
31 * @see \CRM_Mailing_Event_DAO_Queue
32 */
33 private $eventQueueId;
34
35 /**
36 * @var int
37 * The ID of the recipiient.
38 * @see \CRM_Contact_DAO_Contact
39 */
40 private $contactId;
41
42 /**
43 * @var string
44 * An authentication code. The name is misleading - it may be hash, but
45 * that implementation detail is outside our purview.
46 */
47 private $hash;
48
49 /**
50 * @var string
51 * Selected/preferred email address of the intended recipient.
52 */
53 private $address;
54
55 /**
56 * The full email message to send to this recipient (per alterMailParams).
57 *
58 * @var array
59 * @see MailParams
60 * @see \CRM_Utils_Hook::alterMailParams()
61 */
62 private $mailParams = array();
63
64 /**
65 * FlexMailerTask constructor.
66 *
67 * @param int $eventQueueId
68 * A persistent record for this email delivery.
69 * @param int $contactId
70 * The ID of the recipiient.
71 * @param string $hash
72 * An authentication code.
73 * @param string $address
74 * Selected/preferred email address of the intended recipient.
75 */
76 public function __construct(
77 $eventQueueId,
78 $contactId,
79 $hash,
80 $address
81 ) {
82 $this->eventQueueId = $eventQueueId;
83 $this->contactId = $contactId;
84 $this->hash = $hash;
85 $this->address = $address;
86 }
87
88 /**
89 * @return int
90 * @see \CRM_Mailing_Event_DAO_Queue
91 */
92 public function getEventQueueId() {
93 return $this->eventQueueId;
94 }
95
96 /**
97 * @return int
98 * The ID of the recipiient.
99 * @see \CRM_Contact_DAO_Contact
100 */
101 public function getContactId() {
102 return $this->contactId;
103 }
104
105 /**
106 * @return string
107 * An authentication code. The name is misleading - it may be hash, but
108 * that implementation detail is outside our purview.
109 */
110 public function getHash() {
111 return $this->hash;
112 }
113
114 /**
115 * @return string
116 * Selected email address of the intended recipient.
117 */
118 public function getAddress() {
119 return $this->address;
120 }
121
122 /**
123 * @return bool
124 */
125 public function hasContent() {
126 return !empty($this->mailParams['html']) || !empty($this->mailParams['text']);
127 }
128
129 /**
130 * @return array
131 * @see CRM_Utils_Hook::alterMailParams
132 */
133 public function getMailParams() {
134 return $this->mailParams;
135 }
136
137 /**
138 * @param \array $mailParams
139 * @return FlexMailerTask
140 * @see CRM_Utils_Hook::alterMailParams
141 */
142 public function setMailParams($mailParams) {
143 $this->mailParams = $mailParams;
144 return $this;
145 }
146
147 /**
148 * @param string $key
149 * @param string $value
150 * @return $this
151 * @see CRM_Utils_Hook::alterMailParams
152 */
153 public function setMailParam($key, $value) {
154 $this->mailParams[$key] = $value;
155 return $this;
156 }
157
158 /**
159 * @param string $key
160 * @return string
161 * @see CRM_Utils_Hook::alterMailParams
162 */
163 public function getMailParam($key) {
164 return isset($this->mailParams[$key]) ? $this->mailParams[$key] : NULL;
165 }
166
167 }