blob: ae0d3967f76761e49f08b8a3c824e8eea9040f91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
<?php
// src/model/entities/Event.php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: TABLE_PREFIX . 'event')]
class Event
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private int $id;
#[ORM\Column(type: 'string', length: 255)] // type varchar(255)
private string $title;
// contrôle JS: if(title.length > 255)
#[ORM\Column(type: 'text')]
private string $description = '';
// chatgpt: Dans un contexte API/Front comme FullCalendar,
// préférer une chaîne vide à une varaible "null" peut être plus pratique,
// car ça évite des contrôles côté JS.
#[ORM\Column(type: 'datetime')] // chatgpt: Doctrine suppose UTC si pas de configuration spécifique
private \DateTimeInterface $start; // typage possible avec une interface,
//chatgpt: choix \DateTime par défaut, autorise \DateTimeImmutable
#[ORM\Column(type: 'datetime')]
private \DateTimeInterface $end;
#[ORM\Column(type: 'boolean')]
private bool $all_day;
#[ORM\Column(type: 'string', length: 7, nullable: true)]
private ?string $color = null;
public function __construct(array $json){
$this->securedUpdateFromJSON($json);
}
public function securedUpdateFromJSON(array $json): void
{
$this->title = htmlspecialchars($json['title']);
$this->description = htmlspecialchars($json['description']);
try{
$this->start = new \Datetime($json['start']);
$this->end = new \Datetime($json['end']);
}
catch(\Exception $e){
throw new \InvalidArgumentException('Bad date input');
}
$all_day = filter_var($json['allDay'] ?? null, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if(!is_bool($all_day)){
throw new \InvalidArgumentException('Bad checkbox input');
}
$this->all_day = $all_day;
$this->color = isset($json['color']) ? htmlspecialchars($json['color']) : null;
}
public function getId(): int
{
return $this->id;
}
public function getTitle(): string
{
return $this->title;
}
/*public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}*/
public function getDescription(): string
{
return $this->description;
}
/*public function setDescription(string $description = ''): self
{
$this->description = $description;
return $this;
}*/
public function getStart(): \DateTimeInterface
{
return $this->start;
}
/*public function setStart(\DateTimeInterface $start): self
{
$this->start = $start;
return $this;
}*/
public function getEnd(): \DateTimeInterface
{
return $this->end;
}
/*public function setEnd(\DateTimeInterface $end): self
{
$this->end = $end;
return $this;
}*/
public function isAllDay(): bool
{
return $this->all_day;
}
/*public function setAllDay(bool $all_day): self
{
$this->all_day = $all_day;
return $this;
}*/
public function getColor(): ?string
{
return $this->color;
}
/*public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}*/
}
|