Completed
Push — master ( d9adeb...430d2c )
by
unknown
01:15 queued 37s
created

CSurvey::setChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\AbstractResource;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Chamilo\CourseBundle\Repository\CSurveyRepository;
12
use DateTime;
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Doctrine\ORM\Mapping as ORM;
16
use Gedmo\Mapping\Annotation as Gedmo;
17
use Stringable;
18
use Symfony\Component\Uid\Uuid;
19
use Symfony\Component\Validator\Constraints as Assert;
20
21
#[ORM\Table(name: 'c_survey')]
22
#[ORM\Index(columns: ['code'], name: 'idx_survey_code')]
23
#[Gedmo\Tree(type: 'nested')]
24
#[ORM\Entity(repositoryClass: CSurveyRepository::class)]
25
class CSurvey extends AbstractResource implements ResourceInterface, Stringable
26
{
27
    #[ORM\Column(name: 'iid', type: 'integer')]
28
    #[ORM\Id]
29
    #[ORM\GeneratedValue]
30
    protected ?int $iid = null;
31
32
    #[Assert\NotBlank]
33
    #[ORM\Column(name: 'code', type: 'string', length: 40, nullable: true)]
34
    protected ?string $code = null;
35
36
    #[Assert\NotBlank]
37
    #[ORM\Column(name: 'title', type: 'text', nullable: false)]
38
    protected string $title;
39
40
    #[ORM\Column(name: 'subtitle', type: 'text', nullable: true)]
41
    protected ?string $subtitle;
42
43
    #[ORM\Column(name: 'lang', type: 'string', length: 20, nullable: true)]
44
    protected ?string $lang;
45
46
    #[ORM\Column(name: 'avail_from', type: 'datetime', nullable: true)]
47
    protected ?DateTime $availFrom = null;
48
49
    #[ORM\Column(name: 'avail_till', type: 'datetime', nullable: true)]
50
    protected ?DateTime $availTill = null;
51
52
    #[ORM\Column(name: 'is_shared', type: 'string', length: 1, nullable: true)]
53
    protected ?string $isShared = null;
54
55
    #[ORM\Column(name: 'template', type: 'string', length: 20, nullable: true)]
56
    protected ?string $template = null;
57
58
    #[ORM\Column(name: 'intro', type: 'text', nullable: true)]
59
    protected ?string $intro = null;
60
61
    #[ORM\Column(name: 'surveythanks', type: 'text', nullable: true)]
62
    protected ?string $surveyThanks = null;
63
64
    #[ORM\Column(name: 'creation_date', type: 'datetime', nullable: false)]
65
    protected DateTime $creationDate;
66
67
    #[ORM\Column(name: 'invited', type: 'integer', nullable: false)]
68
    protected int $invited;
69
70
    #[ORM\Column(name: 'answered', type: 'integer', nullable: false)]
71
    protected int $answered;
72
73
    #[ORM\Column(name: 'invite_mail', type: 'text', nullable: false)]
74
    protected string $inviteMail;
75
76
    #[ORM\Column(name: 'reminder_mail', type: 'text', nullable: false)]
77
    protected string $reminderMail;
78
79
    #[ORM\Column(name: 'mail_subject', type: 'string', length: 255, nullable: false)]
80
    protected string $mailSubject;
81
82
    #[Assert\NotBlank]
83
    #[ORM\Column(name: 'anonymous', type: 'string', length: 10, nullable: false)]
84
    protected string $anonymous;
85
86
    #[ORM\Column(name: 'access_condition', type: 'text', nullable: true)]
87
    protected ?string $accessCondition = null;
88
89
    #[ORM\Column(name: 'shuffle', type: 'boolean', nullable: false)]
90
    protected bool $shuffle;
91
92
    #[ORM\Column(name: 'one_question_per_page', type: 'boolean', nullable: false)]
93
    protected bool $oneQuestionPerPage;
94
95
    #[ORM\Column(name: 'survey_version', type: 'string', length: 255, nullable: false)]
96
    protected string $surveyVersion;
97
98
    #[Gedmo\TreeLeft]
99
    #[ORM\Column(name: 'lft', type: 'integer', unique: false, nullable: true)]
100
    protected ?int $lft = null;
101
102
    #[Gedmo\TreeRight]
103
    #[ORM\Column(name: 'rgt', type: 'integer', unique: false, nullable: true)]
104
    protected ?int $rgt = null;
105
106
    #[Gedmo\TreeLevel]
107
    #[ORM\Column(name: 'lvl', type: 'integer', unique: false, nullable: true)]
108
    protected ?int $lvl = null;
109
110
    /**
111
     * @var Collection<int, CSurveyQuestion>
112
     */
113
    #[ORM\OneToMany(mappedBy: 'survey', targetEntity: CSurveyQuestion::class, cascade: ['remove'])]
114
    protected Collection $questions;
115
116
    /**
117
     * @var Collection<int, CSurveyInvitation>
118
     */
119
    #[ORM\OneToMany(mappedBy: 'survey', targetEntity: CSurveyInvitation::class, cascade: ['remove'])]
120
    protected Collection $invitations;
121
122
    #[Gedmo\TreeParent]
123
    #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
124
    #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'iid', onDelete: 'CASCADE')]
125
    protected ?CSurvey $surveyParent = null;
126
127
    /**
128
     * @var Collection<int, CSurvey>
129
     */
130
    #[ORM\OneToMany(mappedBy: 'surveyParent', targetEntity: self::class)]
131
    protected Collection $children;
132
133
    /**
134
     * @var Collection<int, CSurveyQuestionOption>
135
     */
136
    #[ORM\OrderBy(['sort' => 'ASC'])]
137
    #[ORM\OneToMany(mappedBy: 'survey', targetEntity: CSurveyQuestionOption::class, cascade: ['remove'])]
138
    protected Collection $options;
139
140
    #[ORM\Column(name: 'survey_type', type: 'integer', nullable: false)]
141
    protected int $surveyType;
142
143
    #[ORM\Column(name: 'show_form_profile', type: 'integer', nullable: false)]
144
    protected int $showFormProfile;
145
146
    #[ORM\Column(name: 'form_fields', type: 'text', nullable: false)]
147
    protected string $formFields;
148
149
    #[ORM\Column(name: 'visible_results', type: 'integer', nullable: true)]
150
    protected ?int $visibleResults = null;
151
152
    #[ORM\Column(name: 'is_mandatory', type: 'boolean', options: ['default' => false])]
153
    protected bool $isMandatory = false;
154
155
    #[ORM\Column(name: 'display_question_number', type: 'boolean', options: ['default' => true])]
156
    protected bool $displayQuestionNumber;
157
158
    #[ORM\Column(name: 'duration', type: 'integer', nullable: true)]
159
    protected ?int $duration = null;
160
161
    public function __construct()
162
    {
163
        $this->title = '';
164
        $this->creationDate = new DateTime();
165
        $this->invited = 0;
166
        $this->answered = 0;
167
        $this->anonymous = '0';
168
        $this->formFields = '0';
169
        $this->subtitle = '';
170
        $this->inviteMail = '';
171
        $this->lang = '';
172
        $this->reminderMail = '';
173
        $this->mailSubject = '';
174
        $this->shuffle = false;
175
        $this->oneQuestionPerPage = false;
176
        $this->surveyVersion = '';
177
        $this->surveyType = 0;
178
        $this->showFormProfile = 0;
179
        $this->questions = new ArrayCollection();
180
        $this->children = new ArrayCollection();
181
        $this->invitations = new ArrayCollection();
182
        $this->options = new ArrayCollection();
183
        $this->displayQuestionNumber = true;
184
    }
185
186
    public function __toString(): string
187
    {
188
        return (string) $this->getCode();
189
    }
190
191
    public function getCode(): ?string
192
    {
193
        return $this->code;
194
    }
195
196
    public function setCode(string $code): self
197
    {
198
        $this->code = $code;
199
200
        return $this;
201
    }
202
203
    public function getTitle(): string
204
    {
205
        return $this->title;
206
    }
207
208
    public function setTitle(string $title): self
209
    {
210
        $this->title = $title;
211
212
        return $this;
213
    }
214
215
    public function getSubtitle(): ?string
216
    {
217
        return $this->subtitle;
218
    }
219
220
    public function setSubtitle(string $subtitle): self
221
    {
222
        $this->subtitle = $subtitle;
223
224
        return $this;
225
    }
226
227
    public function getLang(): ?string
228
    {
229
        return $this->lang;
230
    }
231
232
    public function setLang(string $lang): self
233
    {
234
        $this->lang = $lang;
235
236
        return $this;
237
    }
238
239
    public function getAvailFrom(): ?DateTime
240
    {
241
        return $this->availFrom;
242
    }
243
244
    public function setAvailFrom(?DateTime $availFrom = null): self
245
    {
246
        if (null === $availFrom) {
247
            $availFrom = new DateTime();
248
        }
249
        $this->availFrom = $availFrom;
250
251
        return $this;
252
    }
253
254
    public function getAvailTill(): ?DateTime
255
    {
256
        return $this->availTill;
257
    }
258
259
    public function setAvailTill(?DateTime $availTill = null): self
260
    {
261
        if (null === $availTill) {
262
            $availTill = new DateTime();
263
        }
264
        $this->availTill = $availTill;
265
266
        return $this;
267
    }
268
269
    public function getIsShared(): ?string
270
    {
271
        return $this->isShared;
272
    }
273
274
    public function setIsShared(string $isShared): self
275
    {
276
        $this->isShared = $isShared;
277
278
        return $this;
279
    }
280
281
    public function getTemplate(): ?string
282
    {
283
        return $this->template;
284
    }
285
286
    public function setTemplate(string $template): self
287
    {
288
        $this->template = $template;
289
290
        return $this;
291
    }
292
293
    public function getIntro(): ?string
294
    {
295
        return $this->intro;
296
    }
297
298
    public function setIntro(string $intro): self
299
    {
300
        $this->intro = $intro;
301
302
        return $this;
303
    }
304
305
    public function getSurveythanks(): ?string
306
    {
307
        return $this->surveyThanks;
308
    }
309
310
    public function setSurveythanks(string $surveythanks): self
311
    {
312
        $this->surveyThanks = $surveythanks;
313
314
        return $this;
315
    }
316
317
    public function getCreationDate(): DateTime
318
    {
319
        return $this->creationDate;
320
    }
321
322
    public function setCreationDate(DateTime $creationDate): self
323
    {
324
        $this->creationDate = $creationDate;
325
326
        return $this;
327
    }
328
329
    public function getInvited(): int
330
    {
331
        return $this->invited;
332
    }
333
334
    public function setInvited(int $invited): self
335
    {
336
        $this->invited = $invited;
337
338
        return $this;
339
    }
340
341
    public function getAnswered(): int
342
    {
343
        return $this->answered;
344
    }
345
346
    public function setAnswered(int $answered): self
347
    {
348
        $this->answered = $answered;
349
350
        return $this;
351
    }
352
353
    public function getInviteMail(): string
354
    {
355
        return $this->inviteMail;
356
    }
357
358
    public function setInviteMail(string $inviteMail): self
359
    {
360
        $this->inviteMail = $inviteMail;
361
362
        return $this;
363
    }
364
365
    public function getReminderMail(): string
366
    {
367
        return $this->reminderMail;
368
    }
369
370
    public function setReminderMail(string $reminderMail): self
371
    {
372
        $this->reminderMail = $reminderMail;
373
374
        return $this;
375
    }
376
377
    public function getMailSubject(): string
378
    {
379
        return $this->mailSubject;
380
    }
381
382
    public function setMailSubject(string $mailSubject): self
383
    {
384
        $this->mailSubject = $mailSubject;
385
386
        return $this;
387
    }
388
389
    public function getAnonymous(): string
390
    {
391
        return $this->anonymous;
392
    }
393
394
    public function setAnonymous(string $anonymous): self
395
    {
396
        $this->anonymous = $anonymous;
397
398
        return $this;
399
    }
400
401
    public function getAccessCondition(): ?string
402
    {
403
        return $this->accessCondition;
404
    }
405
406
    public function setAccessCondition(string $accessCondition): self
407
    {
408
        $this->accessCondition = $accessCondition;
409
410
        return $this;
411
    }
412
413
    public function getShuffle(): bool
414
    {
415
        return $this->shuffle;
416
    }
417
418
    public function setShuffle(bool $shuffle): self
419
    {
420
        $this->shuffle = $shuffle;
421
422
        return $this;
423
    }
424
425
    public function getOneQuestionPerPage(): bool
426
    {
427
        return $this->oneQuestionPerPage;
428
    }
429
430
    public function setOneQuestionPerPage(bool $oneQuestionPerPage): self
431
    {
432
        $this->oneQuestionPerPage = $oneQuestionPerPage;
433
434
        return $this;
435
    }
436
437
    public function getSurveyVersion(): string
438
    {
439
        return $this->surveyVersion;
440
    }
441
442
    public function setSurveyVersion(string $surveyVersion): self
443
    {
444
        $this->surveyVersion = $surveyVersion;
445
446
        return $this;
447
    }
448
449
    public function getSurveyType(): int
450
    {
451
        return $this->surveyType;
452
    }
453
454
    public function setSurveyType(int $surveyType): self
455
    {
456
        $this->surveyType = $surveyType;
457
458
        return $this;
459
    }
460
461
    public function getShowFormProfile(): int
462
    {
463
        return $this->showFormProfile;
464
    }
465
466
    public function setShowFormProfile(int $showFormProfile): self
467
    {
468
        $this->showFormProfile = $showFormProfile;
469
470
        return $this;
471
    }
472
473
    public function getFormFields(): string
474
    {
475
        return $this->formFields;
476
    }
477
478
    public function setFormFields(string $formFields): self
479
    {
480
        $this->formFields = $formFields;
481
482
        return $this;
483
    }
484
485
    public function getVisibleResults(): ?int
486
    {
487
        return $this->visibleResults;
488
    }
489
490
    public function setVisibleResults(int $visibleResults): self
491
    {
492
        $this->visibleResults = $visibleResults;
493
494
        return $this;
495
    }
496
497
    public function isMandatory(): bool
498
    {
499
        return $this->isMandatory;
500
    }
501
502
    public function setIsMandatory(bool $isMandatory): self
503
    {
504
        $this->isMandatory = $isMandatory;
505
506
        return $this;
507
    }
508
509
    /**
510
     * @return Collection<int, CSurveyQuestion>
511
     */
512
    public function getQuestions(): Collection
513
    {
514
        return $this->questions;
515
    }
516
517
    public function setQuestions(Collection $questions): self
518
    {
519
        $this->questions = $questions;
520
521
        return $this;
522
    }
523
524
    public function getSurveyParent(): ?self
525
    {
526
        return $this->surveyParent;
527
    }
528
529
    public function setSurveyParent(?self $surveyParent): self
530
    {
531
        $this->surveyParent = $surveyParent;
532
533
        return $this;
534
    }
535
536
    public function getLft(): ?int
537
    {
538
        return $this->lft;
539
    }
540
541
    public function setLft(?int $lft): self
542
    {
543
        $this->lft = $lft;
544
545
        return $this;
546
    }
547
548
    public function getRgt(): ?int
549
    {
550
        return $this->rgt;
551
    }
552
553
    public function setRgt(?int $rgt): self
554
    {
555
        $this->rgt = $rgt;
556
557
        return $this;
558
    }
559
560
    public function getLvl(): ?int
561
    {
562
        return $this->lvl;
563
    }
564
565
    public function setLvl(?int $lvl): self
566
    {
567
        $this->lvl = $lvl;
568
569
        return $this;
570
    }
571
572
    /**
573
     * @return Collection<int, CSurvey>
574
     */
575
    public function getChildren(): Collection
576
    {
577
        return $this->children;
578
    }
579
580
    /**
581
     * @param Collection<int, CSurvey> $children
582
     */
583
    public function setChildren(Collection $children): self
584
    {
585
        $this->children = $children;
586
587
        return $this;
588
    }
589
590
    /**
591
     * @return Collection<int, CSurveyQuestionOption>
592
     */
593
    public function getOptions(): Collection
594
    {
595
        return $this->options;
596
    }
597
598
    public function setOptions(Collection $options): self
599
    {
600
        $this->options = $options;
601
602
        return $this;
603
    }
604
605
    /**
606
     * @return Collection<int, CSurveyInvitation>
607
     */
608
    public function getInvitations(): Collection
609
    {
610
        return $this->invitations;
611
    }
612
613
    public function setInvitations(Collection $invitations): self
614
    {
615
        $this->invitations = $invitations;
616
617
        return $this;
618
    }
619
620
    public function getResourceIdentifier(): int|Uuid
621
    {
622
        return (int) $this->getIid();
623
    }
624
625
    public function getIid(): ?int
626
    {
627
        return $this->iid;
628
    }
629
630
    public function getDuration(): ?int
631
    {
632
        return $this->duration;
633
    }
634
635
    public function setDuration(?int $duration): self
636
    {
637
        $this->duration = $duration;
638
639
        return $this;
640
    }
641
642
    public function getResourceName(): string
643
    {
644
        return (string) $this->getCode();
645
    }
646
647
    public function setResourceName(string $name): self
648
    {
649
        return $this->setCode($name);
650
    }
651
652
    public function isDisplayQuestionNumber(): bool
653
    {
654
        return $this->displayQuestionNumber;
655
    }
656
657
    public function setDisplayQuestionNumber(bool $displayQuestionNumber): static
658
    {
659
        $this->displayQuestionNumber = $displayQuestionNumber;
660
661
        return $this;
662
    }
663
}
664