aboutsummaryrefslogtreecommitdiff
path: root/src/model/entities
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-12-23 15:20:48 +0100
committerpolo <ordipolo@gmx.fr>2025-12-23 15:20:48 +0100
commit774437d3196878388e294a3833a73e900000b5e4 (patch)
tree5d8449beee8b492fe553460f3c4f1027e8cd123a /src/model/entities
parent8393acd0366ee3408db103ba29e8686bab127f42 (diff)
downloadcms-774437d3196878388e294a3833a73e900000b5e4.tar.gz
cms-774437d3196878388e294a3833a73e900000b5e4.tar.bz2
cms-774437d3196878388e294a3833a73e900000b5e4.zip
choix durée stockage e-mails, relation entités Email <=> NodeData
Diffstat (limited to 'src/model/entities')
-rw-r--r--src/model/entities/Email.php30
-rw-r--r--src/model/entities/NodeData.php38
2 files changed, 31 insertions, 37 deletions
diff --git a/src/model/entities/Email.php b/src/model/entities/Email.php
index c66625f..d54b3cc 100644
--- a/src/model/entities/Email.php
+++ b/src/model/entities/Email.php
@@ -12,8 +12,8 @@ use Doctrine\ORM\Mapping as ORM;
12class Email 12class Email
13{ 13{
14 // en mois 14 // en mois
15 const LEGAL_RETENTION_PERIOD = 36; // 3 ans, justification = prospection, durée "glissante", date de suppression remise à jour à chaque nouvel e-mail 15 const DEFAULT_RETENTION_PERIOD = 36; // 3 ans, justification = prospection, durée "glissante", date de suppression remise à jour à chaque nouvel e-mail
16 const LEGAL_RETENTION_PERIOD_SENSITIVE = 60; // 5 ans pour données sensibles ou litige, durée de preuve légale, durée non glissante 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 17
18 #[ORM\Id] 18 #[ORM\Id]
19 #[ORM\GeneratedValue] 19 #[ORM\GeneratedValue]
@@ -48,13 +48,18 @@ class Email
48 #[ORM\Column(type: 'datetime', nullable: true)] 48 #[ORM\Column(type: 'datetime', nullable: true)]
49 private ?\DateTime $is_sensitive_since; 49 private ?\DateTime $is_sensitive_since;
50 50
51 public function __construct(string $sender_name, string $sender_address, string $recipient, string $content, bool $sensitive = false){ 51 #[ORM\ManyToOne(targetEntity: NodeData::class)]
52 #[ORM\JoinColumn(name: "node_data_id", referencedColumnName: "id_node_data", nullable: true)]
53 private ?NodeData $node_data;
54
55 public function __construct(string $sender_name, string $sender_address, string $recipient, string $content, NodeData $node_data, bool $sensitive = false){
52 $this->sender_name = strtolower($sender_name); 56 $this->sender_name = strtolower($sender_name);
53 $this->sender_address = strtolower($sender_address); 57 $this->sender_address = strtolower($sender_address);
54 $this->recipient = strtolower($recipient); 58 $this->recipient = strtolower($recipient);
55 $this->content = $content; 59 $this->content = $content;
56 $this->date_time = new \DateTime; 60 $this->date_time = new \DateTime;
57 $this->last_contact_date = new \DateTime; 61 $this->last_contact_date = new \DateTime;
62 $this->node_data = $node_data;
58 $this->makeSensitive($sensitive); 63 $this->makeSensitive($sensitive);
59 } 64 }
60 65
@@ -108,10 +113,23 @@ class Email
108 $this->last_contact_date = new \DateTime; 113 $this->last_contact_date = new \DateTime;
109 } 114 }
110 115
116 // la durée de conservation $period est propre au bloc formulaire (NodeData)
117 // la date de dernier contact
111 public function getDeletionDate(): \DateTime 118 public function getDeletionDate(): \DateTime
112 { 119 {
113 return $this->is_sensitive // oui durée 5 ans, non durée 3 ans "glissante" 120 // deux tests:
114 ? (clone $this->is_sensitive_since)->modify('+ ' . (string)self::LEGAL_RETENTION_PERIOD_SENSITIVE . ' month') // erreur si vrai mais sans date (pas censé arriver) 121 // => e-mail associé à un formulaire?
115 : (clone $this->last_contact_date)->modify('+ ' . (string)self::LEGAL_RETENTION_PERIOD . ' month'); 122 // => ce formulaire dispose d'une durée de stockage spécifique?
123 $period = $this->node_data === null ? null : ($this->node_data->getData()['retention_period'] ?? null);
124
125 $period = (int)$period;
126 if($period === null || $period <= 0){
127 $period = $this->is_sensitive ? self::DEFAULT_RETENTION_PERIOD_SENSITIVE : self::DEFAULT_RETENTION_PERIOD;
128 }
129
130 $date = $this->is_sensitive ? (clone $this->is_sensitive_since) : (clone $this->last_contact_date); // oui durée 5 ans, non durée 3 ans "glissante"
131 // erreur si "sensible" mais sans date disponible (pas censé arriver)
132
133 return $date->modify('+ ' . (string)$period . ' month');
116 } 134 }
117} \ No newline at end of file 135} \ No newline at end of file
diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php
index 4c07a69..d2f10ba 100644
--- a/src/model/entities/NodeData.php
+++ b/src/model/entities/NodeData.php
@@ -44,8 +44,11 @@ class NodeData
44 #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: NodeDataAsset::class, cascade: ['persist', 'remove'])] 44 #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: NodeDataAsset::class, cascade: ['persist', 'remove'])]
45 private Collection $nda_collection; 45 private Collection $nda_collection;
46 46
47 /*#[ORM\OneToMany(mappedBy: 'node_data', targetEntity: Email::class, cascade: ['persist', 'remove'])] // => noeud "form", inutilisé et conflit avec le tableau $emails
48 private Collection $emails;*/
49
47 private int $nb_pages = 1; 50 private int $nb_pages = 1;
48 private array $emails = []; // noeud show_emails uniquement 51 private array $emails = []; // => noeud "show_emails"
49 52
50 public function __construct(array $data, Node $node, Collection $nda_collection = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) 53 public function __construct(array $data, Node $node, Collection $nda_collection = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null)
51 { 54 {
@@ -70,7 +73,7 @@ class NodeData
70 { 73 {
71 $this->data = $data; 74 $this->data = $data;
72 }*/ 75 }*/
73 public function updateData(string $key, string|bool|array $value = ''): void 76 public function updateData(string $key, string|int|bool|array $value = ''): void
74 { 77 {
75 if($value !== ''){ 78 if($value !== ''){
76 $this->data[$key] = $value; 79 $this->data[$key] = $value;
@@ -153,39 +156,12 @@ class NodeData
153 } 156 }
154 return $nda->getAsset() ?? null; 157 return $nda->getAsset() ?? null;
155 } 158 }
156 /*public function addNodeDataAsset(NodeDataAsset $nda): self
157 {
158 if(!$this->nda_collection->contains($nda)){ // sécurité contrainte UNIQUE
159 $this->nda_collection->add($nda);
160 }
161 return $this;
162 }*/
163 /*public function removeNodeDataAsset(NodeDataAsset $nda): self // inutile on peut faire: $node_data->getNodeDataAssets()->removeElement($nda);
164 {
165 $this->nda_collection->removeElement($nda);
166 // pas de synchro dans NodeDataAsset, les champs de cette table ne sont pas nullables
167 return $this;
168 }*/
169
170 // LE setter, sélectionne l'asset à utiliser en remplaçant l'entrée dans NodeDataAsset en fonction du rôle
171 // à mettre théoriquement dans une classe metier dans "service"
172 /*public function replaceAssetForRole(string $role, Asset $asset): void
173 {
174 foreach($this->nda_collection as $nda){
175 if($nda->getRole() === $role){
176 $this->removeNodeDataAsset($nda);
177 break;
178 }
179 }
180 $this->new_nda = new NodeDataAsset($this, $asset, $role);
181 $this->addNodeDataAsset($this->new_nda);
182 }*/
183 159
184 public function getEmails(): array 160 public function getEmails(): array // appelée dans ShowEmailsBuilder
185 { 161 {
186 return $this->emails; 162 return $this->emails;
187 } 163 }
188 public function setEmails(array $emails): void 164 public function setEmails(array $emails): void // appelée dans Model
189 { 165 {
190 $this->emails = $emails; 166 $this->emails = $emails;
191 } 167 }