aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Entity/Email.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Entity/Email.php')
-rw-r--r--src/Model/Entity/Email.php131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/Model/Entity/Email.php b/src/Model/Entity/Email.php
new file mode 100644
index 0000000..8ad66fd
--- /dev/null
+++ b/src/Model/Entity/Email.php
@@ -0,0 +1,131 @@
1<?php
2// src/Model/Entity/Email.php
3
4declare(strict_types=1);
5
6namespace App\Entity;
7
8use Doctrine\ORM\Mapping as ORM;
9
10#[ORM\Entity]
11#[ORM\Table(name: TABLE_PREFIX . "email")]
12class Email
13{
14 // en mois
15 const DEFAULT_RETENTION_PERIOD = 36; // 3 ans, justification = prospection, durée "glissante", date de suppression remise à jour à chaque nouvel e-mail
16 const DEFAULT_RETENTION_PERIOD_SENSITIVE = 60; // 5 ans pour données sensibles ou litige, durée de preuve légale, durée non glissante
17
18 #[ORM\Id]
19 #[ORM\GeneratedValue]
20 #[ORM\Column(type: "integer")]
21 private int $id_email;
22
23 #[ORM\Column(type: "string", length: 255)]
24 private string $sender_name;
25
26 #[ORM\Column(type: "string", length: 320)]
27 private string $sender_address;
28
29 #[ORM\Column(type: "string", length: 320)]
30 private string $recipient;
31
32 // inutile, objet = 'Message envoyé par ' . $name . ' (' . $email . ') depuis le site web'
33 /*#[ORM\Column(type: "text")]
34 private string $subject;*/
35
36 #[ORM\Column(type: "text")]
37 private string $content;
38
39 #[ORM\Column(type: 'datetime', options: ['default' => 'CURRENT_TIMESTAMP'])]
40 private \DateTime $date_time;
41
42 #[ORM\Column(type: 'boolean')]
43 private bool $is_sensitive; // "sensitive" tout court est un mot réservé
44
45 #[ORM\Column(type: 'datetime', options: ['default' => 'CURRENT_TIMESTAMP'])]
46 private \DateTime $last_contact_date;
47
48 #[ORM\Column(type: 'datetime', nullable: true)]
49 private ?\DateTime $is_sensitive_since;
50
51 #[ORM\ManyToOne(targetEntity: EmailForm::class)]
52 #[ORM\JoinColumn(name: "email_form_id", referencedColumnName: "id_email_form", nullable: true)]
53 private ?EmailForm $email_form;
54
55 public function __construct(string $sender_name, string $sender_address, string $recipient, string $content, EmailForm $email_form, bool $sensitive = false){
56 $this->sender_name = strtolower($sender_name);
57 $this->sender_address = strtolower($sender_address);
58 $this->recipient = strtolower($recipient);
59 $this->content = $content;
60 $this->date_time = new \DateTime;
61 $this->last_contact_date = new \DateTime;
62 $this->email_form = $email_form;
63 $this->makeSensitive($sensitive);
64 }
65
66 public function getId(): int
67 {
68 return $this->id_email;
69 }
70 public function getSenderName(): string
71 {
72 return $this->sender_name;
73 }
74 public function getSenderAddress(): string
75 {
76 return $this->sender_address;
77 }
78 public function getRecipient(): string
79 {
80 return $this->recipient;
81 }
82 public function getContent(): string
83 {
84 return $this->content;
85 }
86 public function getDateTime(): \DateTime
87 {
88 return $this->date_time;
89 }
90 /*public function getLastContactDate(): \DateTime
91 {
92 return $this->last_contact_date;
93 }*/
94 public function isSensitive(): bool
95 {
96 return $this->is_sensitive;
97 }
98 public function isSensitiveSince(): ?\DateTime
99 {
100 return $this->is_sensitive_since;
101 }
102
103 public function makeSensitive(bool $sensitive = true): void
104 {
105 $this->is_sensitive = $sensitive;
106 if($sensitive && $this->is_sensitive_since === null){
107 $this->is_sensitive_since = new \DateTime();
108 }
109 }
110
111 public function updateLastContactDate(): void
112 {
113 $this->last_contact_date = new \DateTime;
114 }
115
116 public function getDeletionDate(): \DateTime // utilise une durée de conservation $period qui est propre au bloc formulaire (à son EmailForm)
117 {
118 // tests appliqués:
119 // => e-mail associé à un formulaire?
120 // => ce formulaire dispose d'une durée de stockage spécifique?
121 // => cette donnée est un entier > 0
122 $key = $this->is_sensitive ? 'retention_period_sensible' : 'retention_period';
123 $period = $this->email_form ? (int)($this->email_form->getData()[$key] ?? null) : null;
124
125 $default = $this->is_sensitive ? self::DEFAULT_RETENTION_PERIOD_SENSITIVE : self::DEFAULT_RETENTION_PERIOD;
126 $period = ($period === null || $period <= 0) ? $default : $period;
127
128 $date = clone ($this->is_sensitive ? $this->is_sensitive_since : $this->last_contact_date); // erreur si "sensible" mais sans date disponible (pas censé arriver)
129 return $date->modify('+ ' . (string)$period . ' month');
130 }
131} \ No newline at end of file