aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controller/ContactFormController.php2
-rw-r--r--src/model/entities/Email.php20
-rw-r--r--src/view/FormBuilder.php8
-rw-r--r--src/view/templates/form_admin.php9
4 files changed, 23 insertions, 16 deletions
diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php
index 0724401..468b732 100644
--- a/src/controller/ContactFormController.php
+++ b/src/controller/ContactFormController.php
@@ -19,7 +19,7 @@ class ContactFormController
19 static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): void 19 static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): void
20 { 20 {
21 $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); 21 $form_data = $entityManager->find('App\Entity\NodeData', $json['id']);
22 $form_data->updateData('retention_period', (int)$json['months']); 22 $form_data->updateData($json['field'], (int)$json['months']);
23 $entityManager->persist($form_data); 23 $entityManager->persist($form_data);
24 $entityManager->flush(); 24 $entityManager->flush();
25 echo json_encode(['success' => true, 'months' => $json['months']]); 25 echo json_encode(['success' => true, 'months' => $json['months']]);
diff --git a/src/model/entities/Email.php b/src/model/entities/Email.php
index d54b3cc..ff76653 100644
--- a/src/model/entities/Email.php
+++ b/src/model/entities/Email.php
@@ -113,23 +113,19 @@ class Email
113 $this->last_contact_date = new \DateTime; 113 $this->last_contact_date = new \DateTime;
114 } 114 }
115 115
116 // la durée de conservation $period est propre au bloc formulaire (NodeData) 116 public function getDeletionDate(): \DateTime // utilise une durée de conservation $period qui est propre au bloc formulaire (à son NodeData)
117 // la date de dernier contact
118 public function getDeletionDate(): \DateTime
119 { 117 {
120 // deux tests: 118 // tests appliqués:
121 // => e-mail associé à un formulaire? 119 // => e-mail associé à un formulaire?
122 // => ce formulaire dispose d'une durée de stockage spécifique? 120 // => 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); 121 // => cette donnée est un entier > 0
122 $key = $this->is_sensitive ? 'retention_period_sensible' : 'retention_period';
123 $period = $this->node_data ? (int)($this->node_data->getData()[$key] ?? null) : null;
124 124
125 $period = (int)$period; 125 $default = $this->is_sensitive ? self::DEFAULT_RETENTION_PERIOD_SENSITIVE : self::DEFAULT_RETENTION_PERIOD;
126 if($period === null || $period <= 0){ 126 $period = ($period === null || $period <= 0) ? $default : $period;
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 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)
133 return $date->modify('+ ' . (string)$period . ' month'); 129 return $date->modify('+ ' . (string)$period . ' month');
134 } 130 }
135} \ No newline at end of file 131} \ No newline at end of file
diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php
index e2389b0..7505510 100644
--- a/src/view/FormBuilder.php
+++ b/src/view/FormBuilder.php
@@ -30,7 +30,8 @@ class FormBuilder extends AbstractBuilder
30 $smtp_username = $smtp_username ?? Config::$smtp_username; 30 $smtp_username = $smtp_username ?? Config::$smtp_username;
31 $email_dest = $email_dest ?? Config::$email_dest; 31 $email_dest = $email_dest ?? Config::$email_dest;
32 $keep_emails = (bool)$keep_emails ?? false; // (bool) est inutile mais plus clair 32 $keep_emails = (bool)$keep_emails ?? false; // (bool) est inutile mais plus clair
33 $retention_period = (int)($retention_period ?? App\Entity\Email::DEFAULT_RETENTION_PERIOD); // (int) est nécessaire à cause du stockage JSON 33 $retention_period = $this->getRetentionPeriod($retention_period ?? null, App\Entity\Email::DEFAULT_RETENTION_PERIOD);
34 $retention_period_sensible = $this->getRetentionPeriod($retention_period_sensible ?? null, App\Entity\Email::DEFAULT_RETENTION_PERIOD_SENSITIVE);
34 35
35 $admin_content = ''; 36 $admin_content = '';
36 if($_SESSION['admin']) 37 if($_SESSION['admin'])
@@ -44,4 +45,9 @@ class FormBuilder extends AbstractBuilder
44 require self::VIEWS_PATH . $node->getName() . '.php'; 45 require self::VIEWS_PATH . $node->getName() . '.php';
45 $this->html = ob_get_clean(); // pas de concaténation ici, on écrase 46 $this->html = ob_get_clean(); // pas de concaténation ici, on écrase
46 } 47 }
48
49 private function getRetentionPeriod(mixed $period, int $default_period): int
50 {
51 return ($period === null || (int)$period <= 0) ? $default_period : (int)$period; // (int) est nécessaire à cause du stockage JSON
52 }
47} \ No newline at end of file 53} \ No newline at end of file
diff --git a/src/view/templates/form_admin.php b/src/view/templates/form_admin.php
index 457f770..7156374 100644
--- a/src/view/templates/form_admin.php
+++ b/src/view/templates/form_admin.php
@@ -9,11 +9,16 @@ declare(strict_types=1);
9 <input type="checkbox" id="keep_emails_<?= $node->getNodeData()->getId() ?>" <?= $keep_emails ? 'checked' : '' ?> onclick="keepEmails(<?= $node->getNodeData()->getId() ?>)"> 9 <input type="checkbox" id="keep_emails_<?= $node->getNodeData()->getId() ?>" <?= $keep_emails ? 'checked' : '' ?> onclick="keepEmails(<?= $node->getNodeData()->getId() ?>)">
10 </p> 10 </p>
11 <p><i>Notez que ces enregistrements sont des données personnelles et sont concernés par le RGPD.</i></p> 11 <p><i>Notez que ces enregistrements sont des données personnelles et sont concernés par le RGPD.</i></p>
12 <p><a href="<?= new URL(['page' => 'emails']) ?>"><button>Consulter les e-mails enregistrés</button></a></p>
12 <p> 13 <p>
13 <label for="retention_period_<?= $node->getNodeData()->getId() ?>">Durée de conservation (en mois)</label> 14 <label for="retention_period_<?= $node->getNodeData()->getId() ?>">Durée de conservation (en mois)</label>
14 <input type="number" id="retention_period_<?= $node->getNodeData()->getId() ?>" min="0" value="<?= $retention_period ?>" size="2" onchange="setEmailsRetentionPeriod(<?= $node->getNodeData()->getId() ?>)"> 15 <input type="number" id="retention_period_<?= $node->getNodeData()->getId() ?>" min="0" value="<?= $retention_period ?>" size="2" onchange="setEmailsRetentionPeriod(<?= $node->getNodeData()->getId() ?>, 'retention_period')">
15 </p> 16 </p>
16 <p><a href="<?= new URL(['page' => 'emails']) ?>"><button>Consulter les e-mails enregistrés</button></a></p> 17 <p>
18 <label for="retention_period_sensible_<?= $node->getNodeData()->getId() ?>">Durée de conservation des emails sensibles(en mois)</label>
19 <input type="number" id="retention_period_sensible_<?= $node->getNodeData()->getId() ?>" min="0" value="<?= $retention_period_sensible ?>" size="2" onchange="setEmailsRetentionPeriod(<?= $node->getNodeData()->getId() ?>, 'retention_period_sensible')">
20 </p>
21
17</div> 22</div>
18<div class="admin_form"> 23<div class="admin_form">
19 <h3>Paramètres d'envoi</h3> 24 <h3>Paramètres d'envoi</h3>