src/Entity/Bailleur.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\BailleurRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. #[ORM\Entity(repositoryClass: BailleurRepository::class)]
  12. #[UniqueEntity(
  13.     fields: ['email',],
  14.     errorPath: 'email',
  15.     message: 'Adresse e-mail déjà utilisée',
  16. )]
  17. #[UniqueEntity(
  18.     fields: ['name',],
  19.     errorPath: 'name',
  20.     message: 'Le nom que vous avez saisi est déjà utilisé',
  21. )]
  22. #[ORM\HasLifecycleCallbacks]
  23. class Bailleur
  24. {
  25.     use TimeStampable;
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue]
  28.     #[ORM\Column]
  29.     #[Groups(["projetBailleur:read", "entity:write", "activiteBailleur:read",'activity:read'])]
  30.     private ?int $id = null;
  31.     #[ORM\Column(length: 255)]
  32.     #[Groups(["projetBailleur:read", "entity:write", "activiteBailleur:read", 'activity:read'])]
  33.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  34.     private ?string $name = null;
  35.     #[ORM\Column(length: 255)]
  36.     #[Groups(["projetBailleur:read", "entity:write", "activiteBailleur:read", 'activity:read'])]
  37.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  38.     private ?string $sigle = null;
  39.     #[ORM\Column(length: 255)]
  40.     #[Groups(["projetBailleur:read", "entity:write", "activiteBailleur:read", 'activity:read'])]
  41.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  42.     private ?string $siege = null;
  43.     #[ORM\OneToMany(mappedBy: 'bailleur', targetEntity: ProjetBailleur::class)]
  44.     private Collection $projetBailleurs;
  45.     #[ORM\Column(length: 255)]
  46.     #[Groups(["entity:write"])]
  47.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  48.     private ?string $phone = null;
  49.     #[ORM\Column(length: 255)]
  50.     #[Groups(["entity:write"])]
  51.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  52.     #[Assert\Email(message: "Veuillez entrez un email correcte")]
  53.     private ?string $email = null;
  54.     #[ORM\ManyToOne(inversedBy: 'bailleurs')]
  55.     private ?User $createdBy = null;
  56.     #[ORM\OneToMany(mappedBy: 'bailleur', targetEntity: ActiviteBailleur::class)]
  57.     private Collection $activiteBailleurs;
  58.     public function  __construct()
  59.     {
  60.         $this->projetBailleurs = new ArrayCollection();
  61.         $this->createdAt = new \DateTimeImmutable();
  62.         $this->updatedAt = new \DateTimeImmutable();
  63.         $this->activiteBailleurs = new ArrayCollection();
  64.     }
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getName(): ?string
  70.     {
  71.         return $this->name;
  72.     }
  73.     public function setName(string $name): self
  74.     {
  75.         $this->name = $name;
  76.         return $this;
  77.     }
  78.     public function getSigle(): ?string
  79.     {
  80.         return $this->sigle;
  81.     }
  82.     public function setSigle(string $sigle): self
  83.     {
  84.         $this->sigle = $sigle;
  85.         return $this;
  86.     }
  87.     public function getSiege(): ?string
  88.     {
  89.         return $this->siege;
  90.     }
  91.     public function setSiege(string $siege): self
  92.     {
  93.         $this->siege = $siege;
  94.         return $this;
  95.     }
  96.     /**
  97.      * @return Collection<int, ProjetBailleur>
  98.      */
  99.     public function getProjetBailleurs(): Collection
  100.     {
  101.         return $this->projetBailleurs;
  102.     }
  103.     public function addProjetBailleur(ProjetBailleur $projetBailleur): self
  104.     {
  105.         if (!$this->projetBailleurs->contains($projetBailleur)) {
  106.             $this->projetBailleurs->add($projetBailleur);
  107.             $projetBailleur->setBailleur($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeProjetBailleur(ProjetBailleur $projetBailleur): self
  112.     {
  113.         if ($this->projetBailleurs->removeElement($projetBailleur)) {
  114.             // set the owning side to null (unless already changed)
  115.             if ($projetBailleur->getBailleur() === $this) {
  116.                 $projetBailleur->setBailleur(null);
  117.             }
  118.         }
  119.         return $this;
  120.     }
  121.     public function getPhone(): ?string
  122.     {
  123.         return $this->phone;
  124.     }
  125.     public function setPhone(string $phone): static
  126.     {
  127.         $this->phone = $phone;
  128.         return $this;
  129.     }
  130.     public function getEmail(): ?string
  131.     {
  132.         return $this->email;
  133.     }
  134.     public function setEmail(string $email): static
  135.     {
  136.         $this->email = $email;
  137.         return $this;
  138.     }
  139.     public function getCreatedBy(): ?User
  140.     {
  141.         return $this->createdBy;
  142.     }
  143.     public function setCreatedBy(?User $createdBy): static
  144.     {
  145.         $this->createdBy = $createdBy;
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection<int, ActiviteBailleur>
  150.      */
  151.     public function getActiviteBailleurs(): Collection
  152.     {
  153.         return $this->activiteBailleurs;
  154.     }
  155.     public function addActiviteBailleur(ActiviteBailleur $activiteBailleur): static
  156.     {
  157.         if (!$this->activiteBailleurs->contains($activiteBailleur)) {
  158.             $this->activiteBailleurs->add($activiteBailleur);
  159.             $activiteBailleur->setBailleur($this);
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeActiviteBailleur(ActiviteBailleur $activiteBailleur): static
  164.     {
  165.         if ($this->activiteBailleurs->removeElement($activiteBailleur)) {
  166.             // set the owning side to null (unless already changed)
  167.             if ($activiteBailleur->getBailleur() === $this) {
  168.                 $activiteBailleur->setBailleur(null);
  169.             }
  170.         }
  171.         return $this;
  172.     }
  173.     public function __toString(): string
  174.     {
  175.         return $this->name;
  176.     }
  177. }