From b76547767ae897b6de752c56e2cef6079ca4abcb Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 11 Jun 2026 01:35:57 +0200 Subject: =?UTF-8?q?classe=20EmailForm=20=C3=A0=20Email=20et=20d=C3=A9tacha?= =?UTF-8?q?ble=20de=20Node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/Email.php | 14 +++++----- src/model/entities/EmailForm.php | 58 ++++++++++++++++++++++++++++++++++++++++ src/model/entities/Node.php | 10 ++++--- src/model/entities/NodeData.php | 4 +-- 4 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 src/model/entities/EmailForm.php (limited to 'src/model') 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 #[ORM\Column(type: 'datetime', nullable: true)] private ?\DateTime $is_sensitive_since; - #[ORM\ManyToOne(targetEntity: NodeData::class)] - #[ORM\JoinColumn(name: "node_data_id", referencedColumnName: "id_node_data", nullable: true)] - private ?NodeData $node_data; + #[ORM\ManyToOne(targetEntity: EmailForm::class)] + #[ORM\JoinColumn(name: "email_form_id", referencedColumnName: "id_email_form", nullable: true)] + private ?EmailForm $email_form; - public function __construct(string $sender_name, string $sender_address, string $recipient, string $content, NodeData $node_data, bool $sensitive = false){ + public function __construct(string $sender_name, string $sender_address, string $recipient, string $content, EmailForm $email_form, bool $sensitive = false){ $this->sender_name = strtolower($sender_name); $this->sender_address = strtolower($sender_address); $this->recipient = strtolower($recipient); $this->content = $content; $this->date_time = new \DateTime; $this->last_contact_date = new \DateTime; - $this->node_data = $node_data; + $this->email_form = $email_form; $this->makeSensitive($sensitive); } @@ -113,14 +113,14 @@ class Email $this->last_contact_date = new \DateTime; } - public function getDeletionDate(): \DateTime // utilise une durée de conservation $period qui est propre au bloc formulaire (à son NodeData) + public function getDeletionDate(): \DateTime // utilise une durée de conservation $period qui est propre au bloc formulaire (à son EmailForm) { // tests appliqués: // => e-mail associé à un formulaire? // => ce formulaire dispose d'une durée de stockage spécifique? // => cette donnée est un entier > 0 $key = $this->is_sensitive ? 'retention_period_sensible' : 'retention_period'; - $period = $this->node_data ? (int)($this->node_data->getData()[$key] ?? null) : null; + $period = $this->email_form ? (int)($this->email_form->getData()[$key] ?? null) : null; $default = $this->is_sensitive ? self::DEFAULT_RETENTION_PERIOD_SENSITIVE : self::DEFAULT_RETENTION_PERIOD; $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 @@ +data = $data; + $this->node = $node; + } + + public function getId(): int + { + return $this->id_email_form; + } + + // getData et updateData sont indentiques au code dans NodeData + // plutôt qu'une interface, pourquoi pas une classe abstraite? ou peut-être un trait? + public function getData(): array + { + return $this->data; + } + public function updateData(string $key, string|int|bool|array $value = ''): void + { + if($value !== ''){ + $this->data[$key] = $value; + } + // si $value est vide, supprime la clé + elseif(isset($this->data[$key])){ + unset($this->data[$key]); + } + } + + public function setNode(?Node $node): void + { + $this->node = $node; + } +} \ 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 #[ORM\OneToOne(targetEntity: NodeData::class, mappedBy: "node", cascade: ['persist', 'remove'])] private ?NodeData $node_data = null; + #[ORM\OneToOne(targetEntity: EmailForm::class, mappedBy: "node", cascade: ['persist'])] // pas de remove, les e-mails sont associés au EmailForm + private ?EmailForm $email_form = null; // attributs non destinés à doctrine private array $children = []; // tableau de Node private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" - public function __construct(string $name = '', int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) - { + public function __construct(string $name = '', int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null){ $this->name_node = $name; $this->position = $position; $this->parent = $parent; @@ -105,9 +106,10 @@ class Node { $this->article = $article; }*/ - public function getNodeData(): ?NodeData + // une interface serait cool! + public function getNodeData(): NodeData|EmailForm|null { - return $this->node_data; + return $this->name_node === 'form' ? $this->email_form : $this->node_data; } public function getChildren(): array { 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 #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: AssetEmployment::class, cascade: ['persist', 'remove'])] private Collection $asset_employment; - /*#[ORM\OneToMany(mappedBy: 'node_data', targetEntity: Email::class, cascade: ['persist', 'remove'])] // => noeud "form", inutilisé et conflit avec le tableau $emails - private Collection $emails;*/ - private int $nb_pages = 1; private array $emails = []; // => noeud "show_emails" @@ -157,6 +154,7 @@ class NodeData return $nda->getAsset() ?? null; } + // pour affichage page Courriels public function getEmails(): array // appelée dans ShowEmailsBuilder { return $this->emails; -- cgit v1.2.3