|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Dashboard; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Absence; |
|
6
|
|
|
use App\Entity\Appointment; |
|
7
|
|
|
use App\Entity\Exam; |
|
8
|
|
|
use App\Entity\Infotext; |
|
9
|
|
|
use App\Entity\LessonEntry; |
|
10
|
|
|
use App\Entity\Message; |
|
11
|
|
|
use App\Entity\MessagePriority; |
|
12
|
|
|
use App\Entity\Student; |
|
13
|
|
|
use App\Entity\Substitution; |
|
14
|
|
|
use App\Entity\Teacher; |
|
15
|
|
|
use DateTime; |
|
16
|
|
|
|
|
17
|
|
|
class DashboardView { |
|
18
|
|
|
|
|
19
|
|
|
/** @var Message[] */ |
|
20
|
|
|
private array $messages = [ ]; |
|
21
|
|
|
|
|
22
|
|
|
/** @var Infotext[] */ |
|
23
|
|
|
private array $infotexts = [ ]; |
|
24
|
|
|
|
|
25
|
|
|
/** @var Absence[] */ |
|
26
|
|
|
private array $absentTeachers = [ ]; |
|
27
|
|
|
|
|
28
|
|
|
/** @var Absence[] */ |
|
29
|
|
|
private array $absentStudyGroups = [ ]; |
|
30
|
|
|
|
|
31
|
|
|
/** @var DashboardLesson[] */ |
|
32
|
|
|
private array $lessons = [ ]; |
|
33
|
|
|
|
|
34
|
|
|
/** @var DashboardLesson[] */ |
|
35
|
|
|
private array $beforeLessons = [ ]; |
|
36
|
|
|
|
|
37
|
|
|
/** @var Message[] */ |
|
38
|
|
|
private array $priorityMessages = [ ]; |
|
39
|
|
|
|
|
40
|
|
|
/** @var SubstitutionViewItem[] */ |
|
41
|
|
|
private array $substitutionMentions = [ ]; |
|
42
|
|
|
|
|
43
|
|
|
/** @var ExamViewItem[] */ |
|
44
|
|
|
private array $exams = [ ]; |
|
45
|
|
|
|
|
46
|
|
|
/** @var Appointment[] */ |
|
47
|
|
|
private array $appointments = [ ]; |
|
48
|
|
|
|
|
49
|
|
|
private array $teacherBirthdays = [ ]; |
|
50
|
|
|
|
|
51
|
|
|
private array $studentBirthdays = [ ]; |
|
52
|
|
|
|
|
53
|
|
|
private ?ExercisesView $exercises = null; |
|
54
|
|
|
|
|
55
|
|
|
public function __construct(private DateTime $dateTime) |
|
56
|
|
|
{ |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getDateTime(): DateTime { |
|
60
|
|
|
return $this->dateTime; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return Message[] |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getMessages(): array { |
|
67
|
|
|
return $this->messages; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getPriorityMessages(): array { |
|
71
|
|
|
return $this->priorityMessages; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return DashboardLesson[] |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getLessons(): array { |
|
78
|
|
|
return $this->lessons; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return int[] |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getLessonNumbers(): array { |
|
85
|
|
|
$lessons = [...array_keys($this->lessons), ...array_keys($this->beforeLessons)]; |
|
86
|
|
|
sort($lessons, SORT_NUMERIC); |
|
87
|
|
|
|
|
88
|
|
|
return array_unique($lessons); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return DashboardLesson[] |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getBeforeLessons(): array { |
|
95
|
|
|
return $this->beforeLessons; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function getLesson(int $lessonNumber, bool $before = false): ?DashboardLesson { |
|
99
|
|
|
if($before === true) { |
|
100
|
|
|
return $this->beforeLessons[$lessonNumber] ?? null; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $this->lessons[$lessonNumber] ?? null; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return Infotext[] |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getInfotexts(): array { |
|
110
|
|
|
return $this->infotexts; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return Absence[] |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getAbsentTeachers(): array { |
|
117
|
|
|
return $this->absentTeachers; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return Absence[] |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getAbsentStudyGroups(): array { |
|
124
|
|
|
return $this->absentStudyGroups; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function addItem(int $lessonNumber, AbstractViewItem $item): void { |
|
128
|
|
|
if(!isset($this->lessons[$lessonNumber])) { |
|
129
|
|
|
$this->lessons[$lessonNumber] = new DashboardLesson($lessonNumber, false); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$this->lessons[$lessonNumber]->addItem($item); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function addItemBefore(int $lessonNumber, AbstractViewItem $item): void { |
|
136
|
|
|
if(!isset($this->beforeLessons[$lessonNumber])) { |
|
137
|
|
|
$this->beforeLessons[$lessonNumber] = new DashboardLesson($lessonNumber, true); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
$this->beforeLessons[$lessonNumber]->addItem($item); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function addMessage(Message $message): void { |
|
144
|
|
|
if($message->getPriority() === MessagePriority::Normal) { |
|
145
|
|
|
$this->messages[] = $message; |
|
146
|
|
|
} else { |
|
147
|
|
|
$this->priorityMessages[] = $message; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function addInfotext(Infotext $infotext): void { |
|
152
|
|
|
$this->infotexts[] = $infotext; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function addAbsence(Absence $absence): void { |
|
156
|
|
|
if($absence->getStudyGroup() !== null) { |
|
157
|
|
|
$this->absentStudyGroups[] = $absence; |
|
158
|
|
|
} else if($absence->getTeacher() !== null) { |
|
159
|
|
|
$this->absentTeachers[] = $absence; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function addExam(ExamViewItem $exam): void { |
|
164
|
|
|
if(!in_array($exam, $this->exams)) { |
|
165
|
|
|
$this->exams[] = $exam; |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @return ExamViewItem[] |
|
171
|
|
|
*/ |
|
172
|
|
|
public function getExams(): array { |
|
173
|
|
|
return $this->exams; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function clearExams(): void { |
|
177
|
|
|
$this->exams = [ ]; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function addSubstitutonMention(SubstitutionViewItem $substitution): void { |
|
181
|
|
|
if(!in_array($substitution, $this->substitutionMentions)) { |
|
182
|
|
|
$this->substitutionMentions[] = $substitution; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return SubstitutionViewItem[] |
|
188
|
|
|
*/ |
|
189
|
|
|
public function getSubstitutionMentions(): array { |
|
190
|
|
|
return $this->substitutionMentions; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function clearSubstitutionMentions(): void { |
|
194
|
|
|
$this->substitutionMentions = [ ]; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function getNumberOfCollisions(): int { |
|
198
|
|
|
$collisions = 0; |
|
199
|
|
|
|
|
200
|
|
|
foreach($this->lessons as $lesson) { |
|
201
|
|
|
if($lesson->hasWarning()) { |
|
202
|
|
|
$collisions++; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
foreach($this->beforeLessons as $lesson) { |
|
207
|
|
|
if($lesson->hasWarning()) { |
|
208
|
|
|
$collisions++; |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
return $collisions; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
public function addAppointment(Appointment $appointment): void { |
|
216
|
|
|
$this->appointments[] = $appointment; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @return Appointment[] |
|
221
|
|
|
*/ |
|
222
|
|
|
public function getAppointments(): array { |
|
223
|
|
|
return $this->appointments; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @return ExercisesView|null |
|
228
|
|
|
*/ |
|
229
|
|
|
public function getExercises(): ?ExercisesView { |
|
230
|
|
|
return $this->exercises; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @param ExercisesView|null $exercises |
|
235
|
|
|
*/ |
|
236
|
|
|
public function setExercises(?ExercisesView $exercises): void { |
|
237
|
|
|
$this->exercises = $exercises; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Removes all timetable and supervisions from the dashboard view |
|
242
|
|
|
* (because the day is free) |
|
243
|
|
|
*/ |
|
244
|
|
|
public function removeLessons(): void { |
|
245
|
|
|
foreach($this->getLessons() as $idx => $lesson) { |
|
246
|
|
|
$lesson->removeLessons(); |
|
247
|
|
|
|
|
248
|
|
|
if(count($lesson->getItems()) === 0) { |
|
249
|
|
|
unset($this->lessons[$idx]); |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
foreach($this->getBeforeLessons() as $idx => $lesson) { |
|
254
|
|
|
$lesson->removeLessons(); |
|
255
|
|
|
|
|
256
|
|
|
if(count($lesson->getItems()) === 0) { |
|
257
|
|
|
unset($this->beforeLessons[$idx]); |
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
public function addStudentBirthday(Student $student): void { |
|
263
|
|
|
$this->studentBirthdays[] = $student; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @return Student[] |
|
268
|
|
|
*/ |
|
269
|
|
|
public function getStudentBirthdays(): array { |
|
270
|
|
|
return $this->studentBirthdays; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
public function addTeacherBirthday(Teacher $teacher): void { |
|
274
|
|
|
$this->teacherBirthdays[] = $teacher; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* @return array |
|
279
|
|
|
*/ |
|
280
|
|
|
public function getTeacherBirthdays(): array { |
|
281
|
|
|
return $this->teacherBirthdays; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
public function isEmpty(): bool { |
|
285
|
|
|
return count($this->messages) === 0 |
|
286
|
|
|
&& count($this->infotexts) === 0 |
|
287
|
|
|
&& count($this->lessons) === 0 |
|
288
|
|
|
&& count($this->beforeLessons) === 0 |
|
289
|
|
|
&& count($this->absentStudyGroups) === 0 |
|
290
|
|
|
&& count($this->absentTeachers) === 0 |
|
291
|
|
|
&& count($this->priorityMessages) === 0 |
|
292
|
|
|
&& count($this->exams) === 0 |
|
293
|
|
|
&& count($this->appointments) === 0 |
|
294
|
|
|
&& count($this->teacherBirthdays) === 0 |
|
295
|
|
|
&& count($this->studentBirthdays) === 0; |
|
296
|
|
|
} |
|
297
|
|
|
} |