Completed
Push — master ( 0c8670...7c9763 )
by Julito
14:22
created

CTool::getName()   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\CourseBundle\Entity;
5
6
use APY\DataGridBundle\Grid\Mapping as GRID;
7
use Chamilo\CoreBundle\Entity\Course;
8
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
9
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
10
use Chamilo\CoreBundle\Entity\Session;
11
use Chamilo\CoreBundle\Entity\Tool;
12
use Chamilo\CoreBundle\ToolChain;
13
use Doctrine\ORM\Event\LifecycleEventArgs;
14
use Doctrine\ORM\Mapping as ORM;
15
16
/**
17
 * CTool.
18
 *
19
 * @ORM\HasLifecycleCallbacks
20
 * @ORM\Table(
21
 *  name="c_tool",
22
 *  indexes={
23
 *      @ORM\Index(name="course", columns={"c_id"}),
24
 *      @ORM\Index(name="session_id", columns={"session_id"})
25
 *  }
26
 * )
27
 * @ORM\Entity
28
 * @GRID\Source(columns="iid, name, resourceNode.createdAt", filterable=false, groups={"resource"})
29
 */
30
class CTool extends AbstractResource implements ResourceInterface
31
{
32
    /**
33
     * @var int
34
     *
35
     * @ORM\Column(name="iid", type="integer")
36
     * @ORM\Id
37
     * @ORM\GeneratedValue
38
     */
39
    protected $iid;
40
41
    /**
42
     * @var int
43
     *
44
     * @ORM\Column(name="id", type="integer", nullable=true)
45
     */
46
    protected $id;
47
48
    /**
49
     * @var string
50
     *
51
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
52
     */
53
    protected $name;
54
55
    /**
56
     * @var bool
57
     *
58
     * @ORM\Column(name="visibility", type="boolean", nullable=true)
59
     */
60
    protected $visibility;
61
62
    /**
63
     * @var string
64
     *
65
     * @ORM\Column(name="category", type="string", length=20, nullable=false, options={"default" = "authoring"})
66
     */
67
    protected $category;
68
69
    /**
70
     * @var Course
71
     *
72
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="tools")
73
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false)
74
     */
75
    protected $course;
76
77
    /**
78
     * @var Session
79
     *
80
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session")
81
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
82
     */
83
    protected $session;
84
85
    /**
86
     * @var Tool
87
     *
88
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool")
89
     * @ORM\JoinColumn(name="tool_id", referencedColumnName="id", nullable=false)
90
     */
91
    protected $tool;
92
93
    /**
94
     * Constructor.
95
     */
96
    public function __construct()
97
    {
98
        // Default values
99
        $this->id = 0;
100
    }
101
102
    public function getName(): string
103
    {
104
        return $this->name;
105
    }
106
107
    /**
108
     * @param string $name
109
     *
110
     * @return CTool
111
     */
112
    public function setName(string $name): CTool
113
    {
114
        $this->name = $name;
115
116
        return $this;
117
    }
118
119
    /**
120
     * @return int
121
     */
122
    public function getIid()
123
    {
124
        return $this->iid;
125
    }
126
127
    /**
128
     * @param int $iid
129
     *
130
     * @return CTool
131
     */
132
    public function setIid($iid)
133
    {
134
        $this->iid = $iid;
135
136
        return $this;
137
    }
138
139
    /**
140
     * @return $this
141
     */
142
    public function setCourse(Course $course)
143
    {
144
        $this->course = $course;
145
146
        return $this;
147
    }
148
149
    public function getCourse(): Course
150
    {
151
        return $this->course;
152
    }
153
154
    /**
155
     * @return Session
156
     */
157
    public function getSession(): ?Session
158
    {
159
        return $this->session;
160
    }
161
162
    /**
163
     * @param Session $session
164
     */
165
    public function setSession(Session $session = null): CTool
166
    {
167
        $this->session = $session;
168
169
        return $this;
170
    }
171
172
    /**
173
     * Set visibility.
174
     *
175
     * @param bool $visibility
176
     *
177
     * @return CTool
178
     */
179
    public function setVisibility($visibility)
180
    {
181
        $this->visibility = $visibility;
182
183
        return $this;
184
    }
185
186
    /**
187
     * Get visibility.
188
     *
189
     * @return bool
190
     */
191
    public function getVisibility()
192
    {
193
        return $this->visibility;
194
    }
195
196
    /**
197
     * Set category.
198
     *
199
     * @param string $category
200
     *
201
     * @return CTool
202
     */
203
    public function setCategory($category)
204
    {
205
        $this->category = $category;
206
207
        return $this;
208
    }
209
210
    /**
211
     * Get category.
212
     *
213
     * @return string
214
     */
215
    public function getCategory()
216
    {
217
        return $this->category;
218
    }
219
220
    /**
221
     * Set id.
222
     *
223
     * @param int $id
224
     *
225
     * @return CTool
226
     */
227
    public function setId($id)
228
    {
229
        $this->id = $id;
230
231
        return $this;
232
    }
233
234
    /**
235
     * Get id.
236
     *
237
     * @return int
238
     */
239
    public function getId()
240
    {
241
        return $this->id;
242
    }
243
244
    public function getTool(): Tool
245
    {
246
        return $this->tool;
247
    }
248
249
    public function setTool(Tool $tool): CTool
250
    {
251
        $this->tool = $tool;
252
253
        return $this;
254
    }
255
256
    /**
257
     * @ORM\PostPersist()
258
     */
259
    public function postPersist(LifecycleEventArgs $args)
260
    {
261
        // Update id with iid value
262
        $em = $args->getEntityManager();
263
        $this->setId($this->iid);
264
        $em->persist($this);
265
        $em->flush($this);
266
    }
267
268
    /**
269
     * Resource identifier.
270
     */
271
    public function getResourceIdentifier(): int
272
    {
273
        return $this->iid;
274
    }
275
276
    public function getResourceName(): string
277
    {
278
        return (string) $this->getName();
279
    }
280
281
    public function __toString(): string
282
    {
283
        return (string) $this->getName();
284
    }
285
}
286