From f27cca08ff786ceff1870147f6d6bad14d71117f Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 23 Oct 2026 00:47:32 +0200 Subject: =?UTF-8?q?dossiers=20avec=20majuscule,=20namespace=20pour=20toute?= =?UTF-8?q?s=20les=20classes,=20autoload=20psr-4,=20UserDataService::creat?= =?UTF-8?q?eZip=20d=C3=A9plac=C3=A9=20dans=20Backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model/Entity/Email.php | 131 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/Model/Entity/Email.php (limited to 'src/Model/Entity/Email.php') 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 @@ + 'CURRENT_TIMESTAMP'])] + private \DateTime $date_time; + + #[ORM\Column(type: 'boolean')] + private bool $is_sensitive; // "sensitive" tout court est un mot réservé + + #[ORM\Column(type: 'datetime', options: ['default' => 'CURRENT_TIMESTAMP'])] + private \DateTime $last_contact_date; + + #[ORM\Column(type: 'datetime', nullable: true)] + private ?\DateTime $is_sensitive_since; + + #[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, 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->email_form = $email_form; + $this->makeSensitive($sensitive); + } + + public function getId(): int + { + return $this->id_email; + } + public function getSenderName(): string + { + return $this->sender_name; + } + public function getSenderAddress(): string + { + return $this->sender_address; + } + public function getRecipient(): string + { + return $this->recipient; + } + public function getContent(): string + { + return $this->content; + } + public function getDateTime(): \DateTime + { + return $this->date_time; + } + /*public function getLastContactDate(): \DateTime + { + return $this->last_contact_date; + }*/ + public function isSensitive(): bool + { + return $this->is_sensitive; + } + public function isSensitiveSince(): ?\DateTime + { + return $this->is_sensitive_since; + } + + public function makeSensitive(bool $sensitive = true): void + { + $this->is_sensitive = $sensitive; + if($sensitive && $this->is_sensitive_since === null){ + $this->is_sensitive_since = new \DateTime(); + } + } + + public function updateLastContactDate(): void + { + $this->last_contact_date = new \DateTime; + } + + 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->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; + + $date = clone ($this->is_sensitive ? $this->is_sensitive_since : $this->last_contact_date); // erreur si "sensible" mais sans date disponible (pas censé arriver) + return $date->modify('+ ' . (string)$period . ' month'); + } +} \ No newline at end of file -- cgit v1.2.3