diff options
Diffstat (limited to 'src/model/entities')
-rw-r--r-- | src/model/entities/Event.php | 125 | ||||
-rw-r--r-- | src/model/entities/Node.php | 2 |
2 files changed, 126 insertions, 1 deletions
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 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | namespace App\Entity; | ||
7 | |||
8 | use Doctrine\ORM\Mapping as ORM; | ||
9 | |||
10 | #[ORM\Entity] | ||
11 | #[ORM\Table(name: TABLE_PREFIX . 'event')] | ||
12 | class 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 | { |