Passed
Push — master ( 12773c...b56fa5 )
by Julito
09:46
created

SessionRelUser::getCourses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use ApiPlatform\Core\Annotation\ApiResource;
10
use Chamilo\CoreBundle\Traits\UserTrait;
11
use DateTime;
12
use DateTimeZone;
13
use Doctrine\Common\Collections\Collection;
14
use Doctrine\ORM\Mapping as ORM;
15
use Symfony\Component\Serializer\Annotation\Groups;
16
17
/**
18
 * SessionRelUser.
19
 *
20
 * @ApiResource(
21
 *     shortName="SessionSubscription",
22
 *     normalizationContext={"groups"={"session_rel_user:read"}}
23
 * )
24
 * @ORM\Table(
25
 *     name="session_rel_user",
26
 *     indexes={
27
 *         @ORM\Index(name="idx_session_rel_user_id_user_moved", columns={"user_id", "moved_to"})
28
 *     }
29
 * )
30
 * @ORM\Entity
31
 */
32
class SessionRelUser
33
{
34
    use UserTrait;
35
36
    /**
37
     * @var string[]
38
     */
39
    public array $relationTypeList = [
40
        0 => 'student',
41
        1 => 'drh',
42
    ];
43
44
    /**
45
     * @ORM\Column(name="id", type="integer")
46
     * @ORM\Id
47
     * @ORM\GeneratedValue
48
     */
49
    protected int $id;
50
51
    /**
52
     * @Groups({"session_rel_user:read"})
53
     *
54
     * @ORM\ManyToOne(targetEntity="Session", inversedBy="users", cascade={"persist"})
55
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id")
56
     */
57
    protected Session $session;
58
59
    /**
60
     * @Groups({"session_rel_user:read"})
61
     *
62
     * @ORM\ManyToOne(targetEntity="User", inversedBy="sessionsRelUser", cascade={"persist"})
63
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
64
     */
65
    protected User $user;
66
67
    /**
68
     * @ORM\Column(name="relation_type", type="integer")
69
     */
70
    protected int $relationType;
71
72
    /**
73
     * @ORM\Column(name="duration", type="integer", nullable=false)
74
     */
75
    protected int $duration;
76
77
    /**
78
     * @ORM\Column(name="moved_to", type="integer", nullable=true, unique=false)
79
     */
80
    protected ?int $movedTo;
81
82
    /**
83
     * @ORM\Column(name="moved_status", type="integer", nullable=true, unique=false)
84
     */
85
    protected ?int $movedStatus;
86
87
    /**
88
     * @ORM\Column(name="moved_at", type="datetime", nullable=true, unique=false)
89
     */
90
    protected ?DateTime $movedAt = null;
91
92
    /**
93
     * @ORM\Column(name="registered_at", type="datetime")
94
     */
95
    protected DateTime $registeredAt;
96
97
    /**
98
     * @Groups({"session_rel_user:read"})
99
     */
100
    protected Collection $courses;
101
102
    public function __construct()
103
    {
104
        $this->duration = 0;
105
        $this->movedTo = null;
106
        $this->movedStatus = null;
107
        $this->registeredAt = new DateTime('now', new DateTimeZone('UTC'));
108
    }
109
110
    public function getCourses()
111
    {
112
        return $this->session->getCoursesByUser($this->getUser());
113
    }
114
115
    public function getId(): int
116
    {
117
        return $this->id;
118
    }
119
120
    public function setSession(Session $session): self
121
    {
122
        $this->session = $session;
123
124
        return $this;
125
    }
126
127
    public function getSession(): Session
128
    {
129
        return $this->session;
130
    }
131
132
    public function setRelationType(int $relationType): self
133
    {
134
        $this->relationType = $relationType;
135
136
        return $this;
137
    }
138
139
    public function setRelationTypeByName(string $relationType): self
140
    {
141
        if (isset($this->relationTypeList[$relationType])) {
142
            $this->setRelationType((int) $this->relationTypeList[$relationType]);
143
        }
144
145
        return $this;
146
    }
147
148
    public function getRelationType(): int
149
    {
150
        return $this->relationType;
151
    }
152
153
    public function setMovedTo(int $movedTo): self
154
    {
155
        $this->movedTo = $movedTo;
156
157
        return $this;
158
    }
159
160
    /**
161
     * Get movedTo.
162
     *
163
     * @return int
164
     */
165
    public function getMovedTo()
166
    {
167
        return $this->movedTo;
168
    }
169
170
    public function setMovedStatus(int $movedStatus): self
171
    {
172
        $this->movedStatus = $movedStatus;
173
174
        return $this;
175
    }
176
177
    /**
178
     * Get movedStatus.
179
     *
180
     * @return int
181
     */
182
    public function getMovedStatus()
183
    {
184
        return $this->movedStatus;
185
    }
186
187
    public function setMovedAt(DateTime $movedAt): self
188
    {
189
        $this->movedAt = $movedAt;
190
191
        return $this;
192
    }
193
194
    /**
195
     * Get movedAt.
196
     *
197
     * @return DateTime
198
     */
199
    public function getMovedAt()
200
    {
201
        return $this->movedAt;
202
    }
203
204
    public function setRegisteredAt(DateTime $registeredAt): self
205
    {
206
        $this->registeredAt = $registeredAt;
207
208
        return $this;
209
    }
210
211
    /**
212
     * Get registeredAt.
213
     *
214
     * @return DateTime
215
     */
216
    public function getRegisteredAt()
217
    {
218
        return $this->registeredAt;
219
    }
220
221
    /**
222
     * @return int
223
     */
224
    public function getDuration()
225
    {
226
        return $this->duration;
227
    }
228
229
    public function setDuration(int $duration): self
230
    {
231
        $this->duration = $duration;
232
233
        return $this;
234
    }
235
}
236