Passed
Push — master ( ec2ac4...5107be )
by Julito
09:28 queued 10s
created

CDocument::getCourse()   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 Doctrine\ORM\Event\LifecycleEventArgs;
12
use Doctrine\ORM\Mapping as ORM;
13
14
/**
15
 * CDocument.
16
 *
17
 * @ORM\Table(
18
 *  name="c_document",
19
 *  indexes={
20
 *      @ORM\Index(name="course", columns={"c_id"})
21
 *  }
22
 * )
23
 * @GRID\Source(columns="iid, id, title, filetype", filterable=false)
24
 *
25
 * @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CDocumentRepository")
26
 */
27
class CDocument extends AbstractResource implements ResourceInterface
28
{
29
    /**
30
     * @var int
31
     *
32
     * @ORM\Column(name="iid", type="integer")
33
     * @ORM\Id
34
     * @ORM\GeneratedValue
35
     */
36
    protected $iid;
37
38
    /**
39
     * @var int
40
     *
41
     * @ORM\Column(name="id", type="integer", nullable=true)
42
     */
43
    protected $id;
44
45
    /**
46
     * @var string
47
     *
48
     * @ORM\Column(name="path", type="string", length=255, nullable=false)
49
     */
50
    protected $path;
51
52
    /**
53
     * @var string
54
     *
55
     * @ORM\Column(name="comment", type="text", nullable=true)
56
     */
57
    protected $comment;
58
59
    /**
60
     * @var string
61
     *
62
     * @ORM\Column(name="title", type="string", length=255, nullable=true)
63
     */
64
    protected $title;
65
66
    /**
67
     * @var string
68
     *
69
     * @ORM\Column(name="filetype", type="string", length=10, nullable=false)
70
     */
71
    protected $filetype;
72
73
    /**
74
     * @var int
75
     *
76
     * @ORM\Column(name="size", type="integer", nullable=false)
77
     */
78
    protected $size;
79
80
    /**
81
     * @var bool
82
     *
83
     * @ORM\Column(name="readonly", type="boolean", nullable=false)
84
     */
85
    protected $readonly;
86
87
    /**
88
     * @var Course|null
89
     *
90
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", cascade={"persist"})
91
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id")
92
     */
93
    protected $course;
94
95
    /**
96
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", cascade={"persist"})
97
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id")
98
     */
99
    protected $session;
100
101
    /**
102
     * CDocument constructor.
103
     */
104
    public function __construct()
105
    {
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function __toString()
112
    {
113
        return (string) $this->title;
114
    }
115
116
    public function __get($a)
117
    {
118
    }
119
120
    /**
121
     * Set path.
122
     *
123
     * @param string $path
124
     *
125
     * @return CDocument
126
     */
127
    public function setPath($path)
128
    {
129
        $this->path = $path;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Get path.
136
     *
137
     * @return string
138
     */
139
    public function getPath()
140
    {
141
        return $this->path;
142
    }
143
144
    /**
145
     * Set comment.
146
     *
147
     * @param string $comment
148
     *
149
     * @return CDocument
150
     */
151
    public function setComment($comment)
152
    {
153
        $this->comment = $comment;
154
155
        return $this;
156
    }
157
158
    /**
159
     * Get comment.
160
     *
161
     * @return string
162
     */
163
    public function getComment()
164
    {
165
        return $this->comment;
166
    }
167
168
    /**
169
     * Set title.
170
     *
171
     * @param string $title
172
     *
173
     * @return CDocument
174
     */
175
    public function setTitle($title)
176
    {
177
        $this->title = $title;
178
179
        return $this;
180
    }
181
182
    /**
183
     * Get title.
184
     *
185
     * @return string
186
     */
187
    public function getTitle()
188
    {
189
        return $this->title;
190
    }
191
192
    /**
193
     * Set filetype.
194
     *
195
     * @param string $filetype
196
     *
197
     * @return CDocument
198
     */
199
    public function setFiletype($filetype)
200
    {
201
        $this->filetype = $filetype;
202
203
        return $this;
204
    }
205
206
    /**
207
     * Get filetype.
208
     *
209
     * @return string
210
     */
211
    public function getFiletype()
212
    {
213
        return $this->filetype;
214
    }
215
216
    /**
217
     * Set size.
218
     *
219
     * @param int $size
220
     *
221
     * @return CDocument
222
     */
223
    public function setSize($size)
224
    {
225
        $this->size = $size;
226
227
        return $this;
228
    }
229
230
    /**
231
     * Get size.
232
     *
233
     * @return int
234
     */
235
    public function getSize()
236
    {
237
        return $this->size;
238
    }
239
240
    /**
241
     * Set readonly.
242
     *
243
     * @param bool $readonly
244
     *
245
     * @return CDocument
246
     */
247
    public function setReadonly($readonly)
248
    {
249
        $this->readonly = $readonly;
250
251
        return $this;
252
    }
253
254
    /**
255
     * Get readonly.
256
     *
257
     * @return bool
258
     */
259
    public function getReadonly()
260
    {
261
        return $this->readonly;
262
    }
263
264
    /**
265
     * Set id.
266
     *
267
     * @param int $id
268
     *
269
     * @return CDocument
270
     */
271
    public function setId($id)
272
    {
273
        $this->id = $id;
274
275
        return $this;
276
    }
277
278
    /**
279
     * Get id.
280
     *
281
     * @return int
282
     */
283
    public function getId()
284
    {
285
        return $this->id;
286
    }
287
288
    /**
289
     * @return Course
290
     */
291
    public function getCourse(): Course
292
    {
293
        return $this->course;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->course could return the type null which is incompatible with the type-hinted return Chamilo\CoreBundle\Entity\Course. Consider adding an additional type-check to rule them out.
Loading history...
294
    }
295
296
    /**
297
     * @param Course $course
298
     *
299
     * @return CDocument
300
     */
301
    public function setCourse($course)
302
    {
303
        $this->course = $course;
304
305
        return $this;
306
    }
307
308
    /**
309
     * @return int
310
     */
311
    public function getIid()
312
    {
313
        return $this->iid;
314
    }
315
316
    /**
317
     * @return Session
318
     */
319
    public function getSession()
320
    {
321
        return $this->session;
322
    }
323
324
    /**
325
     * @param Session $session
326
     *
327
     * @return CDocument
328
     */
329
    public function setSession($session)
330
    {
331
        $this->session = $session;
332
333
        return $this;
334
    }
335
336
    /**
337
     * @ORM\PostPersist()
338
     *
339
     * @param LifecycleEventArgs $args
340
     */
341
    public function postPersist(LifecycleEventArgs $args)
342
    {
343
        // Update id with iid value
344
        $em = $args->getEntityManager();
345
        $this->setId($this->iid);
346
        $em->persist($this);
347
        $em->flush($this);
348
    }
349
350
    // Resource classes
351
352
    public function getResourceIdentifier(): int
353
    {
354
        return $this->getIid();
355
    }
356
357
    public function getResourceName(): string
358
    {
359
        return $this->getTitle();
360
    }
361
362
    public function getToolName(): string
363
    {
364
        return 'document';
365
    }
366
}
367