aboutsummaryrefslogtreecommitdiff
path: root/src/model/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/entities')
-rw-r--r--src/model/entities/Email.php14
-rw-r--r--src/model/entities/EmailForm.php58
-rw-r--r--src/model/entities/Node.php10
-rw-r--r--src/model/entities/NodeData.php4
4 files changed, 72 insertions, 14 deletions
diff --git a/src/model/entities/Email.php b/src/model/entities/Email.php
index ff76653..60fcc1f 100644
--- a/src/model/entities/Email.php
+++ b/src/model/entities/Email.php
@@ -48,18 +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 #[ORM\ManyToOne(targetEntity: NodeData::class)] 51 #[ORM\ManyToOne(targetEntity: EmailForm::class)]
52 #[ORM\JoinColumn(name: "node_data_id", referencedColumnName: "id_node_data", nullable: true)] 52 #[ORM\JoinColumn(name: "email_form_id", referencedColumnName: "id_email_form", nullable: true)]
53 private ?NodeData $node_data; 53 private ?EmailForm $email_form;
54 54
55 public function __construct(string $sender_name, string $sender_address, string $recipient, string $content, NodeData $node_data, bool $sensitive = false){ 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); 56 $this->sender_name = strtolower($sender_name);
57 $this->sender_address = strtolower($sender_address); 57 $this->sender_address = strtolower($sender_address);
58 $this->recipient = strtolower($recipient); 58 $this->recipient = strtolower($recipient);
59 $this->content = $content; 59 $this->content = $content;
60 $this->date_time = new \DateTime; 60 $this->date_time = new \DateTime;
61 $this->last_contact_date = new \DateTime; 61 $this->last_contact_date = new \DateTime;
62 $this->node_data = $node_data; 62 $this->email_form = $email_form;
63 $this->makeSensitive($sensitive); 63 $this->makeSensitive($sensitive);
64 } 64 }
65 65
@@ -113,14 +113,14 @@ class Email
113 $this->last_contact_date = new \DateTime; 113 $this->last_contact_date = new \DateTime;
114 } 114 }
115 115
116 public function getDeletionDate(): \DateTime // utilise une durée de conservation $period qui est propre au bloc formulaire (à son NodeData) 116 public function getDeletionDate(): \DateTime // utilise une durée de conservation $period qui est propre au bloc formulaire (à son EmailForm)
117 { 117 {
118 // tests appliqués: 118 // tests appliqués:
119 // => e-mail associé à un formulaire? 119 // => e-mail associé à un formulaire?
120 // => ce formulaire dispose d'une durée de stockage spécifique? 120 // => ce formulaire dispose d'une durée de stockage spécifique?
121 // => cette donnée est un entier > 0 121 // => cette donnée est un entier > 0
122 $key = $this->is_sensitive ? 'retention_period_sensible' : 'retention_period'; 122 $key = $this->is_sensitive ? 'retention_period_sensible' : 'retention_period';
123 $period = $this->node_data ? (int)($this->node_data->getData()[$key] ?? null) : null; 123 $period = $this->email_form ? (int)($this->email_form->getData()[$key] ?? null) : null;
124 124
125 $default = $this->is_sensitive ? self::DEFAULT_RETENTION_PERIOD_SENSITIVE : self::DEFAULT_RETENTION_PERIOD; 125 $default = $this->is_sensitive ? self::DEFAULT_RETENTION_PERIOD_SENSITIVE : self::DEFAULT_RETENTION_PERIOD;
126 $period = ($period === null || $period <= 0) ? $default : $period; 126 $period = ($period === null || $period <= 0) ? $default : $period;
diff --git a/src/model/entities/EmailForm.php b/src/model/entities/EmailForm.php
new file mode 100644
index 0000000..466a389
--- /dev/null
+++ b/src/model/entities/EmailForm.php
@@ -0,0 +1,58 @@
1<?php
2// src/model/entities/EmailForm.php
3
4declare(strict_types=1);
5
6namespace App\Entity;
7
8use Doctrine\ORM\Mapping as ORM;
9//use Doctrine\Common\Collections\ArrayCollection;
10
11#[ORM\Entity]
12#[ORM\Table(name: TABLE_PREFIX . "email_form")]
13class EmailForm{
14 #[ORM\Id]
15 #[ORM\GeneratedValue]
16 #[ORM\Column(type: "integer")]
17 private int $id_email_form;
18
19 // inverseBy fait le lien avec $email_form dans Node (qui a "mappedBy")
20 #[ORM\OneToOne(targetEntity: Node::class, inversedBy: "email_form")]
21 #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node")]
22 private ?Node $node;
23
24 #[ORM\Column(type: "json")]
25 private array $data;
26
27 public function __construct(array $data, Node $node){
28 $this->data = $data;
29 $this->node = $node;
30 }
31
32 public function getId(): int
33 {
34 return $this->id_email_form;
35 }
36
37 // getData et updateData sont indentiques au code dans NodeData
38 // plutôt qu'une interface, pourquoi pas une classe abstraite? ou peut-être un trait?
39 public function getData(): array
40 {
41 return $this->data;
42 }
43 public function updateData(string $key, string|int|bool|array $value = ''): void
44 {
45 if($value !== ''){
46 $this->data[$key] = $value;
47 }
48 // si $value est vide, supprime la clé
49 elseif(isset($this->data[$key])){
50 unset($this->data[$key]);
51 }
52 }
53
54 public function setNode(?Node $node): void
55 {
56 $this->node = $node;
57 }
58} \ No newline at end of file
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php
index 71c159d..c3e4ec3 100644
--- a/src/model/entities/Node.php
+++ b/src/model/entities/Node.php
@@ -45,13 +45,14 @@ class Node
45 #[ORM\OneToOne(targetEntity: NodeData::class, mappedBy: "node", cascade: ['persist', 'remove'])] 45 #[ORM\OneToOne(targetEntity: NodeData::class, mappedBy: "node", cascade: ['persist', 'remove'])]
46 private ?NodeData $node_data = null; 46 private ?NodeData $node_data = null;
47 47
48 #[ORM\OneToOne(targetEntity: EmailForm::class, mappedBy: "node", cascade: ['persist'])] // pas de remove, les e-mails sont associés au EmailForm
49 private ?EmailForm $email_form = null;
48 50
49 // attributs non destinés à doctrine 51 // attributs non destinés à doctrine
50 private array $children = []; // tableau de Node 52 private array $children = []; // tableau de Node
51 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" 53 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article"
52 54
53 public function __construct(string $name = '', int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) 55 public function __construct(string $name = '', int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null){
54 {
55 $this->name_node = $name; 56 $this->name_node = $name;
56 $this->position = $position; 57 $this->position = $position;
57 $this->parent = $parent; 58 $this->parent = $parent;
@@ -105,9 +106,10 @@ class Node
105 { 106 {
106 $this->article = $article; 107 $this->article = $article;
107 }*/ 108 }*/
108 public function getNodeData(): ?NodeData 109 // une interface serait cool!
110 public function getNodeData(): NodeData|EmailForm|null
109 { 111 {
110 return $this->node_data; 112 return $this->name_node === 'form' ? $this->email_form : $this->node_data;
111 } 113 }
112 public function getChildren(): array 114 public function getChildren(): array
113 { 115 {
diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php
index 49bfb3c..c55f6a1 100644
--- a/src/model/entities/NodeData.php
+++ b/src/model/entities/NodeData.php
@@ -44,9 +44,6 @@ class NodeData
44 #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: AssetEmployment::class, cascade: ['persist', 'remove'])] 44 #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: AssetEmployment::class, cascade: ['persist', 'remove'])]
45 private Collection $asset_employment; 45 private Collection $asset_employment;
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
50 private int $nb_pages = 1; 47 private int $nb_pages = 1;
51 private array $emails = []; // => noeud "show_emails" 48 private array $emails = []; // => noeud "show_emails"
52 49
@@ -157,6 +154,7 @@ class NodeData
157 return $nda->getAsset() ?? null; 154 return $nda->getAsset() ?? null;
158 } 155 }
159 156
157 // pour affichage page Courriels
160 public function getEmails(): array // appelée dans ShowEmailsBuilder 158 public function getEmails(): array // appelée dans ShowEmailsBuilder
161 { 159 {
162 return $this->emails; 160 return $this->emails;