src/Entity/ContactType.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ContactTypeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassContactTypeRepository::class)]
  9. class ContactType
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $label null;
  17.     #[ORM\Column(length255nullabletrue)]
  18.     private ?string $labelPluriel null;
  19.     #[ORM\OneToMany(mappedBy'contact_type'targetEntityContact::class, cascade: ['remove'])]
  20.     private Collection $contacts;
  21.     #[ORM\OneToMany(mappedBy'contactType'targetEntityAttributGroupeLiaison::class, cascade: ['remove'])]
  22.     #[ORM\OrderBy(['colonne' => 'ASC''ordre' => 'ASC'])]
  23.     private Collection $attributGroupeLiaisons;
  24.     #[ORM\OneToMany(mappedBy'contact_group'targetEntityObjetType::class, cascade: ['remove'])]
  25.     private Collection $objetTypes;
  26.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  27.     private ?\DateTimeInterface $date_creation null;
  28.     #[ORM\Column(typeTypes::INTEGERoptions: ['default' => 1])]
  29.     private int $etat 1;
  30.     public function __construct()
  31.     {
  32.         $this->contacts = new ArrayCollection();
  33.         $this->attributGroupeLiaisons = new ArrayCollection();
  34.         $this->objetTypes = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getLabel(): ?string
  41.     {
  42.         return $this->label;
  43.     }
  44.     public function setLabel(string $label): static
  45.     {
  46.         $this->label $label;
  47.         return $this;
  48.     }
  49.     public function getLabelPluriel(): ?string
  50.     {
  51.         return $this->labelPluriel;
  52.     }
  53.     public function setLabelPluriel(?string $labelPluriel): static
  54.     {
  55.         $this->labelPluriel $labelPluriel;
  56.         return $this;
  57.     }
  58.     /**
  59.      * @return Collection<int, Contact>
  60.      */
  61.     public function getContacts(): Collection
  62.     {
  63.         return $this->contacts;
  64.     }
  65.     public function addContact(Contact $contact): static
  66.     {
  67.         if (!$this->contacts->contains($contact)) {
  68.             $this->contacts->add($contact);
  69.             $contact->setContactType($this);
  70.         }
  71.         return $this;
  72.     }
  73.     public function removeContact(Contact $contact): static
  74.     {
  75.         if ($this->contacts->removeElement($contact)) {
  76.             if ($contact->getContactType() === $this) {
  77.                 $contact->setContactType(null);
  78.             }
  79.         }
  80.         return $this;
  81.     }
  82.     /**
  83.      * @return Collection<int, VariablesGroup>
  84.      */
  85.     public function getVariablesGroups(): Collection
  86.     {
  87.         $variablesGroups = new ArrayCollection();
  88.         $liaisons $this->attributGroupeLiaisons->toArray();
  89.         // Sort by ordre
  90.         usort($liaisons, fn($a$b) => $a->getOrdre() <=> $b->getOrdre());
  91.         foreach ($liaisons as $liaison) {
  92.             $variablesGroups->add($liaison->getAttributGroupe());
  93.         }
  94.         return $variablesGroups;
  95.     }
  96.     /**
  97.      * @return Collection<int, AttributGroupeLiaison>
  98.      */
  99.     public function getAttributGroupeLiaisons(): Collection
  100.     {
  101.         return $this->attributGroupeLiaisons;
  102.     }
  103.     public function addAttributGroupeLiaison(AttributGroupeLiaison $attributGroupeLiaison): static
  104.     {
  105.         if (!$this->attributGroupeLiaisons->contains($attributGroupeLiaison)) {
  106.             $this->attributGroupeLiaisons->add($attributGroupeLiaison);
  107.             $attributGroupeLiaison->setContactType($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeAttributGroupeLiaison(AttributGroupeLiaison $attributGroupeLiaison): static
  112.     {
  113.         if ($this->attributGroupeLiaisons->removeElement($attributGroupeLiaison)) {
  114.             if ($attributGroupeLiaison->getContactType() === $this) {
  115.                 $attributGroupeLiaison->setContactType(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return Collection<int, ObjetType>
  122.      */
  123.     public function getObjetTypes(): Collection
  124.     {
  125.         return $this->objetTypes;
  126.     }
  127.     public function getObjetTypesLevelOne(): Collection
  128.     {
  129.         return $this->objetTypes->filter(
  130.             fn($objetType) => $objetType->getObjetType() === null
  131.         );
  132.     }
  133.     public function addObjetType(ObjetType $objetType): static
  134.     {
  135.         if (!$this->objetTypes->contains($objetType)) {
  136.             $this->objetTypes->add($objetType);
  137.             $objetType->setContactGroup($this);
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeObjetType(ObjetType $objetType): static
  142.     {
  143.         if ($this->objetTypes->removeElement($objetType)) {
  144.             if ($objetType->getContactGroup() === $this) {
  145.                 $objetType->setContactGroup(null);
  146.             }
  147.         }
  148.         return $this;
  149.     }
  150.     public function getDateCreation(): ?\DateTimeInterface
  151.     {
  152.         return $this->date_creation;
  153.     }
  154.     public function setDateCreation(?\DateTimeInterface $date_creation): static
  155.     {
  156.         $this->date_creation $date_creation;
  157.         return $this;
  158.     }
  159.     public function getEtat(): int
  160.     {
  161.         return $this->etat;
  162.     }
  163.     public function setEtat(int $etat): static
  164.     {
  165.         $this->etat $etat;
  166.         return $this;
  167.     }
  168.     public function __toString()
  169.     {
  170.         return $this->label;
  171.     }
  172. }