src/Entity/ObjetType.php line 14

Open in your IDE?
  1. <?php
  2. // src/Entity/ObjetType.php
  3. namespace App\Entity;
  4. use App\Repository\ObjetTypeRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClassObjetTypeRepository::class)]
  10. #[ORM\Table(name'objet_type')]
  11. #[ORM\HasLifecycleCallbacks]
  12. class ObjetType
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $label null;
  20.     #[ORM\Column(name'label_pluriel'length100nullabletrue)]
  21.     private ?string $labelPluriel null;
  22.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  23.     private ?string $path null;
  24.     #[ORM\Column(typeTypes::INTEGERoptions: ['default' => 1])]
  25.     private int $etat 1;
  26.     #[ORM\Column(typeTypes::BIGINTnullabletrue)]
  27.     private ?string $numerotation null;
  28.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  29.     private ?string $config_label null;
  30.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  31.     private ?string $config_resume null;
  32.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  33.     private ?string $config_vignette_label null;
  34.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  35.     private ?string $config_vignette_resume null;
  36.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  37.     private ?string $icone null;
  38.     #[ORM\ManyToOne(inversedBy'objetTypes')]
  39.     #[ORM\JoinColumn(onDelete'SET NULL'nullabletrue)]
  40.     private ?ContactType $contact_group null;
  41.     #[ORM\OneToMany(mappedBy'objetType'targetEntityAttributGroupeLiaison::class, cascade: ['remove'])]
  42.     #[ORM\OrderBy(['colonne' => 'ASC''ordre' => 'ASC'])]
  43.     private Collection $attributGroupeLiaisons;
  44.     #[ORM\OneToMany(
  45.         mappedBy'objet_type',
  46.         targetEntityObjet::class,
  47.         cascade: ['remove'],
  48.         orphanRemovaltrue
  49.     )]
  50.     private Collection $objets;
  51.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'childObjetTypes')]
  52.     private ?self $objetType null;
  53.     #[ORM\OneToMany(
  54.         mappedBy'objetType',
  55.         targetEntityself::class,
  56.         cascade: ['remove'],
  57.         orphanRemovaltrue
  58.     )]
  59.     private Collection $childObjetTypes;
  60.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  61.     private ?\DateTimeInterface $date_creation null;
  62.     public function __construct()
  63.     {
  64.         $this->attributGroupeLiaisons = new ArrayCollection();
  65.         $this->objets = new ArrayCollection();
  66.         $this->childObjetTypes = new ArrayCollection();
  67.     }
  68.     // ---------------------
  69.     // Getters & Setters
  70.     // ---------------------
  71.     public function getId(): ?int
  72.     {
  73.         return $this->id;
  74.     }
  75.     public function getLabel(): ?string
  76.     {
  77.         return $this->label;
  78.     }
  79.     public function setLabel(string $label): static
  80.     {
  81.         $this->label ucfirst(trim($label));
  82.         return $this;
  83.     }
  84.     public function getLabelPluriel(): ?string
  85.     {
  86.         return $this->labelPluriel;
  87.     }
  88.     public function setLabelPluriel(?string $labelPluriel): static
  89.     {
  90.         $this->labelPluriel $labelPluriel ucfirst(trim($labelPluriel)) : null;
  91.         return $this;
  92.     }
  93.     public function getPath(): ?string
  94.     {
  95.         return $this->path;
  96.     }
  97.     public function setPath(?string $path): static
  98.     {
  99.         $this->path $path;
  100.         return $this;
  101.     }
  102.     public function getContactGroup(): ?ContactType
  103.     {
  104.         return $this->contact_group;
  105.     }
  106.     public function setContactGroup(?ContactType $contact_group): static
  107.     {
  108.         $this->contact_group $contact_group;
  109.         return $this;
  110.     }
  111.     /**
  112.      * @return Collection<int, VariablesGroup>
  113.      */
  114.     public function getVariablesGroups(): Collection
  115.     {
  116.         $variablesGroups = new ArrayCollection();
  117.         $liaisons $this->attributGroupeLiaisons->toArray();
  118.         // Sort by ordre
  119.         usort($liaisons, fn($a$b) => $a->getOrdre() <=> $b->getOrdre());
  120.         foreach ($liaisons as $liaison) {
  121.             $variablesGroups->add($liaison->getAttributGroupe());
  122.         }
  123.         return $variablesGroups;
  124.     }
  125.     /**
  126.      * @return Collection<int, AttributGroupeLiaison>
  127.      */
  128.     public function getAttributGroupeLiaisons(): Collection
  129.     {
  130.         return $this->attributGroupeLiaisons;
  131.     }
  132.     public function addAttributGroupeLiaison(AttributGroupeLiaison $attributGroupeLiaison): static
  133.     {
  134.         if (!$this->attributGroupeLiaisons->contains($attributGroupeLiaison)) {
  135.             $this->attributGroupeLiaisons->add($attributGroupeLiaison);
  136.             $attributGroupeLiaison->setObjetType($this);
  137.         }
  138.         return $this;
  139.     }
  140.     public function removeAttributGroupeLiaison(AttributGroupeLiaison $attributGroupeLiaison): static
  141.     {
  142.         if ($this->attributGroupeLiaisons->removeElement($attributGroupeLiaison)) {
  143.             if ($attributGroupeLiaison->getObjetType() === $this) {
  144.                 $attributGroupeLiaison->setObjetType(null);
  145.             }
  146.         }
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return Collection<int, Objet>
  151.      */
  152.     public function getObjets(): Collection
  153.     {
  154.         return $this->objets;
  155.     }
  156.     public function addObjet(Objet $objet): static
  157.     {
  158.         if (!$this->objets->contains($objet)) {
  159.             $this->objets->add($objet);
  160.             $objet->setObjetType($this);
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeObjet(Objet $objet): static
  165.     {
  166.         if ($this->objets->removeElement($objet)) {
  167.             if ($objet->getObjetType() === $this) {
  168.                 $objet->setObjetType(null);
  169.             }
  170.         }
  171.         return $this;
  172.     }
  173.     public function getObjetType(): ?self
  174.     {
  175.         return $this->objetType;
  176.     }
  177.     public function setObjetType(?self $objetType): static
  178.     {
  179.         $this->objetType $objetType;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return Collection<int, self>
  184.      */
  185.     public function getchildObjetTypes(): Collection
  186.     {
  187.         return $this->childObjetTypes;
  188.     }
  189.     public function addChildObjet(self $childObjet): static
  190.     {
  191.         if (!$this->childObjetTypes->contains($childObjet)) {
  192.             $this->childObjetTypes->add($childObjet);
  193.             $childObjet->setObjetType($this);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeChildObjet(self $childObjet): static
  198.     {
  199.         if ($this->childObjetTypes->removeElement($childObjet)) {
  200.             if ($childObjet->getObjetType() === $this) {
  201.                 $childObjet->setObjetType(null);
  202.             }
  203.         }
  204.         return $this;
  205.     }
  206.     public function getDateCreation(): ?\DateTimeInterface
  207.     {
  208.         return $this->date_creation;
  209.     }
  210.     public function setDateCreation(?\DateTimeInterface $date_creation): static
  211.     {
  212.         $this->date_creation $date_creation;
  213.         return $this;
  214.     }
  215.     public function getEtat(): int
  216.     {
  217.         return $this->etat;
  218.     }
  219.     public function setEtat(int $etat): static
  220.     {
  221.         $this->etat $etat;
  222.         return $this;
  223.     }
  224.     public function getNumerotation(): ?string
  225.     {
  226.         return $this->numerotation;
  227.     }
  228.     public function setNumerotation(?string $numerotation): static
  229.     {
  230.         $this->numerotation $numerotation;
  231.         return $this;
  232.     }
  233.     public function getConfigLabel(): ?string
  234.     {
  235.         return $this->config_label;
  236.     }
  237.     public function setConfigLabel(?string $config_label): static
  238.     {
  239.         $this->config_label $config_label;
  240.         return $this;
  241.     }
  242.     public function getConfigResume(): ?string
  243.     {
  244.         return $this->config_resume;
  245.     }
  246.     public function setConfigResume(?string $config_resume): static
  247.     {
  248.         $this->config_resume $config_resume;
  249.         return $this;
  250.     }
  251.     public function getConfigVignetteLabel(): ?string
  252.     {
  253.         return $this->config_vignette_label;
  254.     }
  255.     public function setConfigVignetteLabel(?string $config_vignette_label): static
  256.     {
  257.         $this->config_vignette_label $config_vignette_label;
  258.         return $this;
  259.     }
  260.     public function getConfigVignetteResume(): ?string
  261.     {
  262.         return $this->config_vignette_resume;
  263.     }
  264.     public function setConfigVignetteResume(?string $config_vignette_resume): static
  265.     {
  266.         $this->config_vignette_resume $config_vignette_resume;
  267.         return $this;
  268.     }
  269.     public function getIcone(): ?string
  270.     {
  271.         return $this->icone;
  272.     }
  273.     public function setIcone(?string $icone): static
  274.     {
  275.         $this->icone $icone trim($icone) : null;
  276.         return $this;
  277.     }
  278.     // ---------------------
  279.     // Path logic only
  280.     // ---------------------
  281.     public function computePath(): void
  282.     {
  283.         $ids = [];
  284.         $parent $this->getObjetType();
  285.         while ($parent !== null) {
  286.             $ids[] = $parent->getId();
  287.             $parent $parent->getObjetType();
  288.         }
  289.         $ids array_reverse($ids);
  290.         $ids[] = $this->getId();
  291.         $this->path implode(','$ids);
  292.     }
  293. }