summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/EventDTO.php49
-rw-r--r--src/model/entities/Event.php125
-rw-r--r--src/model/entities/Node.php2
3 files changed, 175 insertions, 1 deletions
diff --git a/src/model/EventDTO.php b/src/model/EventDTO.php
new file mode 100644
index 0000000..8d33733
--- /dev/null
+++ b/src/model/EventDTO.php
@@ -0,0 +1,49 @@
1<?php
2// src/model/EventDTO.php
3//
4// classe de données JSONifiable compatible avec fullcalendar
5// servira aussi pour l'import/export de fichiers .ics
6
7use App\Entity\Event;
8
9class EventDTO
10{
11 public int $id;
12 public string $title;
13 public string $start;
14 public string $end;
15 public bool $allDay;
16 public ?string $color;
17 public string $description;
18
19 public function __construct(Event $event)
20 {
21 $this->id = $event->getId();
22 $this->title = $event->getTitle();
23 $this->description = $event->getDescription() ?? ''; // renvoie $event->getDescription() si existe et ne vaut pas "null"
24 $this->allDay = $event->isAllDay();
25 $this->color = $event->getColor();
26
27 if($this->allDay){
28 $this->start = $event->getStart()->format('Y-m-d');
29 $this->end = $event->getEnd()->format('Y-m-d');
30 }
31 else{
32 $this->start = $event->getStart()->format('Y-m-d\TH:i:s\Z');
33 $this->end = $event->getEnd()->format('Y-m-d\TH:i:s\Z');
34 }
35 }
36
37 public function toArray(): array
38 {
39 return [
40 'id' => $this->id,
41 'title' => $this->title,
42 'description' => $this->description,
43 'start' => $this->start,
44 'end' => $this->end,
45 'allDay' => $this->allDay,
46 'color' => $this->color,
47 ];
48 }
49}
diff --git a/src/model/entities/Event.php b/src/model/entities/Event.php
new file mode 100644
index 0000000..c85832f
--- /dev/null
+++ b/src/model/entities/Event.php
@@ -0,0 +1,125 @@
1<?php
2// src/model/entities/Event.php
3
4declare(strict_types=1);
5
6namespace App\Entity;
7
8use Doctrine\ORM\Mapping as ORM;
9
10#[ORM\Entity]
11#[ORM\Table(name: TABLE_PREFIX . 'event')]
12class Event
13{
14 #[ORM\Id]
15 #[ORM\GeneratedValue]
16 #[ORM\Column(type: 'integer')]
17 private int $id;
18
19 #[ORM\Column(type: 'string', length: 255)] // type varchar(255)
20 private string $title;
21 // contrôle JS: if(title.length > 255)
22
23 #[ORM\Column(type: 'text')]
24 private string $description = '';
25 // chatgpt: Dans un contexte API/Front comme FullCalendar,
26 // préférer une chaîne vide à une varaible "null" peut être plus pratique,
27 // car ça évite des contrôles côté JS.
28
29 #[ORM\Column(type: 'datetime')] // chatgpt: Doctrine suppose UTC si pas de configuration spécifique
30 private \DateTimeInterface $start; // typage possible avec une interface,
31 //chatgpt: choix \DateTime par défaut, autorise \DateTimeImmutable
32
33 #[ORM\Column(type: 'datetime')]
34 private \DateTimeInterface $end;
35
36 #[ORM\Column(type: 'boolean')]
37 private bool $all_day;
38
39 #[ORM\Column(type: 'string', length: 7, nullable: true)]
40 private ?string $color = null;
41
42 public function __construct(string $title, string|\DateTimeInterface $start, string|\DateTimeInterface $end, bool $all_day, string $description = '', string $color = null){
43 $this->title = $title;
44 $this->description = $description;
45 $this->start = gettype($start) === 'string' ? new \DateTime($start) : $start;
46 $this->end = gettype($end) === 'string' ? new \DateTime($end) : $end;
47 $this->all_day = $all_day;
48 $this->color = $color;
49 }
50
51 public function updateFromJSON(array $json): void
52 {
53 $this->title = $json['title'];
54 $this->description = $json['description'];
55 $this->start = new \DateTime($json['start']);
56 $this->end = new \DateTime($json['end']);
57 $this->all_day = $json['allDay'];
58 $this->color = $json['color'];
59 }
60
61 public function getId(): int
62 {
63 return $this->id;
64 }
65
66 public function getTitle(): string
67 {
68 return $this->title;
69 }
70 /*public function setTitle(string $title): self
71 {
72 $this->title = $title;
73 return $this;
74 }*/
75
76 public function getDescription(): string
77 {
78 return $this->description;
79 }
80 /*public function setDescription(string $description = ''): self
81 {
82 $this->description = $description;
83 return $this;
84 }*/
85
86 public function getStart(): \DateTimeInterface
87 {
88 return $this->start;
89 }
90 /*public function setStart(\DateTimeInterface $start): self
91 {
92 $this->start = $start;
93 return $this;
94 }*/
95
96 public function getEnd(): \DateTimeInterface
97 {
98 return $this->end;
99 }
100 /*public function setEnd(\DateTimeInterface $end): self
101 {
102 $this->end = $end;
103 return $this;
104 }*/
105
106 public function isAllDay(): bool
107 {
108 return $this->all_day;
109 }
110 /*public function setAllDay(bool $all_day): self
111 {
112 $this->all_day = $all_day;
113 return $this;
114 }*/
115
116 public function getColor(): ?string
117 {
118 return $this->color;
119 }
120 /*public function setColor(?string $color): self
121 {
122 $this->color = $color;
123 return $this;
124 }*/
125}
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php
index 850f37d..711eb3e 100644
--- a/src/model/entities/Node.php
+++ b/src/model/entities/Node.php
@@ -56,7 +56,7 @@ class Node
56 56
57 private array $children = []; // tableau de Node 57 private array $children = []; // tableau de Node
58 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" 58 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article"
59 static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot'],'js_array' => ['main']]; 59 static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot', 'calendar'],'js_array' => ['main']];
60 60
61 public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) 61 public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null)
62 { 62 {