aboutsummaryrefslogtreecommitdiff
path: root/src/View/FormBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/View/FormBuilder.php')
-rw-r--r--src/View/FormBuilder.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/View/FormBuilder.php b/src/View/FormBuilder.php
new file mode 100644
index 0000000..df5687d
--- /dev/null
+++ b/src/View/FormBuilder.php
@@ -0,0 +1,55 @@
1<?php
2// src/View/FormBuilder.php
3
4declare(strict_types=1);
5
6namespace App\View;
7
8use App\Entity\Node;
9use App\Entity\Email;
10use App\Service\Captcha;
11use App\Service\Config;
12
13class FormBuilder extends AbstractBuilder
14{
15 static private ?Captcha $captcha = null;
16
17 public function __construct(Node $node){
18 parent::__construct($node);
19
20 if(!empty($node->getNodeData()->getData())){
21 extract($node->getNodeData()->getData());
22 }
23
24 // un seul captcha à la fois!
25 if(!self::$captcha){
26 self::$captcha = new Captcha;
27 $_SESSION['captcha'] = self::$captcha->getSolution();
28 }
29
30 // données stockées en vrac dans du JSON et récupérées avec extract => changer ça un jour
31 $smtp_host = $smtp_host ?? Config::$smtp_host;
32 $smtp_secure = $smtp_secure ?? Config::$smtp_secure;
33 $smtp_username = $smtp_username ?? Config::$smtp_username;
34 $email_dest = $email_dest ?? Config::$email_dest;
35 $keep_emails = (bool)($keep_emails ?? false); // (bool) est inutile mais plus clair
36 $retention_period = $this->getRetentionPeriod($retention_period ?? null, Email::DEFAULT_RETENTION_PERIOD);
37 $retention_period_sensible = $this->getRetentionPeriod($retention_period_sensible ?? null, Email::DEFAULT_RETENTION_PERIOD_SENSITIVE);
38
39 $admin_content = '';
40 if(IS_ADMIN){
41 ob_start();
42 require self::VIEWS_PATH . 'form_admin.php';
43 $admin_content = ob_get_clean();
44 }
45
46 ob_start();
47 require self::VIEWS_PATH . $node->getName() . '.php';
48 $this->html = ob_get_clean(); // pas de concaténation ici, on écrase
49 }
50
51 private function getRetentionPeriod(mixed $period, int $default_period): int
52 {
53 return ($period === null || (int)$period <= 0) ? $default_period : (int)$period; // (int) est nécessaire à cause du stockage JSON
54 }
55} \ No newline at end of file