src/Entity/TypeContact.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClass\App\Repository\TypeContactRepository::class)]
  7. class TypeContact implements \Stringable
  8. {
  9.     #[ORM\Id]
  10.     #[ORM\GeneratedValue]
  11.     #[ORM\Column(type'integer')]
  12.     private int $id;
  13.     #[ORM\Column(type'string'length255nullabletrue)]
  14.     private ?string $namenull;
  15.     #[ORM\OneToMany(targetEntity\App\Entity\Contact::class, mappedBy'type_contact')]
  16.     private mixed $contacts;
  17.     public function __construct()
  18.     {
  19.         $this->contacts = new ArrayCollection();
  20.     }
  21.     public function getId(): ?int
  22.     {
  23.         return $this->id;
  24.     }
  25.     public function getName(): ?string
  26.     {
  27.         return $this->name;
  28.     }
  29.     public function setName(?string $name): self
  30.     {
  31.         $this->name $name;
  32.         return $this;
  33.     }
  34.     public function __toString(): string
  35.     {
  36.         return (string) $this->name;
  37.     }
  38.     /**
  39.      * @return Collection|Contact[]
  40.      */
  41.     public function getContacts(): Collection
  42.     {
  43.         return $this->contacts;
  44.     }
  45.     public function addContact(Contact $contact): self
  46.     {
  47.         if (!$this->contacts->contains($contact)) {
  48.             $this->contacts[] = $contact;
  49.             $contact->setTypeContact($this);
  50.         }
  51.         return $this;
  52.     }
  53.     public function removeContact(Contact $contact): self
  54.     {
  55.         if ($this->contacts->contains($contact)) {
  56.             $this->contacts->removeElement($contact);
  57.             // set the owning side to null (unless already changed)
  58.             if ($contact->getTypeContact() === $this) {
  59.                 $contact->setTypeContact(null);
  60.             }
  61.         }
  62.         return $this;
  63.     }
  64. }