Passed
Push — master ( 35e116...03a9f3 )
by Angel Fernando Quiroz
10:35 queued 19s
created

SessionRelUser::getAccessEndDate()   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
nc 1
nop 0
dl 0
loc 3
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\CoreBundle\Entity;
8
9
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
10
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
11
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
12
use ApiPlatform\Metadata\ApiFilter;
13
use ApiPlatform\Metadata\ApiResource;
14
use ApiPlatform\Metadata\Get;
15
use ApiPlatform\Metadata\GetCollection;
16
use ApiPlatform\Metadata\Post;
17
use DateTime;
18
use DateTimeZone;
19
use Doctrine\Common\Collections\Collection;
20
use Doctrine\ORM\Mapping as ORM;
21
use Exception;
22
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
23
use Symfony\Component\Serializer\Annotation\Groups;
24
use Symfony\Component\Validator\Constraints as Assert;
25
26
/**
27
 * User subscriptions to a session. See also SessionRelCourseRelUser.php for a more detail subscription by course.
28
 */
29
#[ApiResource(
30
    operations: [
31
        new Get(security: "is_granted('ROLE_ADMIN') or object.user == user"),
32
        new GetCollection(security: "is_granted('ROLE_USER')"),
33
        new Post(security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"),
34
    ],
35
    normalizationContext: [
36
        'groups' => [
37
            'session_rel_user:read',
38
        ],
39
    ],
40
    security: "is_granted('ROLE_USER')"
41
)]
42
#[ORM\Table(name: 'session_rel_user')]
43
#[ORM\Index(columns: ['user_id', 'moved_to'], name: 'idx_session_rel_user_id_user_moved')]
44
#[ORM\UniqueConstraint(name: 'session_user_unique', columns: ['session_id', 'user_id', 'relation_type'])]
45
#[ORM\Entity]
46
#[UniqueEntity(
47
    fields: ['session', 'user', 'relationType'],
48
    message: 'The user-course-relationType is already registered in this session.'
49
)]
50
#[ApiFilter(
51
    filterClass: SearchFilter::class,
52
    properties: ['session' => 'exact', 'user' => 'exact', 'relationType' => 'exact']
53
)]
54
#[ApiFilter(
55
    filterClass: DateFilter::class,
56
    properties: [
57
        'session.displayStartDate' => DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER,
58
        'session.displayEndDate' => DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER,
59
        'session.accessStartDate' => DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER,
60
        'session.accessEndDate' => DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER,
61
        'session.coachAccessStartDate' => DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER,
62
        'session.coachAccessEndDate' => DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER,
63
    ]
