<?php
namespace App\Entity;
use App\Repository\ContactTypeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ContactTypeRepository::class)]
class ContactType
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $label = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $labelPluriel = null;
#[ORM\OneToMany(mappedBy: 'contact_type', targetEntity: Contact::class, cascade: ['remove'])]
private Collection $contacts;
#[ORM\ManyToMany(targetEntity: VariablesGroup::class, mappedBy: 'contact_group')]
#[ORM\OrderBy(['ordre' => 'ASC'])]
private Collection $variablesGroups;
#[ORM\OneToMany(mappedBy: 'contact_group', targetEntity: ObjetType::class, cascade: ['remove'])]
private Collection $objetTypes;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_creation = null;
#[ORM\Column(type: Types::INTEGER, options: ['default' => 1])]
private int $etat = 1;
public function __construct()
{
$this->contacts = new ArrayCollection();
$this->variablesGroups = new ArrayCollection();
$this->objetTypes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): static
{
$this->label = $label;
return $this;
}
public function getLabelPluriel(): ?string
{
return $this->labelPluriel;
}
public function setLabelPluriel(?string $labelPluriel): static
{
$this->labelPluriel = $labelPluriel;
return $this;
}
/**
* @return Collection<int, Contact>
*/
public function getContacts(): Collection
{
return $this->contacts;
}
public function addContact(Contact $contact): static
{
if (!$this->contacts->contains($contact)) {
$this->contacts->add($contact);
$contact->setContactType($this);
}
return $this;
}
public function removeContact(Contact $contact): static
{
if ($this->contacts->removeElement($contact)) {
if ($contact->getContactType() === $this) {
$contact->setContactType(null);
}
}
return $this;
}
/**
* @return Collection<int, VariablesGroup>
*/
public function getVariablesGroups(): Collection
{
$array = $this->variablesGroups->toArray();
usort($array, fn($a, $b) => $a->getOrdre() <=> $b->getOrdre());
return new ArrayCollection($array);
}
public function addVariablesGroup(VariablesGroup $variablesGroup): static
{
if (!$this->variablesGroups->contains($variablesGroup)) {
$this->variablesGroups->add($variablesGroup);
$variablesGroup->addContactGroup($this);
}
return $this;
}
public function removeVariablesGroup(VariablesGroup $variablesGroup): static
{
if ($this->variablesGroups->removeElement($variablesGroup)) {
$variablesGroup->removeContactGroup($this);
}
return $this;
}
/**
* @return Collection<int, ObjetType>
*/
public function getObjetTypes(): Collection
{
return $this->objetTypes;
}
public function getObjetTypesLevelOne(): Collection
{
return $this->objetTypes->filter(
fn($objetType) => $objetType->getObjetType() === null
);
}
public function addObjetType(ObjetType $objetType): static
{
if (!$this->objetTypes->contains($objetType)) {
$this->objetTypes->add($objetType);
$objetType->setContactGroup($this);
}
return $this;
}
public function removeObjetType(ObjetType $objetType): static
{
if ($this->objetTypes->removeElement($objetType)) {
if ($objetType->getContactGroup() === $this) {
$objetType->setContactGroup(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 __toString()
{
return $this->label;
}
}