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