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