diff options
Diffstat (limited to 'src/Model/Entity/Event.php')
| -rw-r--r-- | src/Model/Entity/Event.php | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/Model/Entity/Event.php b/src/Model/Entity/Event.php new file mode 100644 index 0000000..3b81da7 --- /dev/null +++ b/src/Model/Entity/Event.php | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | <?php | ||
| 2 | // src/Model/Entity/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(array $json){ | ||
| 43 | $this->securedUpdateFromJSON($json); | ||
| 44 | } | ||
| 45 | |||
| 46 | public function securedUpdateFromJSON(array $json): void | ||
| 47 | { | ||
| 48 | $this->title = htmlspecialchars($json['title']); | ||
| 49 | $this->description = htmlspecialchars($json['description']); | ||
| 50 | try{ | ||
| 51 | $this->start = new \Datetime($json['start']); | ||
| 52 | $this->end = new \Datetime($json['end']); | ||
| 53 | } | ||
| 54 | catch(\Exception $e){ | ||
| 55 | throw new \InvalidArgumentException('Bad date input'); | ||
| 56 | } | ||
| 57 | $all_day = filter_var($json['allDay'] ?? null, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); | ||
| 58 | if(!is_bool($all_day)){ | ||
| 59 | throw new \InvalidArgumentException('Bad checkbox input'); | ||
| 60 | } | ||
| 61 | $this->all_day = $all_day; | ||
| 62 | $this->color = isset($json['color']) ? htmlspecialchars($json['color']) : null; | ||
| 63 | } | ||
| 64 | |||
| 65 | public function getId(): int | ||
| 66 | { | ||
| 67 | return $this->id; | ||
| 68 | } | ||
| 69 | |||
| 70 | public function getTitle(): string | ||
| 71 | { | ||
| 72 | return $this->title; | ||
| 73 | } | ||
| 74 | /*public function setTitle(string $title): self | ||
| 75 | { | ||
| 76 | $this->title = $title; | ||
| 77 | return $this; | ||
| 78 | }*/ | ||
| 79 | |||
| 80 | public function getDescription(): string | ||
| 81 | { | ||
| 82 | return $this->description; | ||
| 83 | } | ||
| 84 | /*public function setDescription(string $description = ''): self | ||
| 85 | { | ||
| 86 | $this->description = $description; | ||
| 87 | return $this; | ||
| 88 | }*/ | ||
| 89 | |||
| 90 | public function getStart(): \DateTimeInterface | ||
| 91 | { | ||
| 92 | return $this->start; | ||
| 93 | } | ||
| 94 | /*public function setStart(\DateTimeInterface $start): self | ||
| 95 | { | ||
| 96 | $this->start = $start; | ||
| 97 | return $this; | ||
| 98 | }*/ | ||
| 99 | |||
| 100 | public function getEnd(): \DateTimeInterface | ||
| 101 | { | ||
| 102 | return $this->end; | ||
| 103 | } | ||
| 104 | /*public function setEnd(\DateTimeInterface $end): self | ||
| 105 | { | ||
| 106 | $this->end = $end; | ||
| 107 | return $this; | ||
| 108 | }*/ | ||
| 109 | |||
| 110 | public function isAllDay(): bool | ||
| 111 | { | ||
| 112 | return $this->all_day; | ||
| 113 | } | ||
| 114 | /*public function setAllDay(bool $all_day): self | ||
| 115 | { | ||
| 116 | $this->all_day = $all_day; | ||
| 117 | return $this; | ||
| 118 | }*/ | ||
| 119 | |||
| 120 | public function getColor(): ?string | ||
| 121 | { | ||
| 122 | return $this->color; | ||
| 123 | } | ||
| 124 | /*public function setColor(?string $color): self | ||
| 125 | { | ||
| 126 | $this->color = $color; | ||
| 127 | return $this; | ||
| 128 | }*/ | ||
| 129 | } | ||