64
)]
65
class SessionRelUser
66
{
67
    #[ORM\Column(name: 'id', type: 'integer')]
68
    #[ORM\Id]
69
    #[ORM\GeneratedValue]
70
    protected ?int $id = null;
71
72
    #[Assert\NotNull]
73
    #[Groups(['session_rel_user:read'])]
74
    #[ORM\ManyToOne(targetEntity: Session::class, cascade: ['persist'], inversedBy: 'users')]
75
    #[ORM\JoinColumn(name: 'session_id', referencedColumnName: 'id')]
76
    protected ?Session $session = null;
77
78
    #[Assert\NotNull]
79
    #[Groups(['session_rel_user:read', 'session:item:read', 'user_subscriptions:sessions', 'session:basic'])]
80
    #[ORM\ManyToOne(targetEntity: User::class, cascade: ['persist'], inversedBy: 'sessionsRelUser')]
81
    #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
82
    protected User $user;
83
84
    #[Groups(['session_rel_user:read', 'session:item:read', 'user_subscriptions:sessions'])]
85
    #[Assert\Choice(callback: [Session::class, 'getRelationTypeList'], message: 'Choose a valid relation type.')]
86
    #[ORM\Column(name: 'relation_type', type: 'integer')]
87
    protected int $relationType;
88
89
    #[Groups(['session_rel_user:read'])]
90
    #[ORM\Column(name: 'duration', type: 'integer', nullable: false)]
91
    protected int $duration;
92
93
    #[ORM\Column(name: 'moved_to', type: 'integer', unique: false, nullable: true)]
94
    protected ?int $movedTo;
95
96
    #[ORM\Column(name: 'moved_status', type: 'integer', unique: false, nullable: true)]
97
    protected ?int $movedStatus;
98
99
    #[ORM\Column(name: 'moved_at', type: 'datetime', unique: false, nullable: true)]
100
    protected ?DateTime $movedAt = null;
101
102
    #[ORM\Column(name: 'registered_at', type: 'datetime')]
103
    protected DateTime $registeredAt;
104
105
    #[Groups(['session_rel_user:read'])]
106
    protected Collection $courses;
107
108
    #[ORM\Column(name: 'collapsed', type: 'boolean', nullable: true, options: ['default' => null])]
109
    protected ?bool $collapsed = null;
110
111
    #[ORM\Column(name: 'new_subscription_session_id', type: 'integer', nullable: true)]
112
    protected ?int $newSubscriptionSessionId = null;
113
114
    #[ORM\Column(name: 'access_start_date', type: 'datetime', unique: false, nullable: true)]
115
    protected ?DateTime $accessStartDate;
116
117
    #[ORM\Column(name: 'access_end_date', type: 'datetime', unique: false, nullable: true)]
118
    protected ?DateTime $accessEndDate;
119
120
    /**
121
     * @throws Exception
122
     */
123
    public function __construct()
124
    {
125
        $this->relationType = Session::STUDENT;
126
        $this->duration = 0;
127
        $this->movedTo = null;
128
        $this->movedStatus = null;
129
        $this->registeredAt = new DateTime('now', new DateTimeZone('UTC'));
130
    }
131
132
    public function getCourses(): Collection
133
    {
134
        return $this->session->getSessionRelCourseByUser($this->getUser());
0 ignored issues
show
Bug introduced by
The method getSessionRelCourseByUser() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

134
        return $this->session->/** @scrutinizer ignore-call */ getSessionRelCourseByUser($this->getUser());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
    }
136
137
    public function getUser(): User
138
    {
139
        return $this->user;
140
    }
141
142
    public function setUser(User $user): self
143
    {
144
        $user->addSessionRelUser($this);
145
        $this->user = $user;
146
147
        return $this;
148
    }
149
150
    public function getId(): ?int
151
    {
152
        return $this->id;
153
    }
154
155
    public function getSession(): ?Session
156
    {
157
        return $this->session;
158
    }
159
160
    public function setSession(?Session $session): self
161
    {
162
        $this->session = $session;
163
164
        return $this;
165
    }
166
167
    public function getRelationType(): int
168
    {
169
        return $this->relationType;
170
    }
171
172
    public function setRelationType(int $relationType): self
173
    {
174
        $this->relationType = $relationType;
175
176
        return $this;
177
    }
178
179
    public function getMovedTo(): ?int
180
    {
181
        return $this->movedTo;
182
    }
183
184
    public function setMovedTo(int $movedTo): self
185
    {
186
        $this->movedTo = $movedTo;
187
188
        return $this;
189
    }
190
191
    public function getMovedStatus(): ?int
192
    {
193
        return $this->movedStatus;
194
    }
195
196
    public function setMovedStatus(int $movedStatus): self
197
    {
198
        $this->movedStatus = $movedStatus;
199
200
        return $this;
201
    }
202
203
    public function getMovedAt(): ?DateTime
204
    {
205
        return $this->movedAt;
206
    }
207
208
    public function setMovedAt(DateTime $movedAt): self
209
    {
210
        $this->movedAt = $movedAt;
211
212
        return $this;
213
    }
214
215
    public function getRegisteredAt(): DateTime
216
    {
217
        return $this->registeredAt;
218
    }
219
220
    public function setRegisteredAt(DateTime $registeredAt): self
221
    {
222
        $this->registeredAt = $registeredAt;
223
224
        return $this;
225
    }
226
227
    public function getDuration(): int
228
    {
229
        return $this->duration;
230
    }
231
232
    public function setDuration(int $duration): self
233
    {
234
        $this->duration = $duration;
235
236
        return $this;
237
    }
238
239
    public function getNewSubscriptionSessionId(): ?int
240
    {
241
        return $this->newSubscriptionSessionId;
242
    }
243
244
    public function setNewSubscriptionSessionId(?int $newSubscriptionSessionId): self
245
    {
246
        $this->newSubscriptionSessionId = $newSubscriptionSessionId;
247
248
        return $this;
249
    }
250
251
    public function getAccessStartDate(): ?DateTime
252
    {
253
        return $this->accessStartDate;
254
    }
255
256
    public function setAccessStartDate(?DateTime $accessStartDate): SessionRelUser
257
    {
258
        $this->accessStartDate = $accessStartDate;
259
260
        return $this;
261
    }
262
263
    public function getAccessEndDate(): ?DateTime
264
    {
265
        return $this->accessEndDate;
266
    }
267
268
    public function setAccessEndDate(?DateTime $accessEndDate): SessionRelUser
269
    {
270
        $this->accessEndDate = $accessEndDate;
271
272
        return $this;
273
    }
274
}
275