Passed
Push — master ( 691de2...3ef090 )
by Julito
09:33
created

CourseRelUser::setTutor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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