Passed
Push — master ( 6d015e...372bf3 )
by Julito
08:43
created

CStudentPublication::getFileTypes()   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
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\AbstractResource;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Chamilo\CoreBundle\Entity\ResourceNode;
12
use Chamilo\CoreBundle\Entity\User;
13
use DateTime;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\ORM\Mapping as ORM;
17
use Symfony\Component\Validator\Constraints as Assert;
18
19
/**
20
 * CStudentPublication.
21
 *
22
 * @ORM\Table(
23
 *     name="c_student_publication",
24
 *     indexes={
25
 *     }
26
 * )
27
 * @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CStudentPublicationRepository")
28
 */
29
class CStudentPublication extends AbstractResource implements ResourceInterface
30
{
31
    /**
32
     * @ORM\Column(name="iid", type="integer")
33
     * @ORM\Id
34
     * @ORM\GeneratedValue
35
     */
36
    protected int $iid;
37
38
    /**
39
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
40
     */
41
    #[Assert\NotBlank]
42
    protected string $title;
43
44
    /**
45
     * @ORM\Column(name="description", type="text", nullable=true)
46
     */
47
    protected ?string $description;
48
49
    /**
50
     * @ORM\Column(name="author", type="string", length=255, nullable=true)
51
     */
52
    protected ?string $author = null;
53
54
    /**
55
     * @ORM\Column(name="active", type="integer", nullable=true)
56
     */
57
    protected ?int $active = null;
58
59
    /**
60
     * @ORM\Column(name="accepted", type="boolean", nullable=true)
61
     */
62
    protected ?bool $accepted = null;
63
64
    /**
65
     * @ORM\Column(name="post_group_id", type="integer", nullable=false)
66
     */
67
    protected int $postGroupId;
68
69
    /**
70
     * @ORM\Column(name="sent_date", type="datetime", nullable=true)
71
     */
72
    protected ?DateTime $sentDate;
73
74
    /**
75
     * @ORM\Column(name="filetype", type="string", length=10, nullable=false)
76
     */
77
    #[Assert\NotBlank]
78
    #[Assert\Choice(callback: 'getFileTypes')]
79
    protected string $filetype;
80
81
    /**
82
     * @ORM\Column(name="has_properties", type="integer", nullable=false)
83
     */
84
    protected int $hasProperties;
85
86
    /**
87
     * @ORM\Column(name="view_properties", type="boolean", nullable=true)
88
     */
89
    protected ?bool $viewProperties = null;
90
91
    /**
92
     * @ORM\Column(name="qualification", type="float", precision=6, scale=2, nullable=false)
93
     */
94
    protected float $qualification;
95
96
    /**
97
     * @ORM\Column(name="date_of_qualification", type="datetime", nullable=true)
98
     */
99
    protected ?DateTime $dateOfQualification = null;
100
101
    /**
102
     * @var Collection|CStudentPublication[]
103
     * @ORM\OneToMany(targetEntity="CStudentPublication", mappedBy="publicationParent")
104
     */
105
    protected Collection $children;
106
107
    /**
108
     * @var Collection|CStudentPublicationComment[]
109
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublicationComment", mappedBy="publication")
110
     */
111
    protected Collection $comments;
112
113
    /**
114
     * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublication", inversedBy="children")
115
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="iid")
116
     */
117
    protected ?CStudentPublication $publicationParent;
118
119
    /**
120
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
121
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
122
     */
123
    protected User $user;
124
125
    /**
126
     * @ORM\OneToOne(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublicationAssignment", mappedBy="publication")
127
     */
128
    protected ?CStudentPublicationAssignment $assignment = null;
129
130
    /**
131
     * @ORM\Column(name="qualificator_id", type="integer", nullable=false)
132
     */
133
    protected int $qualificatorId;
134
135
    /**
136
     * @ORM\Column(name="weight", type="float", precision=6, scale=2, nullable=false)
137
     */
138
    #[Assert\NotBlank]
139
    protected float $weight;
140
141
    /**
142
     * @ORM\Column(name="allow_text_assignment", type="integer", nullable=false)
143
     */
144
    protected int $allowTextAssignment;
145
146
    /**
147
     * @ORM\Column(name="contains_file", type="integer", nullable=false)
148
     */
149
    protected int $containsFile;
150
151
    /**
152
     * @ORM\Column(name="document_id", type="integer", nullable=false)
153
     */
154
    protected int $documentId;
155
156
    /**
157
     * @ORM\Column(name="filesize", type="integer", nullable=true)
158
     */
159
    protected ?int $fileSize = null;
160
161
    public function __construct()
162
    {
163
        $this->description = '';
164
        $this->documentId = 0;
165
        $this->hasProperties = 0;
166
        $this->containsFile = 0;
167
        $this->publicationParent = null;
168
        $this->qualificatorId = 0;
169
        $this->qualification = 0;
170
        $this->assignment = null;
171
        $this->postGroupId = 0;
172
        $this->allowTextAssignment = 0;
173
        $this->filetype = 'folder';
174
        $this->sentDate = new DateTime();
175
        $this->children = new ArrayCollection();
176
        $this->comments = new ArrayCollection();
177
    }
178
179
    public function __toString(): string
180
    {
181
        return $this->getTitle();
182
    }
183
184
    public function getFileTypes(): array
185
    {
186
        return ['file', 'folder'];
187
    }
188
189
    /**
190
     * Get iid.
191
     *
192
     * @return int
193
     */
194
    public function getIid()
195
    {
196
        return $this->iid;
197
    }
198
199
    public function setTitle(string $title): self
200
    {
201
        $this->title = $title;
202
203
        return $this;
204
    }
205
206
    /**
207
     * Get title.
208
     *
209
     * @return string
210
     */
211
    public function getTitle()
212
    {
213
        return $this->title;
214
    }
215
216
    public function setDescription(string $description): self
217
    {
218
        $this->description = $description;
219
220
        return $this;
221
    }
222
223
    public function getDescription(): ?string
224
    {
225
        return $this->description;
226
    }
227
228
    public function setAuthor(string $author): self
229
    {
230
        $this->author = $author;
231
232
        return $this;
233
    }
234
235
    /**
236
     * Get author.
237
     *
238
     * @return string
239
     */
240
    public function getAuthor()
241
    {
242
        return $this->author;
243
    }
244
245
    public function setActive(int $active): self
246
    {
247
        $this->active = $active;
248
249
        return $this;
250
    }
251
252
    /**
253
     * Get active.
254
     *
255
     * @return int
256
     */
257
    public function getActive()
258
    {
259
        return $this->active;
260
    }
261
262
    public function setAccepted(bool $accepted): self
263
    {
264
        $this->accepted = $accepted;
265
266
        return $this;
267
    }
268
269
    /**
270
     * Get accepted.
271
     *
272
     * @return bool
273
     */
274
    public function getAccepted()
275
    {
276
        return $this->accepted;
277
    }
278
279
    /**
280
     * Set postGroupId.
281
     *
282
     * @return CStudentPublication
283
     */
284
    public function setPostGroupId(int $postGroupId)
285
    {
286
        $this->postGroupId = $postGroupId;
287
288
        return $this;
289
    }
290
291
    /**
292
     * Get postGroupId.
293
     *
294
     * @return int
295
     */
296
    public function getPostGroupId()
297
    {
298
        return $this->postGroupId;
299
    }
300
301
    public function setSentDate(DateTime $sentDate): self
302
    {
303
        $this->sentDate = $sentDate;
304
305
        return $this;
306
    }
307
308
    /**
309
     * Get sentDate.
310
     *
311
     * @return DateTime
312
     */
313
    public function getSentDate()
314
    {
315
        return $this->sentDate;
316
    }
317
318
    public function setFiletype(string $filetype): self
319
    {
320
        $this->filetype = $filetype;
321
322
        return $this;
323
    }
324
325
    /**
326
     * Get filetype.
327
     *
328
     * @return string
329
     */
330
    public function getFiletype()
331
    {
332
        return $this->filetype;
333
    }
334
335
    public function setHasProperties(int $hasProperties): self
336
    {
337
        $this->hasProperties = $hasProperties;
338
339
        return $this;
340
    }
341
342
    /**
343
     * Get hasProperties.
344
     *
345
     * @return int
346
     */
347
    public function getHasProperties()
348
    {
349
        return $this->hasProperties;
350
    }
351
352
    public function setViewProperties(bool $viewProperties): self
353
    {
354
        $this->viewProperties = $viewProperties;
355
356
        return $this;
357
    }
358
359
    /**
360
     * Get viewProperties.
361
     *
362
     * @return bool
363
     */
364
    public function getViewProperties()
365
    {
366
        return $this->viewProperties;
367
    }
368
369
    public function setQualification(float $qualification): self
370
    {
371
        $this->qualification = $qualification;
372
373
        return $this;
374
    }
375
376
    /**
377
     * Get qualification.
378
     *
379
     * @return float
380
     */
381
    public function getQualification()
382
    {
383
        return $this->qualification;
384
    }
385
386
    public function setDateOfQualification(DateTime $dateOfQualification): self
387
    {
388
        $this->dateOfQualification = $dateOfQualification;
389
390
        return $this;
391
    }
392
393
    /**
394
     * Get dateOfQualification.
395
     *
396
     * @return DateTime
397
     */
398
    public function getDateOfQualification()
399
    {
400
        return $this->dateOfQualification;
401
    }
402
403
    /**
404
     * Set qualificatorId.
405
     *
406
     * @return CStudentPublication
407
     */
408
    public function setQualificatorId(int $qualificatorId)
409
    {
410
        $this->qualificatorId = $qualificatorId;
411
412
        return $this;
413
    }
414
415
    public function getQualificatorId(): int
416
    {
417
        return $this->qualificatorId;
418
    }
419
420
    public function setWeight(float $weight): self
421
    {
422
        $this->weight = $weight;
423
424
        return $this;
425
    }
426
427
    /**
428
     * Get weight.
429
     *
430
     * @return float
431
     */
432
    public function getWeight()
433
    {
434
        return $this->weight;
435
    }
436
437
    public function setAllowTextAssignment(int $allowTextAssignment): self
438
    {
439
        $this->allowTextAssignment = $allowTextAssignment;
440
441
        return $this;
442
    }
443
444
    /**
445
     * Get allowTextAssignment.
446
     *
447
     * @return int
448
     */
449
    public function getAllowTextAssignment()
450
    {
451
        return $this->allowTextAssignment;
452
    }
453
454
    public function setContainsFile(int $containsFile): self
455
    {
456
        $this->containsFile = $containsFile;
457
458
        return $this;
459
    }
460
461
    /**
462
     * Get containsFile.
463
     *
464
     * @return int
465
     */
466
    public function getContainsFile()
467
    {
468
        return $this->containsFile;
469
    }
470
471
    /**
472
     * @return int
473
     */
474
    public function getDocumentId()
475
    {
476
        return $this->documentId;
477
    }
478
479
    public function setDocumentId(int $documentId): self
480
    {
481
        $this->documentId = $documentId;
482
483
        return $this;
484
    }
485
486
    public function getFileSize(): int
487
    {
488
        return $this->fileSize;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->fileSize could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
489
    }
490
491
    public function setFileSize(int $fileSize): self
492
    {
493
        $this->fileSize = $fileSize;
494
495
        return $this;
496
    }
497
498
    public function getCorrection(): ?ResourceNode
499
    {
500
        if ($this->hasResourceNode()) {
501
            $children = $this->getResourceNode()->getChildren();
502
            foreach ($children as $child) {
503
                $name = $child->getResourceType()->getName();
504
                if ('student_publications_corrections' === $name) {
505
                    return $child;
506
                }
507
            }
508
        }
509
510
        return null;
511
    }
512
513
    public function getAssignment(): ?CStudentPublicationAssignment
514
    {
515
        return $this->assignment;
516
    }
517
518
    public function setAssignment(?CStudentPublicationAssignment $assignment): self
519
    {
520
        $this->assignment = $assignment;
521
522
        return $this;
523
    }
524
525
    /**
526
     * @return CStudentPublication[]|Collection
527
     */
528
    public function getChildren()
529
    {
530
        return $this->children;
531
    }
532
533
    public function setChildren(Collection $children): self
534
    {
535
        $this->children = $children;
536
537
        return $this;
538
    }
539
540
    public function getPublicationParent(): ?self
541
    {
542
        return $this->publicationParent;
543
    }
544
545
    public function setPublicationParent(?self $publicationParent): self
546
    {
547
        $this->publicationParent = $publicationParent;
548
549
        return $this;
550
    }
551
552
    public function getUser(): User
553
    {
554
        return $this->user;
555
    }
556
557
    public function setUser(User $user): self
558
    {
559
        $this->user = $user;
560
561
        return $this;
562
    }
563
564
    /**
565
     * @return CStudentPublicationComment[]|Collection
566
     */
567
    public function getComments()
568
    {
569
        return $this->comments;
570
    }
571
572
    /**
573
     * @param CStudentPublicationComment[]|Collection $comments
574
     */
575
    public function setComments(Collection $comments): self
576
    {
577
        $this->comments = $comments;
578
579
        return $this;
580
    }
581
582
    public function getResourceIdentifier(): int
583
    {
584
        return $this->getIid();
585
    }
586
587
    public function getResourceName(): string
588
    {
589
        return $this->getTitle();
590
    }
591
592
    public function setResourceName(string $name): self
593
    {
594
        return $this->setTitle($name);
595
    }
596
}
597