Passed
Push — master ( 16202d...83c82e )
by Julito
08:35
created

ResourceLink::setPublic()   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 1
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="links")
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\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceRight", mappedBy="resourceLink", cascade={"persist", "remove"})
71
     */
72
    protected $resourceRight;
73
74
    /**
75
     * @var bool
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
    /**
177
     * @return int
178
     */
179
    public function getId()
180
    {
181
        return $this->id;
182
    }
183
184
    /**
185
     * @param User $user
186
     *
187
     * @return $this
188
     */
189
    public function setUser(User $user = null)
190
    {
191
        $this->user = $user;
192
193
        return $this;
194
    }
195
196
    /**
197
     * @param Course $course
198
     *
199
     * @return $this
200
     */
201
    public function setCourse(Course $course = null)
202
    {
203
        $this->course = $course;
204
205
        return $this;
206
    }
207
208
    /**
209
     * @param Session $session
210
     *
211
     * @return $this
212
     */
213
    public function setSession(Session $session = null)
214
    {
215
        $this->session = $session;
216
217
        return $this;
218
    }
219
220
    /**
221
     * @return CGroupInfo
222
     */
223
    public function getGroup()
224
    {
225
        return $this->group;
226
    }
227
228
    /**
229
     * @param CGroupInfo $group
230
     *
231
     * @return $this
232
     */
233
    public function setGroup(CGroupInfo $group = null)
234
    {
235
        $this->group = $group;
236
237
        return $this;
238
    }
239
240
    /**
241
     * @return Usergroup
242
     */
243
    public function getUserGroup()
244
    {
245
        return $this->userGroup;
246
    }
247
248
    /**
249
     * @param Usergroup $group
250
     *
251
     * @return $this
252
     */
253
    public function setUserGroup(Usergroup $group = null)
254
    {
255
        $this->userGroup = $group;
256
257
        return $this;
258
    }
259
260
    /**
261
     * Get user.
262
     *
263
     * @return User
264
     */
265
    public function getUser()
266
    {
267
        return $this->user;
268
    }
269
270
    /**
271
     * Get course.
272
     *
273
     * @return Course
274
     */
275
    public function getCourse()
276
    {
277
        return $this->course;
278
    }
279
280
    /**
281
     * Get session.
282
     *
283
     * @return Session
284
     */
285
    public function getSession()
286
    {
287
        return $this->session;
288
    }
289
290
    /**
291
     * @param ResourceNode $resourceNode
292
     *
293
     * @return $this
294
     */
295
    public function setResourceNode(ResourceNode $resourceNode)
296
    {
297
        $this->resourceNode = $resourceNode;
298
299
        return $this;
300
    }
301
302
    /**
303
     * @return ResourceNode
304
     */
305
    public function getResourceNode()
306
    {
307
        return $this->resourceNode;
308
    }
309
310
    /**
311
     * @return $this
312
     */
313
    public function getResource()
314
    {
315
        return $this;
316
    }
317
}
318