|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Book\Student; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\BookComment; |
|
6
|
|
|
use App\Entity\LessonAttendanceExcuseStatus; |
|
7
|
|
|
use App\Entity\LessonAttendanceType; |
|
8
|
|
|
use App\Entity\Student; |
|
9
|
|
|
use App\Entity\LessonAttendance as LessonAttendanceEntity; |
|
10
|
|
|
use DateTime; |
|
11
|
|
|
|
|
12
|
|
|
class StudentInfo { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param LessonAttendance[] $lateLessonAttendances |
|
16
|
|
|
* @param LessonAttendance[] $absentLessonAttendances |
|
17
|
|
|
* @param LessonAttendance[] $presentLessonAttendances |
|
18
|
|
|
* @param BookComment[] $comments |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct(private readonly Student $student, private readonly int $totalLessonsCount, private readonly array $lateLessonAttendances, private readonly array $absentLessonAttendances, private readonly array $presentLessonAttendances, private readonly array $comments) |
|
21
|
|
|
{ |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getStudent(): Student { |
|
25
|
|
|
return $this->student; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getTotalLessonsCount(): int { |
|
29
|
|
|
return $this->totalLessonsCount; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return LessonAttendance[] |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getPresentLessonAttendances(): array { |
|
36
|
|
|
return $this->presentLessonAttendances; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return LessonAttendance[] |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getLateLessonAttendances(): array { |
|
43
|
|
|
return $this->lateLessonAttendances; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return LessonAttendance[] |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getAbsentLessonAttendances(): array { |
|
50
|
|
|
return $this->absentLessonAttendances; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getLateMinutesCount(): int { |
|
54
|
|
|
return array_sum( |
|
|
|
|
|
|
55
|
|
|
array_map( |
|
56
|
|
|
fn(LessonAttendance $attendance) => $attendance->getAttendance()->getLateMinutes(), |
|
57
|
|
|
$this->getLateLessonAttendances() |
|
58
|
|
|
) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getAbsentLessonsCount(): int { |
|
63
|
|
|
return array_sum( |
|
|
|
|
|
|
64
|
|
|
array_map( |
|
65
|
|
|
fn(LessonAttendance $attendance) => $attendance->getAttendance()->getType() === LessonAttendanceType::Absent |
|
66
|
|
|
&& $attendance->getAttendance()->getAbsentLessons() > 0 |
|
67
|
|
|
&& ($attendance->getAttendance()->getEntry()->getLessonEnd() - $attendance->getAttendance()->getAbsentLessons()) < $attendance->getLesson() ? 1 : 0, |
|
68
|
|
|
$this->getAbsentLessonAttendances() |
|
69
|
|
|
) |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getNotExcusedOrNotSetLessonsCount(): int { |
|
74
|
|
|
return array_sum( |
|
|
|
|
|
|
75
|
|
|
array_map( |
|
76
|
|
|
fn(LessonAttendance $attendance) => $attendance->getAttendance()->getExcuseStatus() === LessonAttendanceExcuseStatus::NotSet |
|
77
|
|
|
&& $attendance->getExcuses()->count() === 0 |
|
78
|
|
|
&& $attendance->getAttendance()->getAbsentLessons() > 0 |
|
79
|
|
|
&& ($attendance->getAttendance()->getEntry()->getLessonEnd() - $attendance->getAttendance()->getAbsentLessons()) < $attendance->getLesson() ? 1 : 0, |
|
80
|
|
|
$this->getAbsentLessonAttendances() |
|
81
|
|
|
) |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getNotExcusedAbsentLessonsCount(): int { |
|
86
|
|
|
return array_sum( |
|
|
|
|
|
|
87
|
|
|
array_map( |
|
88
|
|
|
fn(LessonAttendance $attendance) => $attendance->getAttendance()->getExcuseStatus() === LessonAttendanceExcuseStatus::NotExcused |
|
89
|
|
|
&& $attendance->getExcuses()->count() === 0, |
|
90
|
|
|
$this->getAbsentLessonAttendances() |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getExcuseCollectionForLesson(LessonAttendanceEntity $attendance): ExcuseCollection { |
|
96
|
|
|
foreach($this->absentLessonAttendances as $absentLessonAttendance) { |
|
97
|
|
|
if($absentLessonAttendance->getAttendance() === $attendance) { |
|
98
|
|
|
return $absentLessonAttendance->getExcuses(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return new ExcuseCollection(clone $attendance->getEntry()->getLesson()->getDate(), $attendance->getEntry()->getLessonStart()); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getAbsentAttendance(DateTime $dateTime, int $lessonNumber): ?LessonAttendance { |
|
106
|
|
|
foreach($this->absentLessonAttendances as $attendance) { |
|
107
|
|
|
if($attendance->getDate() == $dateTime && $attendance->getLesson() === $lessonNumber) { |
|
108
|
|
|
return $attendance; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return null; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function getLateAttendance(DateTime $dateTime, int $lessonNumber): ?LessonAttendance { |
|
116
|
|
|
foreach($this->lateLessonAttendances as $attendance) { |
|
117
|
|
|
if($attendance->getDate() == $dateTime && $attendance->getLesson() === $lessonNumber) { |
|
118
|
|
|
return $attendance; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return null; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return BookComment[] |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getComments(): array { |
|
129
|
|
|
return $this->comments; |
|
130
|
|
|
} |
|
131
|
|
|
} |