Appointment::getCategory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Entity;
4
5
use DateInterval;
6
use DateTime;
7
use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
use Doctrine\ORM\Mapping as ORM;
11
use Ramsey\Uuid\Uuid;
12
use Symfony\Component\Validator\Constraints as Assert;
13
14
#[Auditable]
15
#[ORM\Entity]
16
class Appointment {
17
18
    use IdTrait;
19
    use UuidTrait;
20
21
    #[ORM\Column(type: 'string', unique: true, nullable: true)]
22
    private ?string $externalId = null;
23
24
    #[Assert\NotNull]
25
    #[Assert\NotBlank]
26
    #[ORM\Column(type: 'string')]
27
    private ?string $title = null;
28
29
    #[ORM\Column(type: 'text', nullable: true)]
30
    private ?string $content = null;
31
32
    #[Assert\NotNull]
33
    #[ORM\Column(type: 'datetime')]
34
    private ?DateTime $start = null;
35
36
    #[Assert\GreaterThan(propertyPath: 'start')]
37
    #[ORM\Column(type: 'datetime', nullable: true)]
38
    private ?DateTime $end = null;
39
40
    #[ORM\Column(type: 'string', nullable: true)]
41
    private ?string $location = null;
42
43
    #[ORM\Column(type: 'boolean')]
44
    private bool $allDay = true;
45
46
    /**
47
     * @var ArrayCollection<StudyGroup>
48
     */
49
    #[ORM\JoinTable(name: 'appointment_studygroups')]
50
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
51
    #[ORM\InverseJoinColumn(onDelete: 'CASCADE')]
52
    #[ORM\ManyToMany(targetEntity: StudyGroup::class, cascade: ['persist'])]
53
    private $studyGroups;
54
55
    /**
56
     * @var ArrayCollection<Teacher>
57
     */
58
    #[ORM\JoinTable(name: 'appointment_organizers')]
59
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
60
    #[ORM\InverseJoinColumn(onDelete: 'CASCADE')]
61
    #[ORM\ManyToMany(targetEntity: Teacher::class, cascade: ['persist'])]
62
    private $organizers;
63
64
    #[ORM\Column(type: 'string', nullable: true)]
65
    private ?string $externalOrganizers = null;
66
67
    #[Assert\NotNull]
68
    #[ORM\ManyToOne(targetEntity: AppointmentCategory::class)]
69
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
70
    private ?AppointmentCategory $category = null;
71
72
    /**
73
     * @var ArrayCollection<UserTypeEntity>
74
     */
75
    #[ORM\JoinTable(name: 'appointment_visibilities')]
76
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
77
    #[ORM\InverseJoinColumn(onDelete: 'CASCADE')]
78
    #[ORM\ManyToMany(targetEntity: UserTypeEntity::class)]
79
    private $visibilities;
80
81
    #[ORM\Column(type: 'boolean', options: ['default' => true])]
82
    private bool $isConfirmed = true;
83
84
    /**
85
     *
86
     * Note: we cannot use the Blameable() listener here as it would break when importing appointments
87
     * from API
88
     */
89
    #[ORM\ManyToOne(targetEntity: User::class)]
90
    #[ORM\JoinColumn(nullable: true)]
91
    private ?User $createdBy = null;
92
93
    public function __construct() {
94
        $this->uuid = Uuid::uuid4();
95
96
        $this->studyGroups = new ArrayCollection();
97
        $this->organizers = new ArrayCollection();
98
        $this->visibilities = new ArrayCollection();
99
    }
100
101
    public function getExternalId(): ?string {
102
        return $this->externalId;
103
    }
104
105
    public function setExternalId(?string $externalId): Appointment {
106
        $this->externalId = $externalId;
107
        return $this;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getTitle(): ?string {
114
        return $this->title;
115
    }
116
117
    /**
118
     * @param string $title
119
     */
120
    public function setTitle(?string $title): Appointment {
121
        $this->title = $title;
122
        return $this;
123
    }
124
125
    public function getContent(): ?string {
126
        return $this->content;
127
    }
128
129
    public function setContent(?string $content): Appointment {
130
        $this->content = $content;
131
        return $this;
132
    }
133
134
    /**
135 7
     * @return DateTime
136 7
     */
137
    public function getStart(): ?DateTime {
138 7
        return $this->start;
139 7
    }
140 7
141 7
    /**
142
     * @param DateTime $start
143
     */
144
    public function setStart(?DateTime $start): Appointment {
145
        $this->start = $start;
146 1
        return $this;
147 1
    }
148
149
    /**
150
     * @return DateTime
151
     */
152
    public function getEnd(): ?DateTime {
153
        return $this->end;
154 2
    }
155 2
156 2
    /**
157
     * @param DateTime $end
158
     */
159
    public function setEnd(?DateTime $end): Appointment {
160
        $this->end = $end;
161
        return $this;
162 1
    }
163 1
164
    public function getLocation(): ?string {
165
        return $this->location;
166
    }
167
168
    public function setLocation(?string $location): Appointment {
169
        $this->location = $location;
170 2
        return $this;
171 2
    }
172 2
173
    public function isAllDay(): bool {
174
        return $this->allDay;
175
    }
176
177
    public function setAllDay(bool $allDay): Appointment {
178 1
        $this->allDay = $allDay;
179 1
        return $this;
180
    }
181
182
    public function getCategory(): ?AppointmentCategory {
183
        return $this->category;
184
    }
185
186 2
    public function setCategory(AppointmentCategory $category): Appointment {
187 2
        $this->category = $category;
188 2
        return $this;
189
    }
190
191
    public function getExternalOrganizers(): ?string {
192
        return $this->externalOrganizers;
193
    }
194 3
195 3
    public function setExternalOrganizers(?string $externalOrganizers): Appointment {
196
        $this->externalOrganizers = $externalOrganizers;
197
        return $this;
198
    }
199
200
    public function addOrganizer(Teacher $teacher) {
201
        $this->organizers->add($teacher);
202 3
    }
203 3
204 3
    public function removeOrganizer(Teacher $teacher) {
205
        $this->organizers->removeElement($teacher);
206
    }
207
208
    /**
209
     * @return ArrayCollection<Teacher>
210 6
     */
211 6
    public function getOrganizers() {
212
        return $this->organizers;
213
    }
214
215
    public function addStudyGroup(StudyGroup $studyGroup) {
216
        $this->studyGroups->add($studyGroup);
217
    }
218 6
219 6
    public function removeStudyGroup(StudyGroup $studyGroup) {
220 6
        $this->studyGroups->removeElement($studyGroup);
221
    }
222
223
    /**
224
     * @return ArrayCollection<StudyGroup>
225
     */
226 1
    public function getStudyGroups() {
227 1
        return $this->studyGroups;
228
    }
229
230
    public function addVisibility(UserTypeEntity $visibility) {
231
        $this->visibilities->add($visibility);
232
    }
233
234 2
    public function removeVisibility(UserTypeEntity $visibility) {
235 2
        $this->visibilities->removeElement($visibility);
236 2
    }
237
238
    /**
239
     * @return Collection<UserTypeEntity>
240
     */
241
    public function getVisibilities(): Collection {
242 5
        return $this->visibilities;
243 5
    }
244
245
    public function isConfirmed(): bool {
246
        return $this->isConfirmed;
247
    }
248
249
    public function setIsConfirmed(bool $isConfirmed): Appointment {
250 6
        $this->isConfirmed = $isConfirmed;
251 6
        return $this;
252 6
    }
253
254
    public function getCreatedBy(): ?User {
255
        return $this->createdBy;
256
    }
257
258 1
    public function setCreatedBy(?User $createdBy): Appointment {
259 1
        $this->createdBy = $createdBy;
260
        return $this;
261
    }
262
263
    public function getRealEnd(): DateTime {
264
        if($this->isAllDay() === false) {
265
            return $this->getEnd();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getEnd() could return the type null which is incompatible with the type-hinted return DateTime. Consider adding an additional type-check to rule them out.
Loading history...
266 2
        }
267 2
268 2
        return (clone $this->getEnd())->modify('-1 second');
269
    }
270
271
    public function getDuration(): DateInterval {
272
        return $this->getStart()->diff($this->getEnd());
273
    }
274
}