Passed
Push — master ( 3087c9...f5d059 )
by Julito
11:15
created

ResourceLink::getResourceRight()   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 Alchemy\Zippy\Adapter\Resource\ResourceInterface;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Chamilo\CoreBundle\Entit...ource\ResourceInterface. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use Chamilo\CoreBundle\Entity\Course;
8
use Chamilo\CoreBundle\Entity\Session;
9
use Chamilo\CoreBundle\Entity\Usergroup;
10
use Chamilo\CourseBundle\Entity\CGroupInfo;
11
use Chamilo\UserBundle\Entity\User;
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\ORM\Mapping as ORM;
14
15
/**
16
 * @ORM\Entity
17
 * @ORM\Table(name="resource_link")
18
 */
19
class ResourceLink implements ResourceInterface
20
{
21
    public const VISIBILITY_DRAFT = 0;
22
    public const VISIBILITY_PENDING = 1;
23
    public const VISIBILITY_PUBLISHED = 2;
24
    public const VISIBILITY_DELETED = 3;
25
26
    /**
27
     * @ORM\Id
28
     * @ORM\Column(type="integer")
29
     * @ORM\GeneratedValue(strategy="AUTO")
30
     */
31
    protected $id;
32
33
    /**
34
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", inversedBy="resourceLinks")
35
     * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id")
36
     */
37
    protected $resourceNode;
38
39
    /**
40
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session")
41
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
42
     */
43
    protected $session;
44
45
    /**
46
     * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
47
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)
48
     */
49
    protected $user;
50
51
    /**
52
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course")
53
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=true)
54
     */
55
    protected $course;
56
57
    /**
58
     * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CGroupInfo")
59
     * @ORM\JoinColumn(name="group_id", referencedColumnName="iid", nullable=true)
60
     */
61
    protected $group;
62
63
    /**
64
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Usergroup")
65
     * @ORM\JoinColumn(name="usergroup_id", referencedColumnName="id", nullable=true)
66
     */
67
    protected $userGroup;
68
69
    /**
70
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceRight", mappedBy="resourceLink", cascade={"persist", "remove"})
71
     */
72
    protected $resourceRight;
73
74
    /**
75
     * @var int
76
     *
77
     * @ORM\Column(name="visibility", type="integer", nullable=false)
78
     */
79
    protected $visibility;
80
81
    /**
82
     * @ORM\Column(name="start_visibility_at", type="datetime", nullable=true)
83
     */
84
    protected $startVisibilityAt;
85
86
    /**
87
     * @ORM\Column(name="end_visibility_at", type="datetime", nullable=true)
88
     */
89
    protected $endVisibilityAt;
90
91
    /**
92
     * Constructor.
93
     */
94
    public function __construct()
95
    {
96
        $this->resourceRight = new ArrayCollection();
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function __toString()
103
    {
104
        return (string) $this->getId();
105
    }
106
107
    /**
108
     * @return mixed
109
     */
110
    public function getStartVisibilityAt()
111
    {
112
        return $this->startVisibilityAt;
113
    }
114
115
    /**
116
     * @param mixed $startVisibilityAt
117
     *
118
     * @return ResourceLink
119
     */
120
    public function setStartVisibilityAt($startVisibilityAt)
121
    {
122
        $this->startVisibilityAt = $startVisibilityAt;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @return mixed
129
     */
130
    public function getEndVisibilityAt()
131
    {
132
        return $this->endVisibilityAt;
133
    }
134
135
    /**
136
     * @param mixed $endVisibilityAt
137
     *
138
     * @return ResourceLink
139
     */
140
    public function setEndVisibilityAt($endVisibilityAt)
141
    {
142
        $this->endVisibilityAt = $endVisibilityAt;
143
144
        return $this;
145
    }
146
147
    /**
148
     * @param ArrayCollection $rights
149
     *
150
     * @return $this
151
     */
152
    public function setResourceRight(ArrayCollection $rights)
153
    {
154
        $this->resourceRight = new ArrayCollection();
155
156
        foreach ($rights as $right) {
157
            $this->addResourceRight($right);
158
        }
159
160
        return $this;
161
    }
162
163
    /**
164
     * @param ResourceRight $right
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
    public function getResourceRight()
177
    {
178
        return $this->resourceRight;
179
    }
180
181
    /**
182
     * @return int
183
     */
184
    public function getId()
185
    {
186
        return $this->id;
187
    }
188
189
    /**
190
     * @param User $user
191
     *
192
     * @return $this
193
     */
194
    public function setUser(User $user = null)
195
    {
196
        $this->user = $user;
197
198
        return $this;
199
    }
200
201
    /**
202
     * @param Course $course
203
     *
204
     * @return $this
205
     */
206
    public function setCourse(Course $course = null)
207
    {
208
        $this->course = $course;
209
210
        return $this;
211
    }
212
213
    /**
214
     * @param Session $session
215
     *
216
     * @return $this
217
     */
218
    public function setSession(Session $session = null)
219
    {
220
        $this->session = $session;
221
222
        return $this;
223
    }
224
225
    /**
226
     * @return CGroupInfo
227
     */
228
    public function getGroup()
229
    {
230
        return $this->group;
231
    }
232
233
    /**
234
     * @param CGroupInfo $group
235
     *
236
     * @return $this
237
     */
238
    public function setGroup(CGroupInfo $group = null)
239
    {
240
        $this->group = $group;
241
242
        return $this;
243
    }
244
245
    /**
246
     * @return Usergroup
247
     */
248
    public function getUserGroup()
249
    {
250
        return $this->userGroup;
251
    }
252
253
    /**
254
     * @param Usergroup $group
255
     *
256
     * @return $this
257
     */
258
    public function setUserGroup(Usergroup $group = null)
259
    {
260
        $this->userGroup = $group;
261
262
        return $this;
263
    }
264
265
    /**
266
     * Get user.
267
     *
268
     * @return User
269
     */
270
    public function getUser()
271
    {
272
        return $this->user;
273
    }
274
275
    /**
276
     * Get course.
277
     *
278
     * @return Course
279
     */
280
    public function getCourse()
281
    {
282
        return $this->course;
283
    }
284
285
    /**
286
     * Get session.
287
     *
288
     * @return Session
289
     */
290
    public function getSession()
291
    {
292
        return $this->session;
293
    }
294
295
    /**
296
     * @param ResourceNode $resourceNode
297
     *
298
     * @return $this
299
     */
300
    public function setResourceNode(ResourceNode $resourceNode)
301
    {
302
        $this->resourceNode = $resourceNode;
303
304
        return $this;
305
    }
306
307
    /**
308
     * @return ResourceNode
309
     */
310
    public function getResourceNode()
311
    {
312
        return $this->resourceNode;
313
    }
314
315
    /**
316
     * @return int
317
     */
318
    public function getVisibility(): int
319
    {
320
        return $this->visibility;
321
    }
322
323
    /**
324
     * @param int $visibility
325
     *
326
     * @return ResourceLink
327
     */
328
    public function setVisibility(int $visibility): ResourceLink
329
    {
330
        $this->visibility = $visibility;
331
332
        return $this;
333
    }
334
335
    /**
336
     * @return $this
337
     */
338
    public function getResource()
339
    {
340
        return $this;
341
    }
342
}
343