<?php
namespace App\Entity;
use App\Entity\Traits\TimeStampable;
use App\Repository\StructureRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: StructureRepository::class)]
#[UniqueEntity(
fields: ['name',],
errorPath: 'name',
message: 'Le nom que vous avez saisi est déjà utilisé',
)]
#[UniqueEntity(
fields: ['acronym',],
errorPath: 'acronym',
message: 'L\' acronyme que vous avez saisi est déjà utilisé',
)]
#[UniqueEntity(
fields: ['phone',],
errorPath: 'phone',
message: 'Le numero que vous avez saisi est déjà utilisé',
)]
#[ORM\HasLifecycleCallbacks]
class Structure
{
use TimeStampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(["entity:write"])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['user:read', 'membre:read', 'meetParticipant:read', 'entity:write'])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $name = null;
#[ORM\Column(length: 15)]
#[Groups(["entity:write"])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $acronym = null;
#[ORM\Column(length: 255, nullable:true)]
private ?string $sector = null;
#[ORM\Column(length: 30, nullable: true)]
#[Groups(["entity:write"])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $phone = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(["entity:write"])]
private ?string $description = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(["entity:write"])]
private ?string $email = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'subStructures')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $subStructures;
#[ORM\ManyToOne(targetEntity: StructureType::class, inversedBy:'structures')]
#[Groups(["entity:write"])]
// #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?StructureType $structureType = null;
#[ORM\OneToMany(mappedBy: 'structure', targetEntity: Meeting::class)]
private Collection $meetings;
#[ORM\ManyToOne(inversedBy: 'structures')]
private ?User $createdBy = null;
#[ORM\OneToMany(mappedBy: 'structure', targetEntity: Pao::class)]
private Collection $paos;
#[ORM\OneToMany(mappedBy: 'structure', targetEntity: Decision::class)]
private Collection $decisions;
public function __construct()
{
$this->subStructures = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$this->paos = new ArrayCollection();
$this->meetings = new ArrayCollection();
$this->decisions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getMeetings(): Collection
{
return $this->meetings;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getAcronym(): ?string
{
return $this->acronym;
}
public function setAcronym(string $acronym): self
{
$this->acronym = $acronym;
return $this;
}
public function getSector(): ?string
{
return $this->sector;
}
public function setSector(?string $sector): self
{
$this->sector = $sector;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
// public function getUpdatedAt(): ?DateTimeImmutable
// {
// return $this->updatedAt;
// }
public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function __toString()
{
return $this->name;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getSubStructures(): Collection
{
return $this->subStructures;
}
public function addSubStructure(self $subStructure): self
{
if (!$this->subStructures->contains($subStructure)) {
$this->subStructures->add($subStructure);
$subStructure->setParent($this);
}
return $this;
}
public function removeSubStructure(self $subStructure): self
{
if ($this->subStructures->removeElement($subStructure)) {
// set the owning side to null (unless already changed)
if ($subStructure->getParent() === $this) {
$subStructure->setParent(null);
}
}
return $this;
}
public function getStructureType(): ?StructureType
{
return $this->structureType;
}
public function setStructureType(?StructureType $structureType): self
{
$this->structureType = $structureType;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): static
{
$this->createdBy = $createdBy;
return $this;
}
/**
* @return Collection<int, Pao>
*/
public function getPaos(): Collection
{
return $this->paos;
}
public function addPao(Pao $pao): static
{
if (!$this->paos->contains($pao)) {
$this->paos->add($pao);
$pao->setStructure($this);
}
return $this;
}
public function removePao(Pao $pao): static
{
if ($this->paos->removeElement($pao)) {
// set the owning side to null (unless already changed)
if ($pao->getStructure() === $this) {
$pao->setStructure(null);
}
}
return $this;
}
// Méthode pour ajouter une réunion
public function addMeeting(Meeting $meeting): void
{
if (!$this->meetings->contains($meeting)) {
$this->meetings[] = $meeting;
$meeting->setStructure($this); // Associer la structure à la réunion
}
}
// Méthode pour supprimer une réunion
public function removeMeeting(Meeting $meeting): void
{
if ($this->meetings->contains($meeting)) {
$this->meetings->removeElement($meeting);
// Dissocier la structure de la réunion
if ($meeting->getStructure() === $this) {
$meeting->setStructure(null);
}
}
}
/**
* @return Collection<int, Decision>
*/
public function getDecisions(): Collection
{
return $this->decisions;
}
public function addDecision(Decision $decision): void
{
if (!$this->decisions->contains($decision)) {
$this->decisions[] = $decision;
$decision->setStructure($this);
}
}
public function removeDecision(Decision $decision): self
{
if ($this->decisions->removeElement($decision)) {
if ($decision->getStructure() === $this) {
$decision->setStructure(null);
}
}
return $this;
}
}