src/Entity/Structure.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\StructureRepository;
  5. use DateTimeImmutable;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Doctrine\DBAL\Types\Types;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. #[ORM\Entity(repositoryClass: StructureRepository::class)]
  14. #[UniqueEntity(
  15.     fields: ['name',],
  16.     errorPath: 'name',
  17.     message: 'Le nom que vous avez saisi est déjà utilisé',
  18. )]
  19. #[UniqueEntity(
  20.     fields: ['acronym',],
  21.     errorPath: 'acronym',
  22.     message: 'L\' acronyme que vous avez saisi est déjà utilisé',
  23. )]
  24. #[UniqueEntity(
  25.     fields: ['phone',],
  26.     errorPath: 'phone',
  27.     message: 'Le numero que vous avez saisi est déjà utilisé',
  28. )]
  29. #[ORM\HasLifecycleCallbacks]
  30. class Structure
  31. {
  32.     use TimeStampable;
  33.     #[ORM\Id]
  34.     #[ORM\GeneratedValue]
  35.     #[ORM\Column]
  36.     #[Groups(["entity:write"])]
  37.     private ?int $id = null;
  38.     #[ORM\Column(length: 255)]
  39.     #[Groups(['user:read', 'membre:read', 'meetParticipant:read', 'entity:write'])]
  40.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  41.     private ?string $name = null;
  42.     #[ORM\Column(length: 15)]
  43.     #[Groups(["entity:write"])]
  44.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  45.     private ?string $acronym = null;
  46.     #[ORM\Column(length: 255, nullable:true)]
  47.     private ?string $sector = null;
  48.     #[ORM\Column(length: 30, nullable: true)]
  49.     #[Groups(["entity:write"])]
  50.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  51.     private ?string $phone = null;
  52.     #[ORM\Column(type: Types::TEXT, nullable: true)]
  53.     #[Groups(["entity:write"])]
  54.     private ?string $description = null;
  55.     #[ORM\Column(length: 255, nullable: true)]
  56.     #[Groups(["entity:write"])]
  57.     private ?string $email = null;
  58.     #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'subStructures')]
  59.     private ?self $parent = null;
  60.     #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
  61.     private Collection $subStructures;
  62.     #[ORM\ManyToOne(targetEntity: StructureType::class, inversedBy:'structures')]
  63.     #[Groups(["entity:write"])]
  64.     // #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  65.     private ?StructureType $structureType = null;
  66.     #[ORM\OneToMany(mappedBy: 'structure', targetEntity: Meeting::class)]
  67.     private Collection $meetings;
  68.     #[ORM\ManyToOne(inversedBy: 'structures')]
  69.     private ?User $createdBy = null;
  70.     #[ORM\OneToMany(mappedBy: 'structure', targetEntity: Pao::class)]
  71.     private Collection $paos;
  72.     #[ORM\OneToMany(mappedBy: 'structure', targetEntity: Decision::class)]
  73.     private Collection $decisions;
  74.     public function __construct()
  75.     {
  76.         $this->subStructures = new ArrayCollection();
  77.         $this->createdAt = new \DateTimeImmutable();
  78.         $this->updatedAt = new \DateTimeImmutable();
  79.         $this->paos = new ArrayCollection();
  80.         $this->meetings = new ArrayCollection();
  81.         $this->decisions = new ArrayCollection();
  82.     }
  83.     public function getId(): ?int
  84.     {
  85.         return $this->id;
  86.     }
  87.     public function getMeetings(): Collection
  88.     {
  89.         return $this->meetings;
  90.     }
  91.     public function getName(): ?string
  92.     {
  93.         return $this->name;
  94.     }
  95.     public function setName(string $name): self
  96.     {
  97.         $this->name = $name;
  98.         return $this;
  99.     }
  100.     public function getAcronym(): ?string
  101.     {
  102.         return $this->acronym;
  103.     }
  104.     public function setAcronym(string $acronym): self
  105.     {
  106.         $this->acronym = $acronym;
  107.         return $this;
  108.     }
  109.     public function getSector(): ?string
  110.     {
  111.         return $this->sector;
  112.     }
  113.     public function setSector(?string $sector): self
  114.     {
  115.         $this->sector = $sector;
  116.         return $this;
  117.     }
  118.     public function getPhone(): ?string
  119.     {
  120.         return $this->phone;
  121.     }
  122.     public function setPhone(?string $phone): self
  123.     {
  124.         $this->phone = $phone;
  125.         return $this;
  126.     }
  127.     public function getEmail(): ?string
  128.     {
  129.         return $this->email;
  130.     }
  131.     public function setEmail(?string $email): self
  132.     {
  133.         $this->email = $email;
  134.         return $this;
  135.     }
  136.     public function getCreatedAt(): ?DateTimeImmutable
  137.     {
  138.         return $this->createdAt;
  139.     }
  140.     public function setCreatedAt(DateTimeImmutable $createdAt): self
  141.     {
  142.         $this->createdAt = $createdAt;
  143.         return $this;
  144.     }
  145.     // public function getUpdatedAt(): ?DateTimeImmutable
  146.     // {
  147.     //     return $this->updatedAt;
  148.     // }
  149.     public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
  150.     {
  151.         $this->updatedAt = $updatedAt;
  152.         return $this;
  153.     }
  154.     public function __toString()
  155.     {
  156.         return $this->name;
  157.     }
  158.     public function getDescription(): ?string
  159.     {
  160.         return $this->description;
  161.     }
  162.     public function setDescription(?string $description): self
  163.     {
  164.         $this->description = $description;
  165.         return $this;
  166.     }
  167.     public function getParent(): ?self
  168.     {
  169.         return $this->parent;
  170.     }
  171.     public function setParent(?self $parent): self
  172.     {
  173.         $this->parent = $parent;
  174.         return $this;
  175.     }
  176.     /**
  177.      * @return Collection<int, self>
  178.      */
  179.     public function getSubStructures(): Collection
  180.     {
  181.         return $this->subStructures;
  182.     }
  183.     public function addSubStructure(self $subStructure): self
  184.     {
  185.         if (!$this->subStructures->contains($subStructure)) {
  186.             $this->subStructures->add($subStructure);
  187.             $subStructure->setParent($this);
  188.         }
  189.         return $this;
  190.     }
  191.     public function removeSubStructure(self $subStructure): self
  192.     {
  193.         if ($this->subStructures->removeElement($subStructure)) {
  194.             // set the owning side to null (unless already changed)
  195.             if ($subStructure->getParent() === $this) {
  196.                 $subStructure->setParent(null);
  197.             }
  198.         }
  199.         return $this;
  200.     }
  201.     public function getStructureType(): ?StructureType
  202.     {
  203.         return $this->structureType;
  204.     }
  205.     public function setStructureType(?StructureType $structureType): self
  206.     {
  207.         $this->structureType = $structureType;
  208.         return $this;
  209.     }
  210.     public function getCreatedBy(): ?User
  211.     {
  212.         return $this->createdBy;
  213.     }
  214.     public function setCreatedBy(?User $createdBy): static
  215.     {
  216.         $this->createdBy = $createdBy;
  217.         return $this;
  218.     }
  219.     /**
  220.      * @return Collection<int, Pao>
  221.      */
  222.     public function getPaos(): Collection
  223.     {
  224.         return $this->paos;
  225.     }
  226.     public function addPao(Pao $pao): static
  227.     {
  228.         if (!$this->paos->contains($pao)) {
  229.             $this->paos->add($pao);
  230.             $pao->setStructure($this);
  231.         }
  232.         return $this;
  233.     }
  234.     public function removePao(Pao $pao): static
  235.     {
  236.         if ($this->paos->removeElement($pao)) {
  237.             // set the owning side to null (unless already changed)
  238.             if ($pao->getStructure() === $this) {
  239.                 $pao->setStructure(null);
  240.             }
  241.         }
  242.         return $this;
  243.     }
  244.       // Méthode pour ajouter une réunion
  245.       public function addMeeting(Meeting $meeting): void
  246.       {
  247.           if (!$this->meetings->contains($meeting)) {
  248.               $this->meetings[] = $meeting;
  249.               $meeting->setStructure($this); // Associer la structure à la réunion
  250.           }
  251.       }
  252.   
  253.       // Méthode pour supprimer une réunion
  254.       public function removeMeeting(Meeting $meeting): void
  255.       {
  256.           if ($this->meetings->contains($meeting)) {
  257.               $this->meetings->removeElement($meeting);
  258.               // Dissocier la structure de la réunion
  259.               if ($meeting->getStructure() === $this) {
  260.                   $meeting->setStructure(null);
  261.               }
  262.           }
  263.       }
  264.     
  265.     /**
  266.      * @return Collection<int, Decision>
  267.     */
  268.     public function getDecisions(): Collection
  269.     {
  270.         return $this->decisions;
  271.     }
  272.     public function addDecision(Decision $decision): void
  273.     {
  274.         if (!$this->decisions->contains($decision)) {
  275.             $this->decisions[] = $decision;
  276.             $decision->setStructure($this);
  277.         }
  278.     }
  279.     public function removeDecision(Decision $decision): self
  280.     {
  281.         if ($this->decisions->removeElement($decision)) {
  282.             if ($decision->getStructure() === $this) {
  283.                 $decision->setStructure(null);
  284.             }
  285.         }
  286.         return $this;
  287.     }
  288. }