Completed
Push — master ( d28136...3a5b5f )
by Julito
16:58
created

CDocument::getResourceFieldName()   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 Course
96
     *
97
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", cascade={"persist"})
98
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", onDelete="CASCADE" )
99
     */
100
    protected $course;
101
102
    /**
103
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", cascade={"persist"})
104
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", onDelete="CASCADE" )
105
     */
106
    protected $session;
107
108
    /**
109
     * CDocument constructor.
110
     */
111
    public function __construct()
112
    {
113
        $this->readonly = false;
114
        $this->size = 0;
115
        $this->id = 0;
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function __toString(): string
122
    {
123
        return $this->getTitle();
124
    }
125
126
    /**
127
     * Set path.
128
     *
129
     * @param string $path
130
     *
131
     * @return CDocument
132
     */
133
    public function setPath($path)
134
    {
135
        $this->path = $path;
136
137
        return $this;
138
    }
139
140
    /**
141
     * Get path.
142
     *
143
     * @return string
144
     */
145
    public function getPath()
146
    {
147
        return $this->path;
148
    }
149
150
    /**
151
     * Set comment.
152
     *
153
     * @param string $comment
154
     *
155
     * @return CDocument
156
     */
157
    public function setComment($comment)
158
    {
159
        $this->comment = $comment;
160
161
        return $this;
162
    }
163
164
    /**
165
     * Get comment.
166
     *
167
     * @return string
168
     */
169
    public function getComment()
170
    {
171
        return $this->comment;
172
    }
173
174
    /**
175
     * Set title.
176
     *
177
     * @param string $title
178
     *
179
     * @return CDocument
180
     */
181
    public function setTitle($title)
182
    {
183
        $this->title = $title;
184
185
        return $this;
186
    }
187
188
    /**
189
     * Get title.
190
     *
191
     * @return string
192
     */
193
    public function getTitle()
194
    {
195
        return (string) $this->title;
196
    }
197
198
    /**
199
     * Set filetype.
200
     *
201
     * @param string $filetype
202
     *
203
     * @return CDocument
204
     */
205
    public function setFiletype($filetype)
206
    {
207
        $this->filetype = $filetype;
208
209
        return $this;
210
    }
211
212
    /**
213
     * Get filetype.
214
     *
215
     * @return string
216
     */
217
    public function getFiletype()
218
    {
219
        return $this->filetype;
220
    }
221
222
    /**
223
     * Set size.
224
     *
225
     * @return CDocument
226
     */
227
    public function setSize(int $size)
228
    {
229
        $this->size = $size ?: 0;
230
231
        return $this;
232
    }
233
234
    /**
235
     * Get size.
236
     *
237
     * @return int
238
     */
239
    public function getSize()
240
    {
241
        return $this->size;
242
    }
243
244
    /**
245
     * Set readonly.
246
     *
247
     * @param bool $readonly
248
     *
249
     * @return CDocument
250
     */
251
    public function setReadonly($readonly)
252
    {
253
        $this->readonly = $readonly;
254
255
        return $this;
256
    }
257
258
    /**
259
     * Get readonly.
260
     *
261
     * @return bool
262
     */
263
    public function getReadonly()
264
    {
265
        return $this->readonly;
266
    }
267
268
    /**
269
     * Set id.
270
     *
271
     * @param int $id
272
     *
273
     * @return CDocument
274
     */
275
    public function setId($id)
276
    {
277
        $this->id = $id;
278
279
        return $this;
280
    }
281
282
    /**
283
     * Get id.
284
     *
285
     * @return int
286
     */
287
    public function getId()
288
    {
289
        return $this->id;
290
    }
291
292
    public function getCourse(): Course
293
    {
294
        return $this->course;
295
    }
296
297
    /**
298
     * @param Course $course
299
     *
300
     * @return CDocument
301
     */
302
    public function setCourse($course)
303
    {
304
        $this->course = $course;
305
306
        return $this;
307
    }
308
309
    /**
310
     * @return int
311
     */
312
    public function getIid()
313
    {
314
        return $this->iid;
315
    }
316
317
    /**
318
     * @return Session
319
     */
320
    public function getSession()
321
    {
322
        return $this->session;
323
    }
324
325
    /**
326
     * @param Session $session
327
     *
328
     * @return CDocument
329
     */
330
    public function setSession($session)
331
    {
332
        $this->session = $session;
333
334
        return $this;
335
    }
336
337
338
    public function postPersist(LifecycleEventArgs $args)
339
    {
340
        // Update id with iid value
341
        $em = $args->getEntityManager();
342
        $this->setId($this->getIid());
343
        $em->persist($this);
344
        $em->flush();
345
    }
346
347
    /**
348
     * Resource identifier.
349
     */
350
    public function getResourceIdentifier(): int
351
    {
352
        return $this->getIid();
353
    }
354
355
    public function getResourceName(): string
356
    {
357
        return $this->getTitle();
358
    }
359
}
360