|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProjetNormandie\ForumBundle\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use ApiPlatform\Metadata\ApiResource; |
|
8
|
|
|
use ApiPlatform\Metadata\Get; |
|
9
|
|
|
use ApiPlatform\Metadata\GetCollection; |
|
10
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
11
|
|
|
use Doctrine\Common\Collections\Collection; |
|
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
13
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
|
14
|
|
|
use ProjetNormandie\ForumBundle\Controller\GetHome; |
|
15
|
|
|
use ProjetNormandie\ForumBundle\Repository\CategoryRepository; |
|
16
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
17
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
18
|
|
|
|
|
19
|
|
|
#[ORM\Table(name:'pnf_category')] |
|
20
|
|
|
#[ORM\Entity(repositoryClass: CategoryRepository::class)] |
|
21
|
|
|
#[ApiResource( |
|
22
|
|
|
shortName: 'ForumCategory', |
|
23
|
|
|
order: ['position' => 'ASC'], |
|
24
|
|
|
operations: [ |
|
25
|
|
|
new GetCollection(), |
|
26
|
|
|
new Get(), |
|
27
|
|
|
new GetCollection( |
|
28
|
|
|
uriTemplate: '/forum_category/get-home', |
|
29
|
|
|
controller: GetHome::class, |
|
30
|
|
|
read: false, |
|
31
|
|
|
normalizationContext: [ |
|
32
|
|
|
'groups' => [ |
|
33
|
|
|
'category:read', |
|
34
|
|
|
'category:forums', |
|
35
|
|
|
'forum:read', |
|
36
|
|
|
'forum:last-message', |
|
37
|
|
|
'message:read', |
|
38
|
|
|
'message:user', |
|
39
|
|
|
'user:read:minimal', |
|
40
|
|
|
] |
|
41
|
|
|
], |
|
42
|
|
|
), |
|
43
|
|
|
], |
|
44
|
|
|
normalizationContext: ['groups' => ['category:read']] |
|
45
|
|
|
)] |
|
46
|
|
|
class Category |
|
47
|
|
|
{ |
|
48
|
|
|
use TimestampableEntity; |
|
49
|
|
|
|
|
50
|
|
|
#[Groups(['category:read'])] |
|
51
|
|
|
#[ORM\Id, ORM\Column, ORM\GeneratedValue] |
|
52
|
|
|
private int $id; |
|
53
|
|
|
|
|
54
|
|
|
#[Groups(['category:read'])] |
|
55
|
|
|
#[ORM\Column(length: 50, nullable: false)] |
|
56
|
|
|
private string $name; |
|
57
|
|
|
|
|
58
|
|
|
#[ORM\Column(nullable: true, options: ['default' => 0])] |
|
59
|
|
|
private int $position = 0; |
|
60
|
|
|
|
|
61
|
|
|
#[Groups(['category:read'])] |
|
62
|
|
|
#[ORM\Column(nullable: false, options: ['default' => true])] |
|
63
|
|
|
private bool $displayOnHome = true; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var Collection<int, Forum> |
|
67
|
|
|
*/ |
|
68
|
|
|
#[Groups(['category:forums'])] |
|
69
|
|
|
#[ORM\OneToMany(targetEntity: Forum::class, mappedBy: 'category')] |
|
70
|
|
|
private Collection $forums; |
|
71
|
|
|
|
|
72
|
|
|
public function __toString() |
|
73
|
|
|
{ |
|
74
|
|
|
return sprintf('%s [%s]', $this->getName(), $this->getId()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function __construct() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->forums = new ArrayCollection(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setId(int $id): void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->id = $id; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getId(): ?int |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->id; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function setName(string $name): void |
|
93
|
|
|
{ |
|
94
|
|
|
$this->name = $name; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function getName(): string |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->name; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function setPosition(int $position): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->position = $position; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getPosition(): int |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->position; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function setDisplayOnHome(bool $displayOnHome): void |
|
113
|
|
|
{ |
|
114
|
|
|
$this->displayOnHome = $displayOnHome; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getDisplayOnHome(): bool |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->displayOnHome; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getForums(): Collection |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->forums; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|