src/Entity/Currency.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CurrencyRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use App\Entity\Traits\TimeStampableTrait;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClass: CurrencyRepository::class)]
  12. #[UniqueEntity(
  13.     fields: ['name',],
  14.     errorPath: 'name',
  15.     message: 'Le nom que vous avez saisi est déjà utilisé',
  16. )]
  17. #[UniqueEntity(
  18.     fields: ['code',],
  19.     errorPath: 'code',
  20.     message: 'Le code que vous avez saisi est déjà utilisé',
  21. )]
  22. #[UniqueEntity(
  23.     fields: ['symbol',],
  24.     errorPath: 'symbol',
  25.     message: 'Le symbol que vous avez saisi est déjà utilisé',
  26. )]
  27. class Currency
  28. {
  29.     use TimeStampableTrait;
  30.     #[ORM\Id]
  31.     #[ORM\GeneratedValue]
  32.     #[ORM\Column]
  33.     #[Groups(["entity:write", "activiteBailleur:read", "currency:read", 'activity:read'])]
  34.     private ?int $id = null;
  35.     #[ORM\Column(length: 26)]
  36.     #[Groups(["entity:write", "activiteBailleur:read", "currency:read", 'activity:read'])]
  37.     #[Assert\NotBlank(message: "Veuillez remplir ce champ")]
  38.     private ?string $name = null;
  39.     #[ORM\Column(length: 8, nullable: true)]
  40.     #[Groups(["entity:write", "activiteBailleur:read", "currency:read", 'activity:read'])]
  41.     #[Assert\NotBlank(message: "Veuillez remplir ce champ")]
  42.     private ?string $code = null;
  43.     #[ORM\Column(length: 6)]
  44.     #[Groups(["entity:write"])]
  45.     #[Assert\NotBlank(message: "Veuillez remplir ce champ")]
  46.     private ?string $symbol = null;
  47.     #[ORM\ManyToOne]
  48.     private ?User $createdBy = null;
  49.     #[ORM\OneToMany(mappedBy: 'currency', targetEntity: Projet::class)]
  50.     private Collection $projets;
  51.     #[ORM\OneToMany(mappedBy: 'currency', targetEntity: ActiviteBailleur::class)]
  52.     private Collection $activiteBailleurs;
  53.     public function __construct()
  54.     {
  55.         $this->createdAt = new \DateTimeImmutable();
  56.         $this->updatedAt = new \DateTimeImmutable();
  57.         $this->projets = new ArrayCollection();
  58.         $this->isEnabled = false;
  59.         $this->activiteBailleurs = new ArrayCollection();
  60.     }
  61.     public function getId(): ?int
  62.     {
  63.         return $this->id;
  64.     }
  65.     public function getName(): ?string
  66.     {
  67.         return $this->name;
  68.     }
  69.     public function setName(string $name): self
  70.     {
  71.         $this->name = $name;
  72.         return $this;
  73.     }
  74.     public function getCode(): ?string
  75.     {
  76.         return $this->code;
  77.     }
  78.     public function setCode(?string $code): self
  79.     {
  80.         $this->code = $code;
  81.         return $this;
  82.     }
  83.     public function getSymbol(): ?string
  84.     {
  85.         return $this->symbol;
  86.     }
  87.     public function setSymbol(string $symbol): self
  88.     {
  89.         $this->symbol = $symbol;
  90.         return $this;
  91.     }
  92.     public function getCreatedBy(): ?User
  93.     {
  94.         return $this->createdBy;
  95.     }
  96.     public function setCreatedBy(?User $createdBy): self
  97.     {
  98.         $this->createdBy = $createdBy;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return Collection<int, Projet>
  103.      */
  104.     public function getProjets(): Collection
  105.     {
  106.         return $this->projets;
  107.     }
  108.     public function addProjet(Projet $projet): self
  109.     {
  110.         if (!$this->projets->contains($projet)) {
  111.             $this->projets->add($projet);
  112.             $projet->setCurrency($this);
  113.         }
  114.         return $this;
  115.     }
  116.     public function removeProjet(Projet $projet): self
  117.     {
  118.         if ($this->projets->removeElement($projet)) {
  119.             // set the owning side to null (unless already changed)
  120.             if ($projet->getCurrency() === $this) {
  121.                 $projet->setCurrency(null);
  122.             }
  123.         }
  124.         return $this;
  125.     }
  126.     public function __toString(): string
  127.     {
  128.         return $this->name;
  129.     }
  130.     /**
  131.      * @return Collection<int, ActiviteBailleur>
  132.      */
  133.     public function getActiviteBailleurs(): Collection
  134.     {
  135.         return $this->activiteBailleurs;
  136.     }
  137.     public function addActiviteBailleur(ActiviteBailleur $activiteBailleur): static
  138.     {
  139.         if (!$this->activiteBailleurs->contains($activiteBailleur)) {
  140.             $this->activiteBailleurs->add($activiteBailleur);
  141.             $activiteBailleur->setCurrency($this);
  142.         }
  143.         return $this;
  144.     }
  145.     public function removeActiviteBailleur(ActiviteBailleur $activiteBailleur): static
  146.     {
  147.         if ($this->activiteBailleurs->removeElement($activiteBailleur)) {
  148.             // set the owning side to null (unless already changed)
  149.             if ($activiteBailleur->getCurrency() === $this) {
  150.                 $activiteBailleur->setCurrency(null);
  151.             }
  152.         }
  153.         return $this;
  154.     }
  155. }