Passed
Pull Request — master (#6281)
by
unknown
08:13
created

CAttendanceSheet::setPresence()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\User;
10
use Doctrine\ORM\Mapping as ORM;
11
use Symfony\Component\Validator\Constraints as Assert;
12
13
#[ORM\Table(name: 'c_attendance_sheet')]
14
#[ORM\Index(columns: ['presence'], name: 'presence')]
15
#[ORM\Entity]
16
class CAttendanceSheet
17
{
18
    public const ABSENT = 0;
19
    public const PRESENT = 1;
20
    public const LATE_LESS_THAN_15_MINUTES = 2;
21
    public const LATE_MORE_THAN_15_MINUTES = 3;
22
    public const ABSENT_BUT_JUSTIFIED = 4;
23
24
    #[ORM\Column(name: 'iid', type: 'integer')]
25
    #[ORM\Id]
26
    #[ORM\GeneratedValue]
27
    protected ?int $iid = null;
28
29
    /**
30
     * Attendance status for each user on a given date:
31
     * - 0: Absent (Score: 0)
32
     * - 1: Present (Score: 1)
33
     * - 2: Late less than 15 minutes (Score: 1)
34
     * - 3: Late more than 15 minutes (Score: 0.5)
35
     * - 4: Absent but justified (Score: 0.25)
36
     *
37
     * Scores are tentative and can be used for gradebook calculations.
38
     */
39
    #[Assert\NotNull]
40
    #[ORM\Column(name: 'presence', type: 'integer', nullable: true)]
41
    protected ?int $presence = null;
42
43
    #[ORM\ManyToOne(targetEntity: User::class)]
44
    #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
45
    protected User $user;
46
47
    #[ORM\ManyToOne(targetEntity: CAttendanceCalendar::class, inversedBy: 'sheets')]
48
    #[ORM\JoinColumn(name: 'attendance_calendar_id', referencedColumnName: 'iid', onDelete: 'CASCADE')]
49
    protected CAttendanceCalendar $attendanceCalendar;
50
51
    #[ORM\Column(name: 'signature', type: 'text', nullable: true)]
52
    protected ?string $signature;
53
54
    public function getIid(): ?int
55
    {
56
        return $this->iid;
57
    }
58
59
    public function setPresence(?int $presence): self
60
    {
61
        $this->presence = $presence;
62
63
        return $this;
64
    }
65
66
    public function getPresence(): ?int
67
    {
68
        return $this->presence;
69
    }
70
71
    public function setSignature(?string $signature): static
72
    {
73
        $this->signature = $signature;
74
75
        return $this;
76
    }
77
78
    public function getSignature(): ?string
79
    {
80
        return $this->signature;
81
    }
82
83
    public function getUser(): User
84
    {
85
        return $this->user;
86
    }
87
88
    public function setUser(User $user): self
89
    {
90
        $this->user = $user;
91
92
        return $this;
93
    }
94
95
    public function getAttendanceCalendar(): CAttendanceCalendar
96
    {
97
        return $this->attendanceCalendar;
98
    }
99
100
    public function setAttendanceCalendar(CAttendanceCalendar $attendanceCalendar): self
101
    {
102
        $this->attendanceCalendar = $attendanceCalendar;
103
104
        return $this;
105
    }
106
107
    public static function getPresenceLabels(): array
108
    {
109
        return [
110
            self::ABSENT => 'Absent',
111
            self::PRESENT => 'Present',
112
            self::LATE_LESS_THAN_15_MINUTES => 'Late < 15 min',
113
            self::LATE_MORE_THAN_15_MINUTES => 'Late > 15 min',
114
            self::ABSENT_BUT_JUSTIFIED => 'Absent, justified',
115
        ];
116
    }
117
}
118