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

PageCategory::setPages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
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\ApiResource;
10
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Collection;
13
use Doctrine\ORM\Mapping as ORM;
14
use Symfony\Component\Serializer\Annotation\Groups;
15
use Symfony\Component\Validator\Constraints as Assert;
16
17
/**
18
 * @ORM\Table(
19
 *     name="page_category",
20
 *     indexes={
21
 *     }
22
 * )
23
 * @ORM\Entity
24
 */
25
#[ApiResource(
26
    collectionOperations: [
27
        'get' => [
28
            'security' => "is_granted('ROLE_USER')",
29
        ],
30
        'post' => [
31
            'security' => "is_granted('ROLE_ADMIN')",
32
        ],
33
    ],
34
    itemOperations: [
35
        'get' => [
36
            'security' => "is_granted('ROLE_USER')",
37
        ],
38
        'put' => [
39
            'security' => "is_granted('ROLE_ADMIN')",
40
        ],
41
        'delete' => [
42
            'security' => "is_granted('ROLE_ADMIN')",
43
        ],
44
    ],
45
    denormalizationContext: [
46
        'groups' => ['page_category:write'],
47
    ],
48
    normalizationContext: [
49
        'groups' => ['page_category:read'],
50
    ],
51
)]
52
class PageCategory
53
{
54
    use TimestampableTypedEntity;
55
56
    /**
57
     * @ORM\Column(name="id", type="bigint")
58
     * @ORM\Id
59
     * @ORM\GeneratedValue()
60
     */
61
    #[Groups(['page_category:read', 'page_category:write'])]
62
    protected ?int $id = null;
63
64
    /**
65
     * @ORM\Column(name="title", type="string", length=255)
66
     */
67
    #[Assert\NotBlank]
68
    #[Groups(['page_category:read', 'page_category:write'])]
69
    protected string $title;
70
71
    /**
72
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
73
     * @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
74
     */
75
    #[Assert\NotNull]
76
    protected User $creator;
77
78
    /**
79
     * @ORM\Column(name="type", type="string")
80
     */
81
    #[Groups(['page_category:read', 'page_category:write', 'page:read'])]
82
    #[Assert\NotBlank]
83
    protected string $type;
84
85
    /**
86
     * @var Collection|Page[]
87
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Page", mappedBy="category", cascade={"persist"})
88
     */
89
    protected Collection $pages;
90
91
    public function __construct()
92
    {
93
        $this->pages = new ArrayCollection();
94
    }
95
96
    public function getId(): ?int
97
    {
98
        return $this->id;
99
    }
100
101
    public function getTitle(): string
102
    {
103
        return $this->title;
104
    }
105
106
    public function setTitle(string $title): self
107
    {
108
        $this->title = $title;
109
110
        return $this;
111
    }
112
113
    public function getCreator(): User
114
    {
115
        return $this->creator;
116
    }
117
118
    public function setCreator(User $creator): self
119
    {
120
        $this->creator = $creator;
121
122
        return $this;
123
    }
124
125
    public function getType(): string
126
    {
127
        return $this->type;
128
    }
129
130
    public function setType(string $type): self
131
    {
132
        $this->type = $type;
133
134
        return $this;
135
    }
136
137
    public function getPages()
138
    {
139
        return $this->pages;
140
    }
141
142
    public function setPages($pages): self
143
    {
144
        $this->pages = $pages;
145
146
        return $this;
147
    }
148
}
149