Passed
Push — master ( ad6b2a...ec8fd5 )
by Julito
28:29 queued 12s
created

CourseCategory::setImage()   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
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use ApiPlatform\Core\Annotation\ApiFilter;
10
use ApiPlatform\Core\Annotation\ApiResource;
11
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
12
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
13
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\ORM\Mapping as ORM;
17
use Symfony\Component\Serializer\Annotation\Groups;
18
use Symfony\Component\Validator\Constraints as Assert;
19
20
/**
21
 * CourseCategory.
22
 *
23
 * @ApiResource(
24
 *     attributes={"security"="is_granted('ROLE_ADMIN')"},
25
 *     normalizationContext={"groups"={"course_category:read", "course:read"}, "swagger_definition_name"="Read"},
26
 *     denormalizationContext={"groups"={"course_category:write", "course:write"}},
27
 * )
28
 * @ApiFilter(SearchFilter::class, properties={"name":"partial", "code":"partial"})
29
 * @ApiFilter(PropertyFilter::class)
30
 * @ApiFilter(OrderFilter::class, properties={"name", "code"})
31
 * @ORM\Table(
32
 *     name="course_category",
33
 *     uniqueConstraints={
34
 *         @ORM\UniqueConstraint(name="code", columns={"code"})
35
 *     },
36
 *     indexes={
37
 *         @ORM\Index(name="parent_id", columns={"parent_id"}),
38
 *         @ORM\Index(name="tree_pos", columns={"tree_pos"})
39
 *     }
40
 * )
41
 * @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Repository\CourseCategoryRepository")
42
 */
43
class CourseCategory
44
{
45
    /**
46
     * @Groups({"course_category:read", "course:read"})
47
     * @ORM\Column(name="id", type="integer")
48
     * @ORM\Id
49
     * @ORM\GeneratedValue()
50
     */
51
    protected int $id;
52
53
    /**
54
     * @ORM\OneToMany(targetEntity="CourseCategory", mappedBy="parent")
55
     *
56
     * @var Collection|CourseCategory[]
57
     */
58
    protected Collection $children;
59
60
    /**
61
     * @Assert\NotBlank()
62
     * @Groups({"course_category:read", "course_category:write", "course:read"})
63
     * @ORM\Column(name="name", type="text", nullable=false)
64
     */
65
    protected string $name;
66
67
    /**
68
     * @Assert\NotBlank()
69
     * @Groups({"course_category:read", "course_category:write", "course:read"})
70
     * @ORM\Column(name="code", type="string", length=40, nullable=false)
71
     */
72
    protected string $code;
73
74
    /**
75
     * @ORM\ManyToOne(targetEntity="CourseCategory", inversedBy="children")
76
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
77
     */
78
    protected ?CourseCategory $parent = null;
79
80
    /**
81
     * @ORM\Column(name="tree_pos", type="integer", nullable=true)
82
     */
83
    protected ?int $treePos = null;
84
85
    /**
86
     * @ORM\Column(name="children_count", type="smallint", nullable=true)
87
     */
88
    protected ?int $childrenCount;
89
90
    /**
91
     * @ORM\Column(name="auth_course_child", type="string", length=40, nullable=true)
92
     */
93
    protected ?string $authCourseChild = null;
94
95
    /**
96
     * @ORM\Column(name="auth_cat_child", type="string", length=40, nullable=true)
97
     */
98
    protected ?string $authCatChild = null;
99
100
    /**
101
     * @ORM\Column(name="image", type="string", length=255, nullable=true)
102
     */
103
    protected ?string $image = null;
104
105
    /**
106
     * @Groups({"course_category:read", "course_category:write"})
107
     * @ORM\Column(name="description", type="text", nullable=true)
108
     */
109
    protected ?string $description = null;
110
111
    /**
112
     * @ORM\OneToMany(
113
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelCourseCategory",
114
     *     mappedBy="courseCategory", cascade={"persist"}, orphanRemoval=true
115
     * )
116
     *
117
     * @var AccessUrlRelCourseCategory[]|Collection
118
     */
119
    protected Collection $urls;
120
121
    /**
122
     * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\Course", mappedBy="categories")
123
     */
124
    protected Collection $courses;
125
126
    public function __construct()
127
    {
128
        $this->urls = new ArrayCollection();
129
        $this->childrenCount = 0;
130
        $this->children = new ArrayCollection();
131
        $this->courses = new ArrayCollection();
132
    }
133
134
    public function __toString(): string
135
    {
136
        $name = strip_tags($this->name);
137
138
        return sprintf('%s (%s)', $name, $this->code);
139
    }
140
141
    /**
142
     * Get id.
143
     *
144
     * @return int
145
     */
146
    public function getId()
147
    {
148
        return $this->id;
149
    }
150
151
    public function getParent(): self
152
    {
153
        return $this->parent;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->parent could return the type null which is incompatible with the type-hinted return Chamilo\CoreBundle\Entity\CourseCategory. Consider adding an additional type-check to rule them out.
Loading history...
154
    }
155
156
    /**
157
     * @return Collection
158
     */
159
    public function getChildren()
160
    {
161
        return $this->children;
162
    }
163
164
    public function addChild(self $child): self
165
    {
166
        $this->children[] = $child;
167
        $child->setParent($this);
168
169
        return $this;
170
    }
171
172
    public function setParent(self $parent): self
173
    {
174
        $this->parent = $parent;
175
176
        return $this;
177
    }
178
179
    public function setName(string $name): self
180
    {
181
        $this->name = $name;
182
183
        return $this;
184
    }
185
186
    public function getName(): string
187
    {
188
        return $this->name;
189
    }
190
191
    public function setCode(string $code): self
192
    {
193
        $this->code = $code;
194
195
        return $this;
196
    }
197
198
    /**
199
     * Get code.
200
     *
201
     * @return string
202
     */
203
    public function getCode()
204
    {
205
        return $this->code;
206
    }
207
208
    public function setTreePos(int $treePos): self
209
    {
210
        $this->treePos = $treePos;
211
212
        return $this;
213
    }
214
215
    /**
216
     * Get treePos.
217
     *
218
     * @return int
219
     */
220
    public function getTreePos()
221
    {
222
        return $this->treePos;
223
    }
224
225
    public function setChildrenCount(int $childrenCount): self
226
    {
227
        $this->childrenCount = $childrenCount;
228
229
        return $this;
230
    }
231
232
    /**
233
     * Get childrenCount.
234
     *
235
     * @return int
236
     */
237
    public function getChildrenCount()
238
    {
239
        return $this->childrenCount;
240
    }
241
242
    public function setAuthCourseChild(string $authCourseChild): self
243
    {
244
        $this->authCourseChild = $authCourseChild;
245
246
        return $this;
247
    }
248
249
    /**
250
     * Get authCourseChild.
251
     *
252
     * @return string
253
     */
254
    public function getAuthCourseChild()
255
    {
256
        return $this->authCourseChild;
257
    }
258
259
    public function setAuthCatChild(string $authCatChild): self
260
    {
261
        $this->authCatChild = $authCatChild;
262
263
        return $this;
264
    }
265
266
    /**
267
     * Get authCatChild.
268
     *
269
     * @return string
270
     */
271
    public function getAuthCatChild()
272
    {
273
        return $this->authCatChild;
274
    }
275
276
    public function getImage(): string
277
    {
278
        return $this->image;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->image 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...
279
    }
280
281
    public function setImage(string $image): self
282
    {
283
        $this->image = $image;
284
285
        return $this;
286
    }
287
288
    public function getDescription(): ?string
289
    {
290
        return $this->description;
291
    }
292
293
    public function setDescription(string $description): self
294
    {
295
        $this->description = $description;
296
297
        return $this;
298
    }
299
300
    public function getCourses(): Collection
301
    {
302
        return $this->courses;
303
    }
304
305
    public function setCourses(Collection $courses): self
306
    {
307
        $this->courses = $courses;
308
309
        return $this;
310
    }
311
312
    public function addCourse(Course $course): void
313
    {
314
        $this->courses[] = $course;
315
    }
316
317
    /**
318
     * @return AccessUrlRelCourseCategory[]|Collection
319
     */
320
    public function getUrls()
321
    {
322
        return $this->urls;
323
    }
324
325
    public function setUrls($urls): self
326
    {
327
        $this->urls = $urls;
328
329
        return $this;
330
    }
331
}
332