-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfile.php
More file actions
228 lines (185 loc) · 5.58 KB
/
Profile.php
File metadata and controls
228 lines (185 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
namespace App\Entity;
use App\Entity\Traits\BlameableTrait;
use App\Entity\Traits\TimestampableTrait;
use App\Repository\ProfileRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ProfileRepository::class)]
#[UniqueEntity(
fields: ['username'],
message: 'profile.username.unique',
errorPath: 'username',
ignoreNull: false,
repositoryMethod: 'sluggifyAndFind'
)]
class Profile
{
use BlameableTrait;
use TimestampableTrait;
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?Uuid $id = null;
#[ORM\Column(type: Types::STRING, length: 50)]
#[Assert\NotBlank(message: 'profile.username.not_blank')]
#[Assert\Regex(pattern: '/^[A-zÀ-ú\d ]{2,50}$/', message: 'profile.username.invalid')]
#[Groups('searchable')]
private ?string $username = null;
#[ORM\Column(type: Types::STRING, length: 100, unique: true)]
#[Gedmo\Slug(fields: ['username'])]
#[Groups('searchable')]
private ?string $slug = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Assert\Length(max: 2500, maxMessage: 'profile.description.max_length')]
#[Groups('searchable')]
private ?string $description = null;
#[ORM\OneToOne(inversedBy: 'profile', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
#[Assert\NotNull]
#[Assert\Valid]
private ?User $user = null;
#[ORM\OneToOne(inversedBy: 'profile', cascade: ['persist', 'remove'])]
#[Assert\Valid]
#[Groups('searchable')]
private ?ProfilePicture $picture = null;
#[ORM\Column(length: 255, nullable: true)]
#[Assert\Regex(
pattern: '/^(https:\/\/)?github\.com\/[a-zA-Z0-9_]{1,50}$/',
message: 'profile.github_link.invalid'
)]
#[Assert\Url(message: 'profile.github_link.not_url')]
private ?string $githubLink = null;
#[ORM\OneToMany(mappedBy: 'profile', targetEntity: Vote::class, orphanRemoval: true, cascade: ['persist', 'remove'])]
private Collection $votes;
#[ORM\OneToMany(mappedBy: 'profile', targetEntity: Stack::class, orphanRemoval: true)]
private Collection $stacks;
public function __construct()
{
$this->votes = new ArrayCollection();
$this->stacks = new ArrayCollection();
}
public function getId(): ?Uuid
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(?string $username): self
{
$this->username = $username;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getPicture(): ?ProfilePicture
{
return $this->picture;
}
public function setPicture(?ProfilePicture $picture): self
{
$this->picture = $picture;
return $this;
}
#[Groups('searchable')]
public function isIndexable(): bool
{
return $this->user?->isVerified();
}
public function getGithubLink(): ?string
{
return $this->githubLink;
}
public function setGithubLink(?string $githubLink): self
{
$this->githubLink = $githubLink;
return $this;
}
/**
* @return Collection<int, Vote>
*/
public function getVotes(): Collection
{
return $this->votes;
}
public function addVote(Vote $vote): self
{
if (!$this->votes->contains($vote)) {
$this->votes->add($vote);
$vote->setProfile($this);
}
return $this;
}
public function removeVote(Vote $vote): self
{
if ($this->votes->removeElement($vote)) {
// set the owning side to null (unless already changed)
if ($vote->getProfile() === $this) {
$vote->setProfile(null);
}
}
return $this;
}
/**
* @return Collection<int, Stack>
*/
public function getStacks(): Collection
{
return $this->stacks;
}
public function addStack(Stack $stack): self
{
if (!$this->stacks->contains($stack)) {
$this->stacks->add($stack);
$stack->setProfile($this);
}
return $this;
}
public function removeStack(Stack $stack): self
{
if ($this->stacks->removeElement($stack)) {
// set the owning side to null (unless already changed)
if ($stack->getProfile() === $this) {
$stack->setProfile(null);
}
}
return $this;
}
}