Issues (2136)

src/CourseBundle/Entity/CCourseDescription.php (2 issues)

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\ResourceShowCourseResourcesInSessionInterface;
12
use Chamilo\CourseBundle\Repository\CCourseDescriptionRepository;
13
use Doctrine\ORM\Mapping as ORM;
14
use Stringable;
15
use Symfony\Component\Uid\Uuid;
16
use Symfony\Component\Validator\Constraints as Assert;
17
18
#[ORM\Table(name: 'c_course_description')]
19
#[ORM\Entity(repositoryClass: CCourseDescriptionRepository::class)]
20
class CCourseDescription extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface, Stringable
21
{
22
    public const TYPE_DESCRIPTION = 1;
23
    public const TYPE_OBJECTIVES = 2;
24
    public const TYPE_TOPICS = 3;
25
    public const TYPE_METHODOLOGY = 4;
26
    public const TYPE_COURSE_MATERIAL = 5;
27
    public const TYPE_RESOURCES = 6;
28
    public const TYPE_ASSESSMENT = 7;
29
    public const TYPE_CUSTOM = 8;
30
31
    #[ORM\Column(name: 'iid', type: 'integer')]
32
    #[ORM\Id]
33
    #[ORM\GeneratedValue]
34
    protected ?int $iid = null;
35
36
    #[Assert\NotBlank]
37
    #[ORM\Column(name: 'title', type: 'text', nullable: true)]
38
    protected ?string $title = null;
39
40
    #[ORM\Column(name: 'content', type: 'text', nullable: true)]
41
    protected ?string $content;
42
43
    #[Assert\Choice(callback: 'getTypes')]
44
    #[ORM\Column(name: 'description_type', type: 'integer', nullable: false)]
45
    protected int $descriptionType;
46
47
    #[ORM\Column(name: 'progress', type: 'integer', nullable: false)]
48
    protected int $progress;
49
50
    /**
51
     * Runtime flag to skip search indexing (not persisted).
52
     */
53
    private bool $skipSearchIndex = false;
54
55
    public function __construct()
56
    {
57
        $this->content = '';
58
        $this->progress = 0;
59
        $this->descriptionType = 1;
60
    }
61
62
    public function __toString(): string
63
    {
64
        return $this->getTitle();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getTitle() could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
65
    }
66
67
    public static function getTypes(): array
68
    {
69
        return [
70
            self::TYPE_DESCRIPTION,
71
            self::TYPE_OBJECTIVES,
72
            self::TYPE_TOPICS,
73
            self::TYPE_METHODOLOGY,
74
            self::TYPE_COURSE_MATERIAL,
75
            self::TYPE_RESOURCES,
76
            self::TYPE_ASSESSMENT,
77
            self::TYPE_CUSTOM,
78
        ];
79
    }
80
81
    public function setTitle(string $title): self
82
    {
83
        $this->title = $title;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @return string|null
90
     */
91
    public function getTitle()
92
    {
93
        return $this->title;
94
    }
95
96
    public function setContent(string $content): self
97
    {
98
        $this->content = $content;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @return string|null
105
     */
106
    public function getContent()
107
    {
108
        return $this->content;
109
    }
110
111
    public function setDescriptionType(int $descriptionType): self
112
    {
113
        $this->descriptionType = $descriptionType;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return int
120
     */
121
    public function getDescriptionType()
122
    {
123
        return $this->descriptionType;
124
    }
125
126
    public function setProgress(int $progress): self
127
    {
128
        $this->progress = $progress;
129
130
        return $this;
131
    }
132
133
    /**
134
     * @return int
135
     */
136
    public function getProgress()
137
    {
138
        return $this->progress;
139
    }
140
141
    public function getIid(): ?int
142
    {
143
        return $this->iid;
144
    }
145
146
    public function getResourceIdentifier(): int|Uuid
147
    {
148
        return $this->getIid();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getIid() could return the type null which is incompatible with the type-hinted return Symfony\Component\Uid\Uuid|integer. Consider adding an additional type-check to rule them out.
Loading history...
149
    }
150
151
    public function getResourceName(): string
152
    {
153
        return (string) $this->getTitle();
154
    }
155
156
    public function setResourceName(string $name): self
157
    {
158
        return $this->setTitle($name);
159
    }
160
161
    /**
162
     * Mark this entity to skip search indexing in the current request.
163
     */
164
    public function setSkipSearchIndex(bool $skip): self
165
    {
166
        $this->skipSearchIndex = $skip;
167
168
        return $this;
169
    }
170
171
    /**
172
     * Should search indexing be skipped for this entity in this request?
173
     */
174
    public function shouldSkipSearchIndex(): bool
175
    {
176
        return $this->skipSearchIndex;
177
    }
178
}
179