src/Entity/Accompanist.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AccompanistRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassAccompanistRepository::class)]
  8. class Accompanist
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length50)]
  15.     private ?string $firstname null;
  16.     #[ORM\Column(length50)]
  17.     private ?string $lastname null;
  18.     #[ORM\OneToMany(mappedBy'accompanist'targetEntityCompany::class)]
  19.     private Collection $companies;
  20.     #[ORM\OneToOne(mappedBy'accompanist'cascade: ['persist''remove'])]
  21.     private ?User $user null;
  22.     #[ORM\Column]
  23.     private ?bool $active null;
  24.     public function __construct()
  25.     {
  26.         $this->companies = new ArrayCollection();
  27.         $this->active true;
  28.     }
  29.     public function getName()
  30.     {
  31.         $name $this->getFirstname() . ' ' $this->getLastname();
  32.         return $name;
  33.     }
  34.     public function __toString()
  35.     {
  36.         return $this->firstname ' ' $this->lastname;
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getFirstname(): ?string
  43.     {
  44.         return $this->firstname;
  45.     }
  46.     public function setFirstname(string $firstname): self
  47.     {
  48.         $this->firstname $firstname;
  49.         return $this;
  50.     }
  51.     public function getLastname(): ?string
  52.     {
  53.         return $this->lastname;
  54.     }
  55.     public function setLastname(string $lastname): self
  56.     {
  57.         $this->lastname $lastname;
  58.         return $this;
  59.     }
  60.     /**
  61.      * @return Collection<int, Company>
  62.      */
  63.     public function getCompanies(): Collection
  64.     {
  65.         return $this->companies;
  66.     }
  67.     public function addCompany(Company $company): self
  68.     {
  69.         if (!$this->companies->contains($company)) {
  70.             $this->companies->add($company);
  71.             $company->setAccompanist($this);
  72.         }
  73.         return $this;
  74.     }
  75.     public function removeCompany(Company $company): self
  76.     {
  77.         if ($this->companies->removeElement($company)) {
  78.             // set the owning side to null (unless already changed)
  79.             if ($company->getAccompanist() === $this) {
  80.                 $company->setAccompanist(null);
  81.             }
  82.         }
  83.         return $this;
  84.     }
  85.     public function getUser(): ?User
  86.     {
  87.         return $this->user;
  88.     }
  89.     public function setUser(?User $user): self
  90.     {
  91.         // unset the owning side of the relation if necessary
  92.         if ($user === null && $this->user !== null) {
  93.             $this->user->setAccompanist(null);
  94.         }
  95.         // set the owning side of the relation if necessary
  96.         if ($user !== null && $user->getAccompanist() !== $this) {
  97.             $user->setAccompanist($this);
  98.         }
  99.         $this->user $user;
  100.         return $this;
  101.     }
  102.     public function isActive(): ?bool
  103.     {
  104.         return $this->active;
  105.     }
  106.     public function setActive(bool $active): self
  107.     {
  108.         $this->active $active;
  109.         return $this;
  110.     }
  111. }