summaryrefslogtreecommitdiff
path: root/src/model/entities/Event.php
blob: c85832f161d0eb892c615f5a2ba509640d9e1160 (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
<?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(string $title, string|\DateTimeInterface $start, string|\DateTimeInterface $end, bool $all_day, string $description = '', string $color = null){
        $this->title = $title;
        $this->description = $description;
        $this->start = gettype($start) === 'string' ? new \DateTime($start) : $start;
        $this->end = gettype($end) === 'string' ? new \DateTime($end) : $end;
        $this->all_day = $all_day;
        $this->color = $color;
    }

    public function updateFromJSON(array $json): void
    {
        $this->title = $json['title'];
        $this->description = $json['description'];
        $this->start = new \DateTime($json['start']);
        $this->end = new \DateTime($json['end']);
        $this->all_day = $json['allDay'];
        $this->color = $json['color'];
    }

    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;
    }*/
}