1 <?php
2 /* --------------------------------------------------------------
3 Email.inc.php 2015-01-29 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('EmailInterface');
13
14 /**
15 * Class representing the database entity of an email.
16 *
17 * @category System
18 * @package Email
19 * @subpackage Entities
20 */
21 class Email implements EmailInterface
22 {
23 /**
24 * E-Mail ID.
25 * @var int
26 */
27 protected $id;
28
29 /**
30 * E-Mail sender.
31 * @var EmailContactInterface
32 */
33 protected $sender;
34
35 /**
36 * E-Mail recipient.
37 * @var EmailContactInterface
38 */
39 protected $recipient;
40
41 /**
42 * E-Mail reply-to contact.
43 * @var EmailContactInterface
44 */
45 protected $replyTo;
46
47 /**
48 * E-Mail subject.
49 * @var EmailSubjectInterface
50 */
51 protected $subject;
52
53 /**
54 * E-Mail plain content
55 * @var EmailContentInterface
56 */
57 protected $contentPlain;
58
59 /**
60 * E-Mail HTML content.
61 * @var EmailContentInterface
62 */
63 protected $contentHtml;
64
65 /**
66 * E-Mail attachments.
67 * @var AttachmentCollectionInterface
68 */
69 protected $attachments;
70
71 /**
72 * E-Mail BCC.
73 * @var ContactCollectionInterface
74 */
75 protected $bcc;
76
77 /**
78 * E-Mail CC.
79 * @var ContactCollectionInterface
80 */
81 protected $cc;
82
83 /**
84 * Is E-Mail pending?
85 * @var bool
86 */
87 protected $isPending;
88
89 /**
90 * Create date time.
91 * @var DateTime
92 */
93 protected $creationDate;
94
95 /**
96 * Sent date time.
97 * @var DateTime
98 */
99 protected $sentDate;
100
101
102 /**
103 * Class Constructor
104 *
105 * All parameters are optional and can be set after the creation of the Email
106 * object. All class properties will have "null" as default value.
107 *
108 * @param EmailContactInterface $sender (optional) E-Mail sender.
109 * @param EmailContactInterface $recipient (optional) E-Mail recipient.
110 * @param EmailSubjectInterface $subject (optional) E-Mail subject.
111 * @param EmailContentInterface $contentHtml (optional) E-Mail HTML content.
112 * @param EmailContentInterface $contentPlain (optional) E-Mail plain content.
113 */
114 public function __construct(EmailContactInterface $sender = null,
115 EmailContactInterface $recipient = null,
116 EmailSubjectInterface $subject = null,
117 EmailContentInterface $contentHtml = null,
118 EmailContentInterface $contentPlain = null)
119 {
120 // Required Email Properties
121 $this->sender = $sender;
122 $this->recipient = $recipient;
123 $this->subject = $subject;
124 $this->contentHtml = $contentHtml;
125 $this->contentPlain = $contentPlain;
126
127 // Optional Email Properties
128 $this->id = null;
129 $this->bcc = MainFactory::create('ContactCollection');
130 $this->cc = MainFactory::create('ContactCollection');
131 $this->attachments = MainFactory::create('AttachmentCollection');
132 $this->isPending = true;
133 $this->creationDate = new DateTime(); // Current datetime as default value.
134 $this->sentDate = null;
135 }
136
137
138 /**
139 * Sets the ID of an email.
140 *
141 * @param IdType $id E-Mail ID.
142 */
143 public function setId(IdType $id)
144 {
145 $this->id = (int)(string)$id;
146 }
147
148
149 /**
150 * Returns the ID of an email.
151 *
152 * @return IdType E-Mail ID.
153 */
154 public function getId()
155 {
156 return $this->id;
157 }
158
159
160 /**
161 * Sets the sender of an email.
162 *
163 * @param EmailContactInterface $sender E-Mail sender.
164 */
165 public function setSender(EmailContactInterface $sender)
166 {
167 $this->sender = $sender;
168 }
169
170
171 /**
172 * Returns the sender of an email
173 *
174 * @return EmailContactInterface E-Mail sender.
175 */
176 public function getSender()
177 {
178 return $this->sender;
179 }
180
181
182 /**
183 * Sets the recipient of an email.
184 *
185 * @param EmailContactInterface $recipient E-Mail recipient.
186 */
187 public function setRecipient(EmailContactInterface $recipient)
188 {
189 $this->recipient = $recipient;
190 }
191
192
193 /**
194 * Returns the recipient of an email.
195 *
196 * @return EmailContactInterface E-Mail recipient.
197 */
198 public function getRecipient()
199 {
200 return $this->recipient;
201 }
202
203
204 /**
205 * Sets the 'reply to' option value of an email.
206 *
207 * @param EmailContactInterface $recipient E-Mail reply-to.
208 */
209 public function setReplyTo(EmailContactInterface $recipient)
210 {
211 $this->replyTo = $recipient;
212 }
213
214
215 /**
216 * Returns the 'reply to' option value of an email.
217 *
218 * @return EmailContactInterface E-Mail reply-to.
219 */
220 public function getReplyTo()
221 {
222 return $this->replyTo;
223 }
224
225
226 /**
227 * Sets the subject of an email.
228 *
229 * @param EmailSubjectInterface $subject E-Mail subject.
230 */
231 public function setSubject(EmailSubjectInterface $subject)
232 {
233 $this->subject = $subject;
234 }
235
236
237 /**
238 * Returns the subject of an email.
239 *
240 * @return EmailSubjectInterface E-Mail subject.
241 */
242 public function getSubject()
243 {
244 return $this->subject;
245 }
246
247
248 /**
249 * Sets the plain content of an email.
250 *
251 * @param EmailContentInterface $contentPlain E-Mail plain content.
252 */
253 public function setContentPlain(EmailContentInterface $contentPlain)
254 {
255 $this->contentPlain = $contentPlain;
256 }
257
258
259 /**
260 * Returns the plain content of an email.
261 *
262 * @return EmailContentInterface E-Mail plain content.
263 */
264 public function getContentPlain()
265 {
266 return $this->contentPlain;
267 }
268
269
270 /**
271 * Sets the HTML content of an email.
272 *
273 * @param EmailContentInterface $contentHtml E-Mail HTML content.
274 */
275 public function setContentHtml(EmailContentInterface $contentHtml)
276 {
277 $this->contentHtml = $contentHtml;
278 }
279
280
281 /**
282 * Returns the HTML content of an email.
283 *
284 * @return EmailContentInterface E-Mail HTML content.
285 */
286 public function getContentHtml()
287 {
288 return $this->contentHtml;
289 }
290
291
292 /**
293 * Sets the attachments of an email.
294 *
295 * @param AttachmentCollectionInterface $attachments E-Mail attachments.
296 */
297 public function setAttachments(AttachmentCollectionInterface $attachments)
298 {
299 $this->attachments = $attachments;
300 }
301
302
303 /**
304 * Returns the attachments of an email.
305 *
306 * @return AttachmentCollectionInterface E-Mail attachments.
307 */
308 public function getAttachments()
309 {
310 return $this->attachments;
311 }
312
313
314 /**
315 * Sets the BCC of an email.
316 *
317 * @param ContactCollectionInterface $bcc E-Mail BCC.
318 */
319 public function setBcc(ContactCollectionInterface $bcc)
320 {
321 $this->bcc = $bcc;
322 }
323
324
325 /**
326 * Returns the BCC of an email.
327 *
328 * @return ContactCollectionInterface E-Mail BCC.
329 */
330 public function getBcc()
331 {
332 return $this->bcc;
333 }
334
335
336 /**
337 * Sets the CC of an email.
338 *
339 * @param ContactCollectionInterface $cc E-Mail CC.
340 */
341 public function setCc(ContactCollectionInterface $cc)
342 {
343 $this->cc = $cc;
344 }
345
346
347 /**
348 * Returns the CC of an email.
349 *
350 * @return ContactCollectionInterface E-Mail CC.
351 */
352 public function getCc()
353 {
354 return $this->cc;
355 }
356
357
358 /**
359 * Sets an email status to pending if true is given, else sent.
360 *
361 * @param bool $p_isPending E-Mail pending status.
362 *
363 * @throws InvalidArgumentException If "$p_isPending" is not valid.
364 */
365 public function setPending($p_isPending)
366 {
367 if(!is_bool($p_isPending))
368 {
369 throw new InvalidArgumentException('Invalid argument provided (expected bool) $p_isPending: '
370 . print_r($p_isPending, true));
371 }
372
373 $this->isPending = (bool)$p_isPending;
374 }
375
376
377 /**
378 * Returns if an email is pending or sent.
379 *
380 * @return bool E-Mail pending status.
381 */
382 public function isPending()
383 {
384 return $this->isPending;
385 }
386
387
388 /**
389 * Sets the creation date of an email.
390 *
391 * @param DateTime $creationDate E-Mail creation date.
392 */
393 public function setCreationDate(DateTime $creationDate)
394 {
395 $this->creationDate = $creationDate;
396 }
397
398
399 /**
400 * Returns the creation date of an email.
401 *
402 * @return DateTime E-Mail creation date.
403 */
404 public function getCreationDate()
405 {
406 return $this->creationDate;
407 }
408
409
410 /**
411 * Sets the sent date of an email.
412 *
413 * @param DateTime $sentDate E-Mail sent date.
414 */
415 public function setSentDate(DateTime $sentDate)
416 {
417 $this->sentDate = $sentDate;
418 }
419
420
421 /**
422 * Returns the sent date of an email.
423 *
424 * @return DateTime E-Mail sent date.
425 */
426 public function getSentDate()
427 {
428 return $this->sentDate;
429 }
430 }