Passed
Push — master ( 15bb7c...3ad356 )
by Julito
10:34
created

CourseRelUser::getStatusList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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\ApiFilter;
10
use ApiPlatform\Core\Annotation\ApiResource;
11
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
12
use Chamilo\CoreBundle\Traits\UserTrait;
13
use Doctrine\ORM\Mapping as ORM;
14
use Symfony\Component\Serializer\Annotation\Groups;
15
use Symfony\Component\Serializer\Annotation\MaxDepth;
16
use Symfony\Component\Validator\Constraints as Assert;
17
18
/**
19
 * User subscriptions to a course.
20
 *
21
 * @ORM\Table(
22
 *     name="course_rel_user",
23
 *     indexes={
24
 *         @ORM\Index(name="course_rel_user_user_id", columns={"id", "user_id"}),
25
 *         @ORM\Index(name="course_rel_user_c_id_user_id", columns={"id", "c_id", "user_id"})
26
 *     }
27
 * )
28
 * @ORM\Entity
29
 */
30
#[ApiResource(
31
    attributes: [
32
        'security' => "is_granted('ROLE_USER')",
33
    ],
34
    collectionOperations: [
35
        'get' => [
36
            'security' => "is_granted('ROLE_ADMIN')",
37
        ],
38
        'post' => [
39
            'security' => "is_granted('ROLE_ADMIN')",
40
        ],
41
    ],
42
    itemOperations: [
43
        'get' => [
44
            'security' => "is_granted('ROLE_ADMIN') or object.user == user",
45
        ],
46
    ],
47
    subresourceOperations: [
48
        'api_users_courses_get_subresource' => [
49
            'security' => "is_granted('ROLE_USER')",
50
        ],
51
    ],
52
    normalizationContext: [
53
        'groups' => ['course_rel_user:read', 'user:read'],
54
        'enable_max_depth' => true,
55
    ],
56
)]
57
#[ApiFilter(SearchFilter::class, properties: [
58
    'status' => 'exact',
59
    'user' => 'exact',
60
    'user.username' => 'partial',
61
])]
62
63
class CourseRelUser
64
{
65
    use UserTrait;
66
67
    public const TEACHER = 1;
68
    //public const SESSION_ADMIN = 3;
69
    //public const DRH = 4;
70
    public const STUDENT = 5;
71
72
    /**
73
     * @ORM\Column(name="id", type="integer")
74
     * @ORM\Id
75
     * @ORM\GeneratedValue
76
     */
77
    protected ?int $id = null;
78
79
    /**
80
     * @Groups({"course:read", "user:read"})
81
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="courses", cascade={"persist"})
82
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
83
     */
84
    #[MaxDepth(1)]
85
    protected User $user;
86
87
    /**
88
     * @Groups({"user:read"})
89
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="users", cascade={"persist"})
90
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id")
91
     */
92
    protected Course $course;
93
94
    /**
95
     * @Groups({"course:read", "user:read"})
96
     * @ORM\Column(name="relation_type", type="integer")
97
     */
98
    protected int $relationType;
99
100
    /**
101
     * @Groups({"user:read"})
102
     * @ORM\Column(name="status", type="integer")
103
     */
104
    protected int $status;
105
106
    /**
107
     * @ORM\Column(name="is_tutor", type="boolean", nullable=true, unique=false)
108
     */
109
    protected ?bool $tutor;
110
111
    /**
112
     * @ORM\Column(name="sort", type="integer", nullable=true, unique=false)
113
     */
114
    protected ?int $sort;
115
116
    /**
117
     * @ORM\Column(name="user_course_cat", type="integer", nullable=true, unique=false)
118
     */
119
    protected ?int $userCourseCat;
120
121
    /**
122
     * @ORM\Column(name="legal_agreement", type="integer", nullable=true, unique=false)
123
     */
124
    protected ?int $legalAgreement = null;
125
126
    /**
127
     * @Groups({"course:read", "user:read"})
128
     * @Assert\Range(
129
     *     min = 0,
130
     *     max = 100,
131
     *     notInRangeMessage = "Progress from {{ min }} to {{ max }} only",
132
     * )
133
     * @ORM\Column(name="progress", type="integer")
134
     */
135
    protected int $progress;
136
137
    public function __construct()
138
    {
139
        $this->progress = 0;
140
        $this->userCourseCat = 0;
141
        $this->sort = 0;
142
        $this->tutor = false;
143
        $this->status = self::STUDENT;
144
        $this->relationType = 0;
145
    }
146
147
    public function __toString(): string
148
    {
149
        return $this->getCourse()->getCode();
150
    }
151
152
    public function getId(): ?int
153
    {
154
        return $this->id;
155
    }
156
157
    public function setCourse(Course $course): self
158
    {
159
        $this->course = $course;
160
161
        return $this;
162
    }
163
164
    public function getCourse(): Course
165
    {
166
        return $this->course;
167
    }
168
169
    public function setRelationType(int $relationType): self
170
    {
171
        $this->relationType = $relationType;
172
173
        return $this;
174
    }
175
176
    public function getRelationType(): int
177
    {
178
        return $this->relationType;
179
    }
180
181
    public function setStatus(int $status): self
182
    {
183
        $this->status = $status;
184
185
        return $this;
186
    }
187
188
    public function getStatus(): int
189
    {
190
        return $this->status;
191
    }
192
193
    public function setSort(int $sort): self
194
    {
195
        $this->sort = $sort;
196
197
        return $this;
198
    }
199
200
    public function getSort(): ?int
201
    {
202
        return $this->sort;
203
    }
204
205
    public function isTutor(): ?bool
206
    {
207
        return $this->tutor;
208
    }
209
210
    public function setTutor(bool $tutor): self
211
    {
212
        $this->tutor = $tutor;
213
214
        return $this;
215
    }
216
217
    public function setUserCourseCat(int $userCourseCat): self
218
    {
219
        $this->userCourseCat = $userCourseCat;
220
221
        return $this;
222
    }
223
224
    public function getUserCourseCat(): ?int
225
    {
226
        return $this->userCourseCat;
227
    }
228
229
    public function setLegalAgreement(int $legalAgreement): self
230
    {
231
        $this->legalAgreement = $legalAgreement;
232
233
        return $this;
234
    }
235
236
    public function getLegalAgreement(): ?int
237
    {
238
        return $this->legalAgreement;
239
    }
240
241
    public function getUser(): User
242
    {
243
        return $this->user;
244
    }
245
246
    public function setUser(User $user): self
247
    {
248
        $this->user = $user;
249
250
        return $this;
251
    }
252
253
    public function getProgress(): int
254
    {
255
        return $this->progress;
256
    }
257
258
    public function setProgress(int $progress): self
259
    {
260
        $this->progress = $progress;
261
262
        return $this;
263
    }
264
}
265