src/Entity/Accompanist.php line 11
<?php
namespace App\Entity;
use App\Repository\AccompanistRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: AccompanistRepository::class)]
class Accompanist
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 50)]
private ?string $firstname = null;
#[ORM\Column(length: 50)]
private ?string $lastname = null;
#[ORM\OneToMany(mappedBy: 'accompanist', targetEntity: Company::class)]
private Collection $companies;
#[ORM\OneToOne(mappedBy: 'accompanist', cascade: ['persist', 'remove'])]
private ?User $user = null;
#[ORM\Column]
private ?bool $active = null;
public function __construct()
{
$this->companies = new ArrayCollection();
$this->active = true;
}
public function getName()
{
$name = $this->getFirstname() . ' ' . $this->getLastname();
return $name;
}
public function __toString()
{
return $this->firstname . ' ' . $this->lastname;
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
$company->setAccompanist($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->removeElement($company)) {
// set the owning side to null (unless already changed)
if ($company->getAccompanist() === $this) {
$company->setAccompanist(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
// unset the owning side of the relation if necessary
if ($user === null && $this->user !== null) {
$this->user->setAccompanist(null);
}
// set the owning side of the relation if necessary
if ($user !== null && $user->getAccompanist() !== $this) {
$user->setAccompanist($this);
}
$this->user = $user;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
}