Passed
Push — master ( 12773c...b56fa5 )
by Julito
09:46
created

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