1: <?php
2: namespace TIC\MailBundle\Entity;
3:
4: use Doctrine\ORM\Mapping as ORM;
5: use TIC\MailBundle\Repository\MaillogRepository as EntityRepo;
6:
7: /**
8: * Entité représentant un évènement du journal des envois.
9: * @ORM\Table(name="tic_mail_maillog")
10: * @ORM\Entity(repositoryClass=EntityRepo::class)
11: */
12: class Maillog
13: {
14:
15: // --------------------------------------------------------------------- Properties
16:
17: /**
18: * @ORM\Column(type="integer")
19: * @ORM\GeneratedValue(strategy="AUTO")
20: * @ORM\Id
21: */
22: private $id;
23:
24: /**
25: * @ORM\Column(type="string", length=100, nullable=true)
26: */
27: private $template;
28:
29: /**
30: * @ORM\Column(type="string", length=10, nullable=true)
31: */
32: private $locale;
33:
34: /**
35: * @ORM\Column(type="string", length=250, nullable=true)
36: */
37: private $returnPath;
38:
39: /**
40: * @ORM\Column(type="string", length=250, nullable=true)
41: */
42: private $mailFrom;
43:
44: /**
45: * @ORM\Column(type="string", length=250, nullable=true)
46: */
47: private $mailRcpt;
48:
49: /**
50: * @ORM\Column(type="string", length=250, nullable=true)
51: */
52: private $mailBcc;
53:
54: /**
55: * @ORM\Column(type="string", length=250, nullable=true)
56: */
57: private $subject;
58:
59: /**
60: * @ORM\Column(type="text", nullable=true)
61: */
62: private $body;
63:
64: /**
65: * @ORM\Column(type="string", length=25, nullable=true)
66: */
67: private $contentType;
68:
69: /**
70: * #ORM\Column(type="text", nullable=true)
71: */
72: # private $data;
73:
74: /**
75: * @ORM\Column(type="string", length=250, nullable=true)
76: */
77: private $messageId;
78:
79: /**
80: * @ORM\Column(type="smallint", nullable=true)
81: */
82: private $sendCode;
83:
84: /**
85: * @ORM\Column(type="string", length=250, nullable=true)
86: */
87: private $errorMsg;
88:
89: /**
90: * @ORM\Column(type="string", length=250)
91: */
92: private $origin;
93:
94: /**
95: * @ORM\Column(type="datetime")
96: */
97: private $createdAt;
98:
99:
100: // --------------------------------------------------------------------- Custom methods
101:
102: public function __construct(array $data = null)
103: {
104: $this->origin = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : \implode(" ", $_SERVER["argv"]);
105: $this->createdAt = new \DateTime("now");
106: if ($data !== null) $this->loadData($data);
107: }
108:
109: public function __toString()
110: {
111: return \sprint("[%s] %s", $this->createdAt->format('Y-m-d H:i:s'), $this->subject);
112: }
113:
114: public function loadData(array $data = []): void
115: {
116: foreach ($data as $field => $value) {
117: $mutator = "set" . \ucfirst($field);
118: if (! \method_exists($this, $mutator)) continue;
119:
120: # if (\is_array($value)) $value = \implode(', ', $value);
121: \call_user_func(array($this, $mutator), $value);
122: }
123: }
124:
125:
126: // --------------------------------------------------------------------- Tweaked methods
127:
128: /**
129: * Set mailFrom
130: * @param string|array $mailFrom
131: * @return Maillog
132: */
133: public function setMailFrom($mailFrom): self
134: {
135: if (\is_array($mailFrom)) $mailFrom = \implode(', ', $mailFrom);
136: $this->mailFrom = $mailFrom;
137: return $this;
138: }
139:
140: /**
141: * Set mailRcpt
142: * @param string|array $mailRcpt
143: * @return Maillog
144: */
145: public function setMailRcpt($mailRcpt): self
146: {
147: if (\is_array($mailRcpt)) $mailRcpt = \implode(', ', $mailRcpt);
148: $this->mailRcpt = $mailRcpt;
149: return $this;
150: }
151:
152: /**
153: * Set mailBcc
154: * @param string|array $mailBcc
155: * @return Maillog
156: */
157: public function setMailBcc($mailBcc): self
158: {
159: if (\is_array($mailBcc)) $mailBcc = \implode(', ', $mailBcc);
160: $this->mailBcc = $mailBcc;
161: return $this;
162: }
163:
164:
165: // --------------------------------------------------------------------- Auto-generated
166:
167: /**
168: * Get id
169: *
170: * @return integer
171: */
172: public function getId()
173: {
174: return $this->id;
175: }
176:
177: /**
178: * Set template
179: *
180: * @param string $template
181: *
182: * @return Maillog
183: */
184: public function setTemplate($template)
185: {
186: $this->template = $template;
187:
188: return $this;
189: }
190:
191: /**
192: * Get template
193: *
194: * @return string
195: */
196: public function getTemplate()
197: {
198: return $this->template;
199: }
200:
201: /**
202: * Set locale
203: *
204: * @param string $locale
205: *
206: * @return Maillog
207: */
208: public function setLocale($locale)
209: {
210: $this->locale = $locale;
211:
212: return $this;
213: }
214:
215: /**
216: * Get locale
217: *
218: * @return string
219: */
220: public function getLocale()
221: {
222: return $this->locale;
223: }
224:
225: /**
226: * Set returnPath
227: *
228: * @param string $returnPath
229: *
230: * @return Maillog
231: */
232: public function setReturnPath($returnPath)
233: {
234: $this->returnPath = $returnPath;
235:
236: return $this;
237: }
238:
239: /**
240: * Get returnPath
241: *
242: * @return string
243: */
244: public function getReturnPath()
245: {
246: return $this->returnPath;
247: }
248:
249: /**
250: * Get mailFrom
251: *
252: * @return string
253: */
254: public function getMailFrom()
255: {
256: return $this->mailFrom;
257: }
258:
259: /**
260: * Get mailRcpt
261: *
262: * @return string
263: */
264: public function getMailRcpt()
265: {
266: return $this->mailRcpt;
267: }
268:
269: /**
270: * Get mailBcc
271: *
272: * @return string
273: */
274: public function getMailBcc()
275: {
276: return $this->mailBcc;
277: }
278:
279: /**
280: * Set subject
281: *
282: * @param string $subject
283: *
284: * @return Maillog
285: */
286: public function setSubject($subject)
287: {
288: $this->subject = $subject;
289:
290: return $this;
291: }
292:
293: /**
294: * Get subject
295: *
296: * @return string
297: */
298: public function getSubject()
299: {
300: return $this->subject;
301: }
302:
303: /**
304: * Set body
305: *
306: * @param string $body
307: *
308: * @return Maillog
309: */
310: public function setBody($body)
311: {
312: $this->body = $body;
313:
314: return $this;
315: }
316:
317: /**
318: * Get body
319: *
320: * @return string
321: */
322: public function getBody()
323: {
324: return $this->body;
325: }
326:
327: /**
328: * Set contentType
329: *
330: * @param string $contentType
331: *
332: * @return Maillog
333: */
334: public function setContentType($contentType)
335: {
336: $this->contentType = $contentType;
337:
338: return $this;
339: }
340:
341: /**
342: * Get contentType
343: *
344: * @return string
345: */
346: public function getContentType()
347: {
348: return $this->contentType;
349: }
350:
351: /**
352: * Set messageId
353: *
354: * @param string $messageId
355: *
356: * @return Maillog
357: */
358: public function setMessageId($messageId)
359: {
360: $this->messageId = $messageId;
361:
362: return $this;
363: }
364:
365: /**
366: * Get messageId
367: *
368: * @return string
369: */
370: public function getMessageId()
371: {
372: return $this->messageId;
373: }
374:
375: /**
376: * Set sendCode
377: *
378: * @param integer $sendCode
379: *
380: * @return Maillog
381: */
382: public function setSendCode($sendCode)
383: {
384: $this->sendCode = $sendCode;
385:
386: return $this;
387: }
388:
389: /**
390: * Get sendCode
391: *
392: * @return integer
393: */
394: public function getSendCode()
395: {
396: return $this->sendCode;
397: }
398:
399: /**
400: * Set errorMsg
401: *
402: * @param string $errorMsg
403: *
404: * @return Maillog
405: */
406: public function setErrorMsg($errorMsg)
407: {
408: $this->errorMsg = $errorMsg;
409:
410: return $this;
411: }
412:
413: /**
414: * Get errorMsg
415: *
416: * @return string
417: */
418: public function getErrorMsg()
419: {
420: return $this->errorMsg;
421: }
422:
423: /**
424: * Set origin
425: *
426: * @param string $origin
427: *
428: * @return Maillog
429: */
430: public function setOrigin($origin)
431: {
432: $this->origin = $origin;
433:
434: return $this;
435: }
436:
437: /**
438: * Get origin
439: *
440: * @return string
441: */
442: public function getOrigin()
443: {
444: return $this->origin;
445: }
446:
447: /**
448: * Set createdAt
449: *
450: * @param \DateTime $createdAt
451: *
452: * @return Maillog
453: */
454: public function setCreatedAt($createdAt)
455: {
456: $this->createdAt = $createdAt;
457:
458: return $this;
459: }
460:
461: /**
462: * Get createdAt
463: *
464: * @return \DateTime
465: */
466: public function getCreatedAt()
467: {
468: return $this->createdAt;
469: }
470: }
471: