src/Entity/Objet.php line 19

Open in your IDE?
  1. <?php
  2. // src/Entity/Objet.php
  3. namespace App\Entity;
  4. use App\Repository\ObjetRepository;
  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(repositoryClassObjetRepository::class)]
  10. #[ORM\Table(name'objet')]
  11. #[ORM\UniqueConstraint(
  12.     name'uniq_objet_type_num',
  13.     columns: ['objet_type_id''numero']
  14. )]
  15. #[ORM\HasLifecycleCallbacks]
  16. class Objet
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     private ?int $id null;
  22.     #[ORM\ManyToOne(inversedBy'objets')]
  23.     private ?Contact $contact null;
  24.     #[ORM\Column(length255)]
  25.     private ?string $label null;
  26.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  27.     private ?\DateTimeInterface $date_creation null;
  28.     #[ORM\OneToMany(mappedBy'objet'targetEntityDossier::class, cascade: ['remove'])]
  29.     private Collection $dossiers;
  30.     #[ORM\OneToMany(mappedBy'objet'targetEntityVariableValue::class)]
  31.     private Collection $variableValues;
  32.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'objets')]
  33.     private ?Objet $objet null;
  34.     #[ORM\OneToMany(mappedBy'objet'targetEntityself::class, cascade: ['remove'])]
  35.     private Collection $objets;
  36.     #[ORM\ManyToOne(targetEntityObjetType::class, inversedBy'objets')]
  37.     #[ORM\JoinColumn(onDelete'CASCADE'nullabletrue)]
  38.     private ?ObjetType $objet_type null;
  39.     #[ORM\ManyToOne(inversedBy'objets')]
  40.     private ?User $utilisateur null;
  41.     #[ORM\OneToMany(mappedBy'objet'targetEntityFichier::class)]
  42.     private Collection $fichiers;
  43.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  44.     private ?string $path null;
  45.     #[ORM\Column(typeTypes::INTEGERoptions: ['default' => 1])]
  46.     private int $etat 1;
  47.     #[ORM\Column(typeTypes::BIGINTnullabletrue)]
  48.     private ?string $numero null;
  49.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  50.     private ?array $data null;
  51.     private ?array $groupObjetTypeVariables null;
  52.     private ?array $groupContactVariables null;
  53.     private ?array $ancestors null;
  54.     public function __construct()
  55.     {
  56.         $this->dossiers = new ArrayCollection();
  57.         $this->variableValues = new ArrayCollection();
  58.         $this->fichiers = new ArrayCollection();
  59.         $this->objets = new ArrayCollection();
  60.     }
  61.     // ---------------------
  62.     // Getters & Setters
  63.     // ---------------------
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getContact(): ?Contact
  69.     {
  70.         return $this->contact;
  71.     }
  72.     public function setContact(?Contact $contact): static
  73.     {
  74.         $this->contact $contact;
  75.         return $this;
  76.     }
  77.     public function getLabel(): ?string
  78.     {
  79.         return $this->label;
  80.     }
  81.     public function setLabel(string $label): static
  82.     {
  83.         $this->label ucfirst(trim($label));
  84.         return $this;
  85.     }
  86.     public function getDateCreation(): ?\DateTimeInterface
  87.     {
  88.         return $this->date_creation;
  89.     }
  90.     public function setDateCreation(\DateTimeInterface $date_creation): static
  91.     {
  92.         $this->date_creation $date_creation;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return Collection<int, Dossier>
  97.      */
  98.     public function getDossiers(): Collection
  99.     {
  100.         return $this->dossiers;
  101.     }
  102.     public function addDossier(Dossier $dossier): static
  103.     {
  104.         if (!$this->dossiers->contains($dossier)) {
  105.             $this->dossiers->add($dossier);
  106.             $dossier->setObjet($this);
  107.         }
  108.         return $this;
  109.     }
  110.     public function removeDossier(Dossier $dossier): static
  111.     {
  112.         if ($this->dossiers->removeElement($dossier)) {
  113.             if ($dossier->getObjet() === $this) {
  114.                 $dossier->setObjet(null);
  115.             }
  116.         }
  117.         return $this;
  118.     }
  119.     /**
  120.      * @return Collection<int, VariableValue>
  121.      */
  122.     public function getVariableValues(): Collection
  123.     {
  124.         return $this->variableValues;
  125.     }
  126.     public function addVariableValue(VariableValue $variableValue): static
  127.     {
  128.         if (!$this->variableValues->contains($variableValue)) {
  129.             $this->variableValues->add($variableValue);
  130.             $variableValue->setObjet($this);
  131.         }
  132.         return $this;
  133.     }
  134.     public function removeVariableValue(VariableValue $variableValue): static
  135.     {
  136.         if ($this->variableValues->removeElement($variableValue)) {
  137.             if ($variableValue->getObjet() === $this) {
  138.                 $variableValue->setObjet(null);
  139.             }
  140.         }
  141.         return $this;
  142.     }
  143.     public function getObjet(): ?self
  144.     {
  145.         return $this->objet;
  146.     }
  147.     public function setObjet(?self $objet): static
  148.     {
  149.         $this->objet $objet;
  150.         return $this;
  151.     }
  152.     public function setObjets(Collection $objets): static
  153.     {
  154.         $this->objets $objets;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return Collection<int, self>
  159.      */
  160.     public function getObjets(): Collection
  161.     {
  162.         return $this->objets;
  163.     }
  164.     public function addObjet(self $objet): static
  165.     {
  166.         if (!$this->objets->contains($objet)) {
  167.             $this->objets->add($objet);
  168.             $objet->setObjet($this);
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeObjet(self $objet): static
  173.     {
  174.         if ($this->objets->removeElement($objet)) {
  175.             if ($objet->getObjet() === $this) {
  176.                 $objet->setObjet(null);
  177.             }
  178.         }
  179.         return $this;
  180.     }
  181.     public function getObjetType(): ?ObjetType
  182.     {
  183.         return $this->objet_type;
  184.     }
  185.     public function setObjetType(?ObjetType $objet_type): static
  186.     {
  187.         $this->objet_type $objet_type;
  188.         return $this;
  189.     }
  190.     public function getUtilisateur(): ?User
  191.     {
  192.         return $this->utilisateur;
  193.     }
  194.     public function setUtilisateur(?User $utilisateur): static
  195.     {
  196.         $this->utilisateur $utilisateur;
  197.         return $this;
  198.     }
  199.     
  200.     /**
  201.      * @return Collection<int, Fichier>
  202.      */
  203.     public function getFichiers(): Collection
  204.     {
  205.         return $this->fichiers;
  206.     }
  207.     public function addFichier(Fichier $fichier): static
  208.     {
  209.         if (!$this->fichiers->contains($fichier)) {
  210.             $this->fichiers->add($fichier);
  211.             $fichier->setObjet($this);
  212.         }
  213.         return $this;
  214.     }
  215.     public function removeFichier(Fichier $fichier): static
  216.     {
  217.         if ($this->fichiers->removeElement($fichier)) {
  218.             if ($fichier->getObjet() === $this) {
  219.                 $fichier->setObjet(null);
  220.             }
  221.         }
  222.         return $this;
  223.     }
  224.     // ---------------------
  225.     // Path logic
  226.     // ---------------------
  227.     public function getPath(): ?string
  228.     {
  229.         return $this->path;
  230.     }
  231.     public function setPath(?string $path): static
  232.     {
  233.         $this->path $path;
  234.         return $this;
  235.     }
  236.     public function computePath(): void
  237.     {
  238.         $ids = [];
  239.         $parent $this->getObjet();
  240.         while ($parent !== null) {
  241.             $ids[] = $parent->getId();
  242.             $parent $parent->getObjet();
  243.         }
  244.         $ids array_reverse($ids);
  245.         $ids[] = $this->getId();
  246.         $this->path implode(','$ids);
  247.     }
  248.     /**
  249.      * Set grouped objet type variables
  250.      */
  251.     public function setGroupObjetTypeVariables(?array $groupObjetTypeVariables): self
  252.     {
  253.         $this->groupObjetTypeVariables $groupObjetTypeVariables;
  254.         return $this;
  255.     }
  256.     /**
  257.      * Get grouped objet type variables
  258.      * Access in Twig: {{ objet.groupObjetTypeVariables }}
  259.      */
  260.     public function getGroupObjetTypeVariables(): ?array
  261.     {
  262.         return $this->groupObjetTypeVariables;
  263.     }
  264.     /**
  265.      * Set grouped contact variables
  266.      */
  267.     public function setGroupContactVariables(?array $groupContactVariables): self
  268.     {
  269.         $this->groupContactVariables $groupContactVariables;
  270.         return $this;
  271.     }
  272.     /**
  273.      * Get grouped contact variables
  274.      * Access in Twig: {{ objet.groupContactVariables }}
  275.      */
  276.     public function getGroupContactVariables(): ?array
  277.     {
  278.         return $this->groupContactVariables;
  279.     }
  280.     /**
  281.      * Set ancestors chain
  282.      */
  283.     public function setAncestors(?array $ancestors): self
  284.     {
  285.         $this->ancestors $ancestors;
  286.         return $this;
  287.     }
  288.     /**
  289.      * Get ancestors
  290.      * Access in Twig: {{ objet.ancestors }}
  291.      */
  292.     public function getAncestors(): ?array
  293.     {
  294.         return $this->ancestors;
  295.     }
  296.     /**
  297.      * Group and sort variables by colonne (used by repository)
  298.      */
  299.     public function getVariablesGroupedByColonne(array $variablesGroups): array
  300.     {
  301.         return $this->groupAndSortByColonne($variablesGroups);
  302.     }
  303.     /**
  304.      * Group and sort contact variables by colonne (used by repository)
  305.      */
  306.     public function getContactVariablesGroupedByColonne(array $variablesGroups): array
  307.     {
  308.         return $this->groupAndSortByColonne($variablesGroups);
  309.     }
  310.     /**
  311.      * Helper: Group and sort VariablesGroups by colonne
  312.      */
  313.     private function groupAndSortByColonne(array $variablesGroups): array
  314.     {
  315.         $grouped = [];
  316.         foreach ($variablesGroups as $group) {
  317.             $colonne $group->getColonne() ?? 'default';
  318.             if (!isset($grouped[$colonne])) {
  319.                 $grouped[$colonne] = [];
  320.             }
  321.             $grouped[$colonne][] = $group;
  322.         }
  323.         // Sort each colonne's groups
  324.         foreach ($grouped as &$groups) {
  325.             usort($groups, static function ($a$b) {
  326.                 return ($a->getOrdre() ?? 0) <=> ($b->getOrdre() ?? 0);
  327.             });
  328.         }
  329.         return $grouped;
  330.     }
  331.     public function getEtat(): int
  332.     {
  333.         return $this->etat;
  334.     }
  335.     public function setEtat(int $etat): static
  336.     {
  337.         $this->etat $etat;
  338.         return $this;
  339.     }
  340.     public function getNumero(): ?string
  341.     {
  342.         return $this->numero;
  343.     }
  344.     public function setNumero(?string $numero): static
  345.     {
  346.         $this->numero $numero;
  347.         return $this;
  348.     }
  349.     public function getData(): ?array
  350.     {
  351.         return $this->data;
  352.     }
  353.     public function setData(?array $data): static
  354.     {
  355.         $this->data $data;
  356.         return $this;
  357.     }
  358. }