123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- namespace App\Entity;
- use App\Repository\UserRepository;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- use Symfony\Component\Validator\Constraints as Assert;
- #[ORM\Entity(repositoryClass: UserRepository::class)]
- #[ORM\Table(name: '`user`')]
- #[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
- #[UniqueEntity('email')]
- class User implements UserInterface, PasswordAuthenticatedUserInterface
- {
- #[ORM\Id]
- #[ORM\GeneratedValue]
- #[ORM\Column]
- private ?int $id = null;
- #[ORM\Column(length: 180)]
- #[Assert\Email]
- private ?string $email = null;
- /**
- * @var list<string> The user roles
- */
- #[ORM\Column]
- private array $roles = [];
- /**
- * @var string The hashed password
- */
- #[ORM\Column]
- private ?string $password = null;
- /**
- * @var Collection<int, CommonList>
- */
- #[ORM\OneToMany(targetEntity: CommonList::class, mappedBy: 'addedBy')]
- private Collection $commonLists;
- /**
- * @var Collection<int, UserList>
- */
- #[ORM\OneToMany(targetEntity: UserList::class, mappedBy: 'viewer', orphanRemoval: true)]
- private Collection $userLists;
- #[ORM\Column(length: 255, nullable: true)]
- private ?string $name = null;
- public function __construct()
- {
- $this->commonLists = new ArrayCollection();
- $this->userLists = new ArrayCollection();
- }
- public function getId(): ?int
- {
- return $this->id;
- }
- public function getEmail(): ?string
- {
- return $this->email;
- }
- public function setEmail(string $email): static
- {
- $this->email = $email;
- return $this;
- }
- /**
- * A visual identifier that represents this user.
- *
- * @see UserInterface
- */
- public function getUserIdentifier(): string
- {
- return (string) $this->email;
- }
- /**
- * @see UserInterface
- *
- * @return list<string>
- */
- public function getRoles(): array
- {
- $roles = $this->roles;
- // guarantee every user at least has ROLE_USER
- $roles[] = 'ROLE_USER';
- return array_unique($roles);
- }
- /**
- * @param list<string> $roles
- */
- public function setRoles(array $roles): static
- {
- $this->roles = $roles;
- return $this;
- }
- /**
- * @see PasswordAuthenticatedUserInterface
- */
- public function getPassword(): ?string
- {
- return $this->password;
- }
- public function setPassword(string $password): static
- {
- $this->password = $password;
- return $this;
- }
- /**
- * @see UserInterface
- */
- public function eraseCredentials(): void
- {
- // If you store any temporary, sensitive data on the user, clear it here
- // $this->plainPassword = null;
- }
- /**
- * @return Collection<int, CommonList>
- */
- public function getCommonLists(): Collection
- {
- return $this->commonLists;
- }
- public function addCommonList(CommonList $commonList): static
- {
- if (!$this->commonLists->contains($commonList)) {
- $this->commonLists->add($commonList);
- $commonList->setAddedBy($this);
- }
- return $this;
- }
- public function removeCommonList(CommonList $commonList): static
- {
- if ($this->commonLists->removeElement($commonList)) {
- // set the owning side to null (unless already changed)
- if ($commonList->getAddedBy() === $this) {
- $commonList->setAddedBy(null);
- }
- }
- return $this;
- }
- /**
- * @return Collection<int, UserList>
- */
- public function getUserLists(): Collection
- {
- return $this->userLists;
- }
- public function addUserList(UserList $userList): static
- {
- if (!$this->userLists->contains($userList)) {
- $this->userLists->add($userList);
- $userList->setViewer($this);
- }
- return $this;
- }
- public function removeUserList(UserList $userList): static
- {
- if ($this->userLists->removeElement($userList)) {
- // set the owning side to null (unless already changed)
- if ($userList->getViewer() === $this) {
- $userList->setViewer(null);
- }
- }
- return $this;
- }
- public function getName(): ?string
- {
- return $this->name;
- }
- public function setName(?string $name): static
- {
- $this->name = $name;
- return $this;
- }
- public function getPseudo(): string
- {
- return $this->getName() ?? $this->getEmail();
- }
- }
|