Completed
Push — master ( 5b557d...3742bc )
by Julito
12:11
created

ResourceLink::getUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Entity\Resource;
5
6
use Chamilo\CoreBundle\Entity\Course;
7
use Chamilo\CoreBundle\Entity\Session;
8
use Chamilo\CoreBundle\Entity\Usergroup;
9
use Chamilo\CourseBundle\Entity\CGroupInfo;
10
use Chamilo\UserBundle\Entity\User;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\ORM\Mapping as ORM;
13
14
/**
15
 * @ORM\Entity
16
 * @ORM\Table(name="resource_link")
17
 */
18
class ResourceLink
19
{
20
    public const VISIBILITY_DRAFT = 0;
21
    public const VISIBILITY_PENDING = 1;
22
    public const VISIBILITY_PUBLISHED = 2;
23
    public const VISIBILITY_DELETED = 3;
24
25
    /**
26
     * @ORM\Id
27
     * @ORM\Column(type="integer")
28
     * @ORM\GeneratedValue(strategy="AUTO")
29
     */
30
    protected $id;
31
32
    /**
33
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", inversedBy="resourceLinks")
34
     * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id")
35
     */
36
    protected $resourceNode;
37
38
    /**
39
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", inversedBy="resourceLinks")
40
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
41
     */
42
    protected $session;
43
44
    /**
45
     * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
46
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)
47
     */
48
    protected $user;
49
50
    /**
51
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="resourceLinks")
52
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=true)
53
     */
54
    protected $course;
55
56
    /**
57
     * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CGroupInfo")
58
     * @ORM\JoinColumn(name="group_id", referencedColumnName="iid", nullable=true, onDelete="CASCADE")
59
     */
60
    protected $group;
61
62
    /**
63
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Usergroup")
64
     * @ORM\JoinColumn(name="usergroup_id", referencedColumnName="id", nullable=true)
65
     */
66
    protected $userGroup;
67
68
    /**
69
     * @ORM\OneToMany(
70
     *     targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceRight",
71
     *     mappedBy="resourceLink", cascade={"persist", "remove"}, orphanRemoval=true
72
     * )
73
     */
74
    protected $resourceRight;
75
76
    /**
77
     * @var int
78
     *
79
     * @ORM\Column(name="visibility", type="integer", nullable=false)
80
     */
81
    protected $visibility;
82
83
    /**
84
     * @ORM\Column(name="start_visibility_at", type="datetime", nullable=true)
85
     */
86
    protected $startVisibilityAt;
87
88
    /**
89
     * @ORM\Column(name="end_visibility_at", type="datetime", nullable=true)
90
     */
91
    protected $endVisibilityAt;
92
93
    /**
94
     * Constructor.
95
     */
96
    public function __construct()
97
    {
98
        $this->resourceRight = new ArrayCollection();
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function __toString()
105
    {
106
        return (string) $this->getId();
107
    }
108
109
    /**
110
     * @return mixed
111
     */
112
    public function getStartVisibilityAt()
113
    {
114
        return $this->startVisibilityAt;
115
    }
116
117
    /**
118
     * @param mixed $startVisibilityAt
119
     *
120
     * @return ResourceLink
121
     */
122
    public function setStartVisibilityAt($startVisibilityAt)
123
    {
124
        $this->startVisibilityAt = $startVisibilityAt;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @return mixed
131
     */
132
    public function getEndVisibilityAt()
133
    {
134
        return $this->endVisibilityAt;
135
    }
136
137
    /**
138
     * @param mixed $endVisibilityAt
139
     *
140
     * @return ResourceLink
141
     */
142
    public function setEndVisibilityAt($endVisibilityAt)
143
    {
144
        $this->endVisibilityAt = $endVisibilityAt;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @param ArrayCollection $rights
151
     *
152
     * @return $this
153
     */
154
    public function setResourceRight($rights)
155
    {
156
        $this->resourceRight = $rights;
157
158
        /*foreach ($rights as $right) {
159
            $this->addResourceRight($right);
160
        }*/
161
162
        return $this;
163
    }
164
165
    /**
166
     * @return $this
167
     */
168
    public function addResourceRight(ResourceRight $right)
169
    {
170
        $right->setResourceLink($this);
171
        $this->resourceRight[] = $right;
172
173
        return $this;
174
    }
175
176
    /**
177
     * @return ArrayCollection|ResourceRight[]
178
     */
179
    public function getResourceRight()
180
    {
181
        return $this->resourceRight;
182
    }
183
184
    /**
185
     * @return int
186
     */
187
    public function getId()
188
    {
189
        return $this->id;
190
    }
191
192
    /**
193
     * @param User $user
194
     *
195
     * @return $this
196
     */
197
    public function setUser(User $user = null)
198
    {
199
        $this->user = $user;
200
201
        return $this;
202
    }
203
204
    /**
205
     * @param Course $course
206
     *
207
     * @return $this
208
     */
209
    public function setCourse(Course $course = null)
210
    {
211
        $this->course = $course;
212
213
        return $this;
214
    }
215
216
    /**
217
     * @param Session $session
218
     *
219
     * @return $this
220
     */
221
    public function setSession(Session $session = null)
222
    {
223
        $this->session = $session;
224
225
        return $this;
226
    }
227
228
    /**
229
     * @return CGroupInfo
230
     */
231
    public function getGroup()
232
    {
233
        return $this->group;
234
    }
235
236
    /**
237
     * @param CGroupInfo $group
238
     *
239
     * @return $this
240
     */
241
    public function setGroup(CGroupInfo $group = null)
242
    {
243
        $this->group = $group;
244
245
        return $this;
246
    }
247
248
    /**
249
     * @return Usergroup
250
     */
251
    public function getUserGroup()
252
    {
253
        return $this->userGroup;
254
    }
255
256
    /**
257
     * @param Usergroup $group
258
     *
259
     * @return $this
260
     */
261
    public function setUserGroup(Usergroup $group = null)
262
    {
263
        $this->userGroup = $group;
264
265
        return $this;
266
    }
267
268
    /**
269
     * Get user.
270
     *
271
     * @return User
272
     */
273
    public function getUser()
274
    {
275
        return $this->user;
276
    }
277
278
    /**
279
     * Get course.
280
     *
281
     * @return Course
282
     */
283
    public function getCourse()
284
    {
285
        return $this->course;
286
    }
287
288
    /**
289
     * Get session.
290
     *
291
     * @return Session
292
     */
293
    public function getSession()
294
    {
295
        return $this->session;
296
    }
297
298
    /**
299
     * @return $this
300
     */
301
    public function setResourceNode(ResourceNode $resourceNode)
302
    {
303
        $this->resourceNode = $resourceNode;
304
305
        return $this;
306
    }
307
308
    /**
309
     * @return ResourceNode
310
     */
311
    public function getResourceNode()
312
    {
313
        return $this->resourceNode;
314
    }
315
316
    /**
317
     * @return int
318
     */
319
    public function getVisibility(): int
320
    {
321
        return $this->visibility;
322
    }
323
324
    /**
325
     * @param int $visibility
326
     *
327
     * @return ResourceLink
328
     */
329
    public function setVisibility(int $visibility): ResourceLink
330
    {
331
        if (!in_array($visibility, self::getVisibilityList())) {
332
            throw new \LogicException('The visibility is not valid');
333
        }
334
335
        $this->visibility = $visibility;
336
337
        return $this;
338
    }
339
340
    /**
341
     * @return bool
342
     */
343
    public function isPublished()
344
    {
345
        return $this->getVisibility() === self::VISIBILITY_PUBLISHED;
346
    }
347
348
    /**
349
     * @return bool
350
     */
351
    public function isPending()
352
    {
353
        return $this->getVisibility() === self::VISIBILITY_PENDING;
354
    }
355
356
    /**
357
     * @return bool
358
     */
359
    public function isDraft()
360
    {
361
        return $this->getVisibility() === self::VISIBILITY_DRAFT;
362
    }
363
364
    /**
365
     * @return $this
366
     */
367
    public function getResource()
368
    {
369
        return $this;
370
    }
371
372
    /**
373
     * @return array
374
     */
375
    public static function getVisibilityList(): array
376
    {
377
        return [
378
            'Draft' => self::VISIBILITY_DRAFT,
379
            'Pending' => self::VISIBILITY_PENDING,
380
            'Published' => self::VISIBILITY_PUBLISHED,
381
            'Deleted' => self::VISIBILITY_DELETED,
382
        ];
383
    }
384
}
385