diff options
Diffstat (limited to 'src/model/entities/Event.php')
| -rw-r--r-- | src/model/entities/Event.php | 125 |
1 files changed, 125 insertions, 0 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 | } | ||
