<?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\OneToMany(mappedBy: 'contact_type', targetEntity: Contact::class, cascade: ['remove'])]
private Collection $contacts;
#[ORM\ManyToMany(targetEntity: VariablesGroup::class, mappedBy: 'contact_group')]
private Collection $variablesGroups;
#[ORM\OneToMany(mappedBy: 'contact_group', targetEntity: ProjectType::class, cascade: ['remove'])]
private Collection $projectTypes;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_creation = null;
public function __construct()
{
$this->contacts = new ArrayCollection();
$this->variablesGroups = new ArrayCollection();
$this->projectTypes = 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;
}
/**
* @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)) {
// set the owning side to null (unless already changed)
if ($contact->getContactType() === $this) {
$contact->setContactType(null);
}
}
return $this;
}
/**
* @return Collection<int, VariablesGroup>
*/
public function getVariablesGroups(): Collection
{
// Convert to an array to sort
$array = $this->variablesGroups->toArray();
// Sort the array using usort
usort($array, function($a, $b) {
return $a->getOrdre() <=> $b->getOrdre();
});
// Convert back to ArrayCollection or PersistentCollection if needed
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, ProjectType>
*/
public function getProjectTypes(): Collection
{
return $this->projectTypes;
}
public function addProjectType(ProjectType $projectType): static
{
if (!$this->projectTypes->contains($projectType)) {
$this->projectTypes->add($projectType);
$projectType->setContactGroup($this);
}
return $this;
}
public function removeProjectType(ProjectType $projectType): static
{
if ($this->projectTypes->removeElement($projectType)) {
// set the owning side to null (unless already changed)
if ($projectType->getContactGroup() === $this) {
$projectType->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 __toString()
{
return $this->label; // Assurez-vous que $this->name est une propriété chaîne de caractères
}
}