src/Entity/Localite.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use DateTimeInterface;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity()]
  8. class Localite
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column(type'integer')]
  13.     private $id;
  14.     #[ORM\Column(type'string'length100)]
  15.     private $nom;
  16.     #[ORM\Column(type'string'length20)]
  17.     private $type// 'region', 'departement', 'commune', 'ville', 'sous-prefecture', 'village'
  18.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'enfants')]
  19.     #[ORM\JoinColumn(name'parent_id'referencedColumnName'id'onDelete'CASCADE')]
  20.     private $parent;
  21.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  22.     private $enfants;
  23.     // NOUVEAU : Relation avec DirectionRegionale
  24.     #[ORM\ManyToOne(targetEntityDirectionRegionale::class, inversedBy'localites')]
  25.     #[ORM\JoinColumn(nullabletrue)]
  26.     private $directionRegionale;
  27.     // NOUVEAU : Relation avec Etablissement
  28.     #[ORM\OneToMany(mappedBy'localite'targetEntityEtablissement::class)]
  29.     private $etablissements;
  30.     #[ORM\ManyToOne(targetEntityUser::class)]
  31.     #[ORM\JoinColumn(nullabletrue)]
  32.     private $user;
  33.     #[ORM\Column(type'datetime'nullabletrue)]
  34.     private $creation;
  35.     #[ORM\Column(type'datetime'nullabletrue)]
  36.     private $modification;
  37.     public function __construct()
  38.     {
  39.         $this->enfants = new ArrayCollection();
  40.         $this->etablissements = new ArrayCollection();
  41.     }
  42.     public function getUser(): ?User
  43.     {
  44.         return $this->user;
  45.     }
  46.     public function setUser(?User $user): self
  47.     {
  48.         $this->user $user;
  49.         return $this;
  50.     }
  51.     public function getCreation(): ?\DateTimeInterface
  52.     {
  53.         return $this->creation;
  54.     }
  55.     public function setCreation(?\DateTimeInterface $creation): self
  56.     {
  57.         $this->creation $creation;
  58.         return $this;
  59.     }
  60.     public function getModification(): ?\DateTimeInterface
  61.     {
  62.         return $this->modification;
  63.     }
  64.     public function setModification(?\DateTimeInterface $modification): self
  65.     {
  66.         $this->modification $modification;
  67.         return $this;
  68.     }
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function getNom(): ?string
  74.     {
  75.         return $this->nom;
  76.     }
  77.     public function setNom(?string $nom): self
  78.     {
  79.         $this->nom $nom;
  80.         return $this;
  81.     }
  82.     public function getType(): ?string
  83.     {
  84.         return $this->type;
  85.     }
  86.     public function setType(?string $type): self
  87.     {
  88.         $this->type $type;
  89.         return $this;
  90.     }
  91.     public function getParent(): ?self
  92.     {
  93.         return $this->parent;
  94.     }
  95.     public function setParent(?self $parent): self
  96.     {
  97.         $this->parent $parent;
  98.         return $this;
  99.     }
  100.     public function getEnfants(): Collection
  101.     {
  102.         return $this->enfants;
  103.     }
  104.     public function addEnfant(self $enfant): self
  105.     {
  106.         if (!$this->enfants->contains($enfant)) {
  107.             $this->enfants[] = $enfant;
  108.             $enfant->setParent($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeEnfant(self $enfant): self
  113.     {
  114.         if ($this->enfants->removeElement($enfant)) {
  115.             if ($enfant->getParent() === $this) {
  116.                 $enfant->setParent(null);
  117.             }
  118.         }
  119.         return $this;
  120.     }
  121.     // NOUVELLES MÉTHODES pour DirectionRegionale
  122.     public function getDirectionRegionale(): ?DirectionRegionale
  123.     {
  124.         return $this->directionRegionale;
  125.     }
  126.     public function setDirectionRegionale(?DirectionRegionale $directionRegionale): self
  127.     {
  128.         $this->directionRegionale $directionRegionale;
  129.         return $this;
  130.     }
  131.     // NOUVELLES MÉTHODES pour Etablissement
  132.     /**
  133.      * @return Collection<int, Etablissement>
  134.      */
  135.     public function getEtablissements(): Collection
  136.     {
  137.         return $this->etablissements;
  138.     }
  139.     public function addEtablissement(Etablissement $etablissement): self
  140.     {
  141.         if (!$this->etablissements->contains($etablissement)) {
  142.             $this->etablissements[] = $etablissement;
  143.             $etablissement->setLocalite($this);
  144.         }
  145.         return $this;
  146.     }
  147.     public function removeEtablissement(Etablissement $etablissement): self
  148.     {
  149.         if ($this->etablissements->removeElement($etablissement)) {
  150.             if ($etablissement->getLocalite() === $this) {
  151.                 $etablissement->setLocalite(null);
  152.             }
  153.         }
  154.         return $this;
  155.     }
  156.     public function __toString(): string
  157.     {
  158.         return $this->nom ?? '';
  159.     }
  160. }