Passed
Push — master ( e174a9...e6c349 )
by Julito
10:39
created

ResourceLink::addResourceRight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
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(
71
     *     targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceRight",
72
     *     mappedBy="resourceLink", cascade={"persist", "remove"}, orphanRemoval=true
73
     * )
74
     */
75
    protected $resourceRight;
76
77
    /**
78
     * @var int
79
     *
80
     * @ORM\Column(name="visibility", type="integer", nullable=false)
81
     */
82
    protected $visibility;
83
84
    /**
85
     * @ORM\Column(name="start_visibility_at", type="datetime", nullable=true)
86
     */
87
    protected $startVisibilityAt;
88
89
    /**
90
     * @ORM\Column(name="end_visibility_at", type="datetime", nullable=true)
91
     */
92
    protected $endVisibilityAt;
93
94
    /**
95
     * Constructor.
96
     */
97
    public function __construct()
98
    {
99
        $this->resourceRight = new ArrayCollection();
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function __toString()
106
    {
107
        return (string) $this->getId();
108
    }
109
110
    /**
111
     * @return mixed
112
     */
113
    public function getStartVisibilityAt()
114
    {
115
        return $this->startVisibilityAt;
116
    }
117
118
    /**
119
     * @param mixed $startVisibilityAt
120
     *
121
     * @return ResourceLink
122
     */
123
    public function setStartVisibilityAt($startVisibilityAt)
124
    {
125
        $this->startVisibilityAt = $startVisibilityAt;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @return mixed
132
     */
133
    public function getEndVisibilityAt()
134
    {
135
        return $this->endVisibilityAt;
136
    }
137
138
    /**
139
     * @param mixed $endVisibilityAt
140
     *
141
     * @return ResourceLink
142
     */
143
    public function setEndVisibilityAt($endVisibilityAt)
144
    {
145
        $this->endVisibilityAt = $endVisibilityAt;
146
147
        return $this;
148
    }
149
150
    /**
151
     * @param ArrayCollection $rights
152
     *
153
     * @return $this
154
     */
155
    public function setResourceRight($rights)
156
    {
157
        $this->resourceRight = $rights;
158
159
        /*foreach ($rights as $right) {
160
            $this->addResourceRight($right);
161
        }*/
162
163
        return $this;
164
    }
165
166
    /**
167
     * @param ResourceRight $right
168
     *
169
     * @return $this
170
     */
171
    public function addResourceRight(ResourceRight $right)
172
    {
173
        $right->setResourceLink($this);
174
        $this->resourceRight[] = $right;
175
176
        return $this;
177
    }
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
     * @param ResourceNode $resourceNode
300
     *
301
     * @return $this
302
     */
303
    public function setResourceNode(ResourceNode $resourceNode)
304
    {
305
        $this->resourceNode = $resourceNode;
306
307
        return $this;
308
    }
309
310
    /**
311
     * @return ResourceNode
312
     */
313
    public function getResourceNode()
314
    {
315
        return $this->resourceNode;
316
    }
317
318
    /**
319
     * @return int
320
     */
321
    public function getVisibility(): int
322
    {
323
        return $this->visibility;
324
    }
325
326
    /**
327
     * @param int $visibility
328
     *
329
     * @return ResourceLink
330
     */
331
    public function setVisibility(int $visibility): ResourceLink
332
    {
333
        $this->visibility = $visibility;
334
335
        return $this;
336
    }
337
338
    /**
339
     * @return $this
340
     */
341
    public function getResource()
342
    {
343
        return $this;
344
    }
345
346
    /**
347
     * @return array
348
     */
349
    public static function getVisibilityList(): array
350
    {
351
        return [
352
            'Draft' => self::VISIBILITY_DRAFT,
353
            'Pending' => self::VISIBILITY_PENDING,
354
            'Published' => self::VISIBILITY_PUBLISHED,
355
            'Deleted' => self::VISIBILITY_DELETED,
356
        ];
357
    }
358
}
359