<?php
// src/Entity/ObjetType.php
namespace App\Entity;
use App\Repository\ObjetTypeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ObjetTypeRepository::class)]
#[ORM\Table(name: 'objet_type')]
#[ORM\HasLifecycleCallbacks]
class ObjetType
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $label = null;
#[ORM\Column(name: 'label_pluriel', length: 100, nullable: true)]
private ?string $labelPluriel = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $path = null;
#[ORM\Column(type: Types::INTEGER, options: ['default' => 1])]
private int $etat = 1;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $numerotation = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $config_label = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $config_resume = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $config_vignette_label = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $config_vignette_resume = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $icone = null;
#[ORM\ManyToOne(inversedBy: 'objetTypes')]
#[ORM\JoinColumn(onDelete: 'SET NULL', nullable: true)]
private ?ContactType $contact_group = null;
#[ORM\ManyToMany(targetEntity: VariablesGroup::class, mappedBy: 'objet_group')]
#[ORM\OrderBy(['ordre' => 'ASC'])]
private Collection $variablesGroups;
#[ORM\OneToMany(
mappedBy: 'objet_type',
targetEntity: Objet::class,
cascade: ['remove'],
orphanRemoval: true
)]
private Collection $objets;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'childObjetTypes')]
private ?self $objetType = null;
#[ORM\OneToMany(
mappedBy: 'objetType',
targetEntity: self::class,
cascade: ['remove'],
orphanRemoval: true
)]
private Collection $childObjetTypes;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_creation = null;
public function __construct()
{
$this->variablesGroups = new ArrayCollection();
$this->objets = new ArrayCollection();
$this->childObjetTypes = new ArrayCollection();
}
// ---------------------
// Getters & Setters
// ---------------------
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): static
{
$this->label = ucfirst(trim($label));
return $this;
}
public function getLabelPluriel(): ?string
{
return $this->labelPluriel;
}
public function setLabelPluriel(?string $labelPluriel): static
{
$this->labelPluriel = $labelPluriel ? ucfirst(trim($labelPluriel)) : null;
return $this;
}
public function getPath(): ?string
{
return $this->path;
}
public function setPath(?string $path): static
{
$this->path = $path;
return $this;
}
public function getContactGroup(): ?ContactType
{
return $this->contact_group;
}
public function setContactGroup(?ContactType $contact_group): static
{
$this->contact_group = $contact_group;
return $this;
}
/**
* @return Collection<int, VariablesGroup>
*/
public function getVariablesGroups(): Collection
{
return $this->variablesGroups;
}
public function addVariablesGroup(VariablesGroup $variablesGroup): static
{
if (!$this->variablesGroups->contains($variablesGroup)) {
$this->variablesGroups->add($variablesGroup);
$variablesGroup->addObjetGroup($this);
}
return $this;
}
public function removeVariablesGroup(VariablesGroup $variablesGroup): static
{
if ($this->variablesGroups->removeElement($variablesGroup)) {
$variablesGroup->removeObjetGroup($this);
}
return $this;
}
/**
* @return Collection<int, Objet>
*/
public function getObjets(): Collection
{
return $this->objets;
}
public function addObjet(Objet $objet): static
{
if (!$this->objets->contains($objet)) {
$this->objets->add($objet);
$objet->setObjetType($this);
}
return $this;
}
public function removeObjet(Objet $objet): static
{
if ($this->objets->removeElement($objet)) {
if ($objet->getObjetType() === $this) {
$objet->setObjetType(null);
}
}
return $this;
}
public function getObjetType(): ?self
{
return $this->objetType;
}
public function setObjetType(?self $objetType): static
{
$this->objetType = $objetType;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getchildObjetTypes(): Collection
{
return $this->childObjetTypes;
}
public function addChildObjet(self $childObjet): static
{
if (!$this->childObjetTypes->contains($childObjet)) {
$this->childObjetTypes->add($childObjet);
$childObjet->setObjetType($this);
}
return $this;
}
public function removeChildObjet(self $childObjet): static
{
if ($this->childObjetTypes->removeElement($childObjet)) {
if ($childObjet->getObjetType() === $this) {
$childObjet->setObjetType(null);
}
}
return $this;
}
public function getDateCreation(): ?\DateTimeInterface
{
return $this->date_creation;
}
public function setDateCreation(?\DateTimeInterface $date_creation): static
{
$this->date_creation = $date_creation;
return $this;
}
public function getEtat(): int
{
return $this->etat;
}
public function setEtat(int $etat): static
{
$this->etat = $etat;
return $this;
}
public function getNumerotation(): ?string
{
return $this->numerotation;
}
public function setNumerotation(?string $numerotation): static
{
$this->numerotation = $numerotation;
return $this;
}
public function getConfigLabel(): ?string
{
return $this->config_label;
}
public function setConfigLabel(?string $config_label): static
{
$this->config_label = $config_label;
return $this;
}
public function getConfigResume(): ?string
{
return $this->config_resume;
}
public function setConfigResume(?string $config_resume): static
{
$this->config_resume = $config_resume;
return $this;
}
public function getConfigVignetteLabel(): ?string
{
return $this->config_vignette_label;
}
public function setConfigVignetteLabel(?string $config_vignette_label): static
{
$this->config_vignette_label = $config_vignette_label;
return $this;
}
public function getConfigVignetteResume(): ?string
{
return $this->config_vignette_resume;
}
public function setConfigVignetteResume(?string $config_vignette_resume): static
{
$this->config_vignette_resume = $config_vignette_resume;
return $this;
}
public function getIcone(): ?string
{
return $this->icone;
}
public function setIcone(?string $icone): static
{
$this->icone = $icone ? trim($icone) : null;
return $this;
}
// ---------------------
// Path logic only
// ---------------------
public function computePath(): void
{
$ids = [];
$parent = $this->getObjetType();
while ($parent !== null) {
$ids[] = $parent->getId();
$parent = $parent->getObjetType();
}
$ids = array_reverse($ids);
$ids[] = $this->getId();
$this->path = implode(',', $ids);
}
}