You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
435 lines
10 KiB
PHP
435 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
/**
|
|
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
|
|
*/
|
|
class User implements UserInterface
|
|
{
|
|
/**
|
|
* @var int The internal ID of user
|
|
*
|
|
* @ORM\Id()
|
|
* @ORM\GeneratedValue()
|
|
* @ORM\Column(type="integer")
|
|
*/
|
|
private int $id;
|
|
|
|
/**
|
|
* @var string The user email
|
|
*
|
|
* @ORM\Column(type="string", length=180, unique=true)
|
|
*/
|
|
private string $email;
|
|
|
|
/**
|
|
* @var array The list of user's roles
|
|
*
|
|
* @ORM\Column(type="json")
|
|
*/
|
|
private array $roles = [];
|
|
|
|
/**
|
|
* @var string The hashed password
|
|
*
|
|
* @ORM\Column(type="string")
|
|
*/
|
|
private string $password;
|
|
|
|
/**
|
|
* @var string The user name
|
|
*
|
|
* @ORM\Column(type="string", length=255)
|
|
*/
|
|
private string $name;
|
|
|
|
/**
|
|
* @var string|null The user first name
|
|
*
|
|
* @ORM\Column(type="string", length=255, nullable=true)
|
|
*/
|
|
private ?string $fist_name;
|
|
|
|
/**
|
|
* @var int The user gender
|
|
* 0 = no gender
|
|
* 1 = male
|
|
* 2 = femalle
|
|
* 3 = genderqueer
|
|
*
|
|
* @ORM\Column(type="smallint")
|
|
*/
|
|
private int $gender;
|
|
|
|
/**
|
|
* @var string|null The user avatar relative path
|
|
*
|
|
* @ORM\Column(type="string", length=255, nullable=true)
|
|
*/
|
|
private ?string $avatar;
|
|
|
|
/**
|
|
* @var Language The user language
|
|
*
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Language")
|
|
*/
|
|
private Language $language;
|
|
|
|
/**
|
|
* @var ArrayCollection The user {@see User friends}
|
|
*
|
|
* @ORM\ManyToMany(targetEntity="App\Entity\User")
|
|
*/
|
|
private ArrayCollection $friends;
|
|
|
|
/**
|
|
* @var ArrayCollection The user {@see ConfigNotification configured notifications}
|
|
*
|
|
* @ORM\OneToMany(targetEntity="App\Entity\ConfigNotification", mappedBy="user", orphanRemoval=true)
|
|
*/
|
|
private ArrayCollection $configNotifications;
|
|
|
|
/**
|
|
* @var ArrayCollection Thue user {@see UserNotification notifications}
|
|
*
|
|
* @ORM\OneToMany(targetEntity="App\Entity\UserNotification", mappedBy="user", orphanRemoval=true)
|
|
*/
|
|
private ArrayCollection $notifications;
|
|
|
|
/**
|
|
* @var ArrayCollection The user owned {@see Wish wishes}
|
|
*
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Wish", mappedBy="owner")
|
|
*/
|
|
private ArrayCollection $ownedWishes;
|
|
|
|
/**
|
|
* @var ArrayCollection The user {@see Participant participations}
|
|
*
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Participant", mappedBy="user", orphanRemoval=true)
|
|
*/
|
|
private ArrayCollection $participations;
|
|
|
|
/**
|
|
* @var ArrayCollection The user {@see Comment comments}
|
|
*
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="user", orphanRemoval=true)
|
|
*/
|
|
private ArrayCollection $comments;
|
|
|
|
public function __construct () {
|
|
$this->friends = new ArrayCollection();
|
|
$this->configNotifications = new ArrayCollection();
|
|
$this->notifications = new ArrayCollection();
|
|
$this->ownedWishes = new ArrayCollection();
|
|
$this->participations = new ArrayCollection();
|
|
$this->comments = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getEmail(): ?string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setEmail(string $email): self
|
|
{
|
|
$this->email = $email;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* A visual identifier that represents this user.
|
|
*
|
|
* @see UserInterface
|
|
*/
|
|
public function getUsername(): string
|
|
{
|
|
return (string) $this->email;
|
|
}
|
|
|
|
/**
|
|
* @see UserInterface
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* @see UserInterface
|
|
*/
|
|
public function getPassword(): string
|
|
{
|
|
return (string) $this->password;
|
|
}
|
|
|
|
public function setPassword(string $password): self
|
|
{
|
|
$this->password = $password;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @see UserInterface
|
|
*/
|
|
public function getSalt()
|
|
{
|
|
// not needed when using the "bcrypt" algorithm in security.yaml
|
|
}
|
|
|
|
/**
|
|
* @see UserInterface
|
|
*/
|
|
public function eraseCredentials()
|
|
{
|
|
// If you store any temporary, sensitive data on the user, clear it here
|
|
// $this->plainPassword = null;
|
|
}
|
|
|
|
public function getName (): ?string {
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName (string $name): self {
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFistname (): ?string {
|
|
return $this->fist_name;
|
|
}
|
|
|
|
public function setFistname (?string $fist_name): self {
|
|
$this->fist_name = $fist_name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getGender (): ?int {
|
|
return $this->gender;
|
|
}
|
|
|
|
public function setGender (int $gender): self {
|
|
$this->gender = $gender;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAvatar (): ?string {
|
|
return $this->avatar;
|
|
}
|
|
|
|
public function setAvatar (?string $avatar): self {
|
|
$this->avatar = $avatar;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getLanguage (): ?Language {
|
|
return $this->language;
|
|
}
|
|
|
|
public function setLanguage (?Language $language): self {
|
|
$this->language = $language;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|self[]
|
|
*/
|
|
public function getFriends (): Collection {
|
|
return $this->friends;
|
|
}
|
|
|
|
public function addFriend (self $friend): self {
|
|
if (!$this->friends->contains($friend)) {
|
|
$this->friends[] = $friend;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeFriend (self $friend): self {
|
|
if ($this->friends->contains($friend)) {
|
|
$this->friends->removeElement($friend);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|ConfigNotification[]
|
|
*/
|
|
public function getConfigNotifications (): Collection {
|
|
return $this->configNotifications;
|
|
}
|
|
|
|
public function addConfigNotification (ConfigNotification $configNotification): self {
|
|
if (!$this->configNotifications->contains($configNotification)) {
|
|
$this->configNotifications[] = $configNotification;
|
|
$configNotification->setUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeConfigNotification (ConfigNotification $configNotification): self {
|
|
if ($this->configNotifications->contains($configNotification)) {
|
|
$this->configNotifications->removeElement($configNotification);
|
|
// set the owning side to null (unless already changed)
|
|
if ($configNotification->getUser() === $this) {
|
|
$configNotification->setUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|UserNotification[]
|
|
*/
|
|
public function getNotifications (): Collection {
|
|
return $this->notifications;
|
|
}
|
|
|
|
public function addNotification (UserNotification $notification): self {
|
|
if (!$this->notifications->contains($notification)) {
|
|
$this->notifications[] = $notification;
|
|
$notification->setUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeNotification (UserNotification $notification): self {
|
|
if ($this->notifications->contains($notification)) {
|
|
$this->notifications->removeElement($notification);
|
|
// set the owning side to null (unless already changed)
|
|
if ($notification->getUser() === $this) {
|
|
$notification->setUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Wish[]
|
|
*/
|
|
public function getOwnedWishes(): Collection
|
|
{
|
|
return $this->ownedWishes;
|
|
}
|
|
|
|
public function addOwnedWish(Wish $ownedWish): self
|
|
{
|
|
if (!$this->ownedWishes->contains($ownedWish)) {
|
|
$this->ownedWishes[] = $ownedWish;
|
|
$ownedWish->setOwner($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeOwnedWish(Wish $ownedWish): self
|
|
{
|
|
if ($this->ownedWishes->contains($ownedWish)) {
|
|
$this->ownedWishes->removeElement($ownedWish);
|
|
// set the owning side to null (unless already changed)
|
|
if ($ownedWish->getOwner() === $this) {
|
|
$ownedWish->setOwner(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Participant[]
|
|
*/
|
|
public function getParticipations(): Collection
|
|
{
|
|
return $this->participations;
|
|
}
|
|
|
|
public function addParticipation(Participant $participation): self
|
|
{
|
|
if (!$this->participations->contains($participation)) {
|
|
$this->participations[] = $participation;
|
|
$participation->setUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeParticipation(Participant $participation): self
|
|
{
|
|
if ($this->participations->contains($participation)) {
|
|
$this->participations->removeElement($participation);
|
|
// set the owning side to null (unless already changed)
|
|
if ($participation->getUser() === $this) {
|
|
$participation->setUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Comment[]
|
|
*/
|
|
public function getComments(): Collection
|
|
{
|
|
return $this->comments;
|
|
}
|
|
|
|
public function addComment(Comment $comment): self
|
|
{
|
|
if (!$this->comments->contains($comment)) {
|
|
$this->comments[] = $comment;
|
|
$comment->setUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeComment(Comment $comment): self
|
|
{
|
|
if ($this->comments->contains($comment)) {
|
|
$this->comments->removeElement($comment);
|
|
// set the owning side to null (unless already changed)
|
|
if ($comment->getUser() === $this) {
|
|
$comment->setUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|