<?php
namespace App\Entity;
use App\Repository\CurrencyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use App\Entity\Traits\TimeStampableTrait;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: CurrencyRepository::class)]
#[UniqueEntity(
fields: ['name',],
errorPath: 'name',
message: 'Le nom que vous avez saisi est déjà utilisé',
)]
#[UniqueEntity(
fields: ['code',],
errorPath: 'code',
message: 'Le code que vous avez saisi est déjà utilisé',
)]
#[UniqueEntity(
fields: ['symbol',],
errorPath: 'symbol',
message: 'Le symbol que vous avez saisi est déjà utilisé',
)]
class Currency
{
use TimeStampableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(["entity:write", "activiteBailleur:read", "currency:read", 'activity:read'])]
private ?int $id = null;
#[ORM\Column(length: 26)]
#[Groups(["entity:write", "activiteBailleur:read", "currency:read", 'activity:read'])]
#[Assert\NotBlank(message: "Veuillez remplir ce champ")]
private ?string $name = null;
#[ORM\Column(length: 8, nullable: true)]
#[Groups(["entity:write", "activiteBailleur:read", "currency:read", 'activity:read'])]
#[Assert\NotBlank(message: "Veuillez remplir ce champ")]
private ?string $code = null;
#[ORM\Column(length: 6)]
#[Groups(["entity:write"])]
#[Assert\NotBlank(message: "Veuillez remplir ce champ")]
private ?string $symbol = null;
#[ORM\ManyToOne]
private ?User $createdBy = null;
#[ORM\OneToMany(mappedBy: 'currency', targetEntity: Projet::class)]
private Collection $projets;
#[ORM\OneToMany(mappedBy: 'currency', targetEntity: ActiviteBailleur::class)]
private Collection $activiteBailleurs;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$this->projets = new ArrayCollection();
$this->isEnabled = false;
$this->activiteBailleurs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getSymbol(): ?string
{
return $this->symbol;
}
public function setSymbol(string $symbol): self
{
$this->symbol = $symbol;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
/**
* @return Collection<int, Projet>
*/
public function getProjets(): Collection
{
return $this->projets;
}
public function addProjet(Projet $projet): self
{
if (!$this->projets->contains($projet)) {
$this->projets->add($projet);
$projet->setCurrency($this);
}
return $this;
}
public function removeProjet(Projet $projet): self
{
if ($this->projets->removeElement($projet)) {
// set the owning side to null (unless already changed)
if ($projet->getCurrency() === $this) {
$projet->setCurrency(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->name;
}
/**
* @return Collection<int, ActiviteBailleur>
*/
public function getActiviteBailleurs(): Collection
{
return $this->activiteBailleurs;
}
public function addActiviteBailleur(ActiviteBailleur $activiteBailleur): static
{
if (!$this->activiteBailleurs->contains($activiteBailleur)) {
$this->activiteBailleurs->add($activiteBailleur);
$activiteBailleur->setCurrency($this);
}
return $this;
}
public function removeActiviteBailleur(ActiviteBailleur $activiteBailleur): static
{
if ($this->activiteBailleurs->removeElement($activiteBailleur)) {
// set the owning side to null (unless already changed)
if ($activiteBailleur->getCurrency() === $this) {
$activiteBailleur->setCurrency(null);
}
}
return $this;
}
}