You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
4.8 KiB

<?php
namespace App\Entity;
use App\Repository\ProfilRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: ProfilRepository::class)]
#[UniqueEntity(fields: ['name'], message: 'There is already an account with this name')]
class Profil implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
private array $roles = [];
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $description = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $password = null;
/**
* @var Collection<int, Post>
*/
#[ORM\OneToMany(targetEntity: Post::class, mappedBy: 'profil')]
private Collection $posts;
/**
* @var Collection<int, Commentary>
*/
#[ORM\OneToMany(targetEntity: Commentary::class, mappedBy: 'profil')]
private Collection $commentaries;
/**
* @var Collection<int, self>
*/
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'followers')]
private Collection $followers;
public function __construct()
{
$this->posts = new ArrayCollection();
$this->commentaries = new ArrayCollection();
$this->followers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(?string $password): static
{
$this->password = $password;
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): static
{
if (!$this->posts->contains($post)) {
$this->posts->add($post);
$post->setProfil($this);
}
return $this;
}
public function removePost(Post $post): static
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getProfil() === $this) {
$post->setProfil(null);
}
}
return $this;
}
/**
* @return Collection<int, Commentary>
*/
public function getCommentaries(): Collection
{
return $this->commentaries;
}
public function addCommentary(Commentary $commentary): static
{
if (!$this->commentaries->contains($commentary)) {
$this->commentaries->add($commentary);
$commentary->setProfil($this);
}
return $this;
}
public function removeCommentary(Commentary $commentary): static
{
if ($this->commentaries->removeElement($commentary)) {
// set the owning side to null (unless already changed)
if ($commentary->getProfil() === $this) {
$commentary->setProfil(null);
}
}
return $this;
}
/**
* @return Collection<int, self>
*/
public function getFollowers(): Collection
{
return $this->followers;
}
public function addFollower(self $follower): static
{
if (!$this->followers->contains($follower)) {
$this->followers->add($follower);
}
return $this;
}
public function removeFollower(self $follower): static
{
$this->followers->removeElement($follower);
return $this;
}
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function eraseCredentials(): void
{
// TODO: Implement eraseCredentials() method.
}
public function getUserIdentifier(): string
{
return $this->name;
}
}