caisse-bliss/src/Entity/User.php
2025-02-17 17:51:01 +01:00

433 lines
10 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
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;
use ApiPlatform\Metadata\ApiResource;
use \App\Entity\GroupOfProducts;
use \App\Entity\Product;
use \App\Entity\Selling;
#[ApiResource(paginationEnabled: false)]
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[ORM\Column(length: 180)]
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;
#[ORM\Column]
private bool $isVerified = false;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $last_login = null;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Festival $currentFestival = null;
/**
* @var Collection<int, Expense>
*/
#[ORM\OneToMany(targetEntity: Expense::class, mappedBy: 'user')]
private Collection $expenses;
/**
* @var Collection<int, Product>
*/
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'user')]
private Collection $products;
/**
* @var Collection<int, Festival>
*/
#[ORM\OneToMany(targetEntity: Festival::class, mappedBy: 'user')]
private Collection $festivals;
/**
* @var Collection<int, SerieFestival>
*/
#[ORM\OneToMany(targetEntity: SerieFestival::class, mappedBy: 'user')]
private Collection $seriesFestival;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
private ?Festival $activeFestival = null;
/**
* @var Collection<int, GroupOfProducts>
*/
#[ORM\OneToMany(targetEntity: GroupOfProducts::class, mappedBy: 'owner')]
private Collection $groupOfProducts;
/**
* @var Collection<int, Selling>
*/
#[ORM\OneToMany(targetEntity: Selling::class, mappedBy: 'owner')]
private Collection $sellings;
public function __construct()
{
$this->expenses = new ArrayCollection();
$this->products = new ArrayCollection();
$this->festivals = new ArrayCollection();
$this->seriesFestival = new ArrayCollection();
$this->groupOfProducts = new ArrayCollection();
$this->sellings = 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;
}
public function getExpenses(): ?object
{
return $this->expenses;
}
public function setExpenses(?object $expenses): static
{
$this->expenses = $expenses;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): static
{
$this->isVerified = $isVerified;
return $this;
}
public function getCurrentFestival(): ?object
{
return $this->currentFestival;
}
public function setCurrentFestival(?object $currentFestival): static
{
$this->currentFestival = $currentFestival;
return $this;
}
public function addExpense(Expense $expense): static
{
if (!$this->expenses->contains($expense)) {
$this->expenses->add($expense);
$expense->setUser($this);
}
return $this;
}
public function removeExpense(Expense $expense): static
{
if ($this->expenses->removeElement($expense)) {
// set the owning side to null (unless already changed)
if ($expense->getUser() === $this) {
$expense->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setUser($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getUser() === $this) {
$product->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Festival>
*/
public function getFestivals(): Collection
{
return $this->festivals;
}
public function addFestival(Festival $festival): static
{
if (!$this->festivals->contains($festival)) {
$this->festivals->add($festival);
$festival->setUser($this);
}
return $this;
}
public function removeFestival(Festival $festival): static
{
if ($this->festivals->removeElement($festival)) {
// set the owning side to null (unless already changed)
if ($festival->getUser() === $this) {
$festival->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, SerieFestival>
*/
public function getSeriesFestival(): Collection
{
return $this->seriesFestival;
}
public function addSeriesFestival(SerieFestival $seriesFestival): static
{
if (!$this->seriesFestival->contains($seriesFestival)) {
$this->seriesFestival->add($seriesFestival);
$seriesFestival->setUser($this);
}
return $this;
}
public function removeSeriesFestival(SerieFestival $seriesFestival): static
{
if ($this->seriesFestival->removeElement($seriesFestival)) {
// set the owning side to null (unless already changed)
if ($seriesFestival->getUser() === $this) {
$seriesFestival->setUser(null);
}
}
return $this;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->last_login;
}
public function setLastLogin(?\DateTimeInterface $last_login): static
{
$this->last_login = $last_login;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getActiveFestival(): ?Festival
{
return $this->activeFestival;
}
public function setActiveFestival(?Festival $activeFestival): static
{
$this->activeFestival = $activeFestival;
return $this;
}
/**
* @return Collection<int, GroupOfProducts>
*/
public function getGroupOfProducts(): Collection
{
return $this->groupOfProducts;
}
public function addGroupOfProduct(GroupOfProducts $groupOfProduct): static
{
if (!$this->groupOfProducts->contains($groupOfProduct)) {
$this->groupOfProducts->add($groupOfProduct);
$groupOfProduct->setOwner($this);
}
return $this;
}
public function removeGroupOfProduct(GroupOfProducts $groupOfProduct): static
{
if ($this->groupOfProducts->removeElement($groupOfProduct)) {
// set the owning side to null (unless already changed)
if ($groupOfProduct->getOwner() === $this) {
$groupOfProduct->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Selling>
*/
public function getSellings(): Collection
{
return $this->sellings;
}
public function addSelling(Selling $selling): static
{
if (!$this->sellings->contains($selling)) {
$this->sellings->add($selling);
$selling->setOwner($this);
}
return $this;
}
public function removeSelling(Selling $selling): static
{
if ($this->sellings->removeElement($selling)) {
// set the owning side to null (unless already changed)
if ($selling->getOwner() === $this) {
$selling->setOwner(null);
}
}
return $this;
}
}