Completed
Push — master ( 792ce7...e487ad )
by Julito
21:06 queued 10s
created

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