Passed
Push — master ( 435634...9a6e0b )
by Julito
10:38
created

Page::getPosition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\SearchFilter;
12
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
13
use Doctrine\ORM\Mapping as ORM;
14
use Gedmo\Mapping\Annotation as Gedmo;
15
use Symfony\Component\Serializer\Annotation\Groups;
16
use Symfony\Component\Validator\Constraints as Assert;
17
18
/**
19
 * @ORM\Table(
20
 *     name="page",
21
 *     indexes={
22
 *     }
23
 * )
24
 * @ORM\Entity
25
 */
26
#[ApiResource(
27
    collectionOperations: [
28
        'get' => [
29
            'security' => "is_granted('ROLE_USER')",
30
        ],
31
        'post' => [
32
            'security' => "is_granted('ROLE_ADMIN')",
33
        ],
34
    ],
35
    itemOperations: [
36
        'get' => [
37
            'security' => "is_granted('ROLE_USER')",
38
        ],
39
        'put' => [
40
            'security' => "is_granted('ROLE_ADMIN')",
41
        ],
42
        'delete' => [
43
            'security' => "is_granted('ROLE_ADMIN')",
44
        ],
45
    ],
46
    denormalizationContext: [
47
        'groups' => ['page:write'],
48
    ],
49
    normalizationContext: [
50
        'groups' => ['page:read'],
51
    ],
52
)]
53
54
#[ApiFilter(SearchFilter::class, properties: [
55
    'locale' => 'exact',
56
    'url' => 'exact',
57
    'category' => 'exact',
58
    'category.title' => 'partial',
59
])]
60
class Page
61
{
62
    use TimestampableTypedEntity;
63
64
    /**
65
     * @ORM\Column(name="id", type="bigint")
66
     * @ORM\Id
67
     * @ORM\GeneratedValue()
68
     */
69
    protected int $id;
70
71
    /**
72
     * @ORM\Column(name="title", type="string", length=255)
73
     */
74
    #[Assert\NotBlank]
75
    #[Groups(['page:read', 'page:write'])]
76
    protected string $title;
77
78
    /**
79
     * @ORM\Column(name="content", type="text")
80
     */
81
    #[Groups(['page:read', 'page:write'])]
82
    #[Assert\NotBlank]
83
    protected string $content;
84
85
    /**
86
     * @Gedmo\Slug(
87
     *     fields={"title"},
88
     *     updatable=true,
89
     *     unique=true,
90
     * )
91
     * @ORM\Column(name="slug", type="string", length=255)
92
     */
93
    protected string $slug;
94
95
    /**
96
     * @ORM\Column(name="enabled", type="boolean", nullable=false)
97
     */
98
    #[Groups(['page:read', 'page:write'])]
99
    protected bool $enabled;
100
101
    /**
102
     * @Gedmo\SortablePosition
103
     * @ORM\Column(name="position", type="integer")
104
     */
105
    #[Groups(['page:read', 'page:write'])]
106
    protected int $position;
107
108
    /**
109
     * @ORM\Column(name="locale", type="string", length=10)
110
     */
111
    #[Groups(['page:read', 'page:write'])]
112
    protected string $locale;
113
114
    /**
115
     * @ORM\ManyToOne(targetEntity="AccessUrl", cascade={"persist"})
116
     * @ORM\JoinColumn(name="access_url_id", referencedColumnName="id")
117
     */
118
    #[Assert\NotNull]
119
    #[Groups(['page:read', 'page:write'])]
120
    protected AccessUrl $url;
121
122
    /**
123
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
124
     * @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
125
     */
126
    #[Assert\NotNull]
127
    #[Groups(['page:read', 'page:write'])]
128
    protected User $creator;
129
130
    /**
131
     * @Gedmo\SortableGroup
132
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\PageCategory", inversedBy="pages")
133
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="SET NULL")
134
     */
135
    #[Groups(['page:read', 'page:write'])]
136
    protected ?PageCategory $category = null;
137
138
    public function __construct()
139
    {
140
        $this->enabled = false;
141
    }
142
143
    public function getId(): int
144
    {
145
        return $this->id;
146
    }
147
148
    public function getTitle(): string
149
    {
150
        return $this->title;
151
    }
152
153
    public function setTitle(string $title): self
154
    {
155
        $this->title = $title;
156
157
        return $this;
158
    }
159
160
    public function getContent(): string
161
    {
162
        return $this->content;
163
    }
164
165
    public function setContent(string $content): self
166
    {
167
        $this->content = $content;
168
169
        return $this;
170
    }
171
172
    public function getSlug(): string
173
    {
174
        return $this->slug;
175
    }
176
177
    public function setSlug(string $slug): self
178
    {
179
        $this->slug = $slug;
180
181
        return $this;
182
    }
183
184
    public function isEnabled(): bool
185
    {
186
        return $this->enabled;
187
    }
188
189
    public function setEnabled(bool $enabled): self
190
    {
191
        $this->enabled = $enabled;
192
193
        return $this;
194
    }
195
196
    public function getLocale(): string
197
    {
198
        return $this->locale;
199
    }
200
201
    public function setLocale(string $locale): self
202
    {
203
        $this->locale = $locale;
204
205
        return $this;
206
    }
207
208
    public function getUrl(): AccessUrl
209
    {
210
        return $this->url;
211
    }
212
213
    public function setUrl(AccessUrl $url): self
214
    {
215
        $this->url = $url;
216
217
        return $this;
218
    }
219
220
    public function getCreator(): User
221
    {
222
        return $this->creator;
223
    }
224
225
    public function setCreator(User $creator): self
226
    {
227
        $this->creator = $creator;
228
229
        return $this;
230
    }
231
232
    public function getPosition(): int
233
    {
234
        return $this->position;
235
    }
236
237
    public function setPosition(int $position): self
238
    {
239
        $this->position = $position;
240
241
        return $this;
242
    }
243
244
    public function getCategory(): ?PageCategory
245
    {
246
        return $this->category;
247
    }
248
249
    public function setCategory(PageCategory $category): self
250
    {
251
        $this->category = $category;
252
253
        return $this;
254
    }
255
}
256