<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\InvitationRepository")
*/
class Invitation
{
use TimestampableEntity;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Company")
* @ORM\JoinColumn(nullable=false)
*/
private $company;
/**
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
*/
private $isAnonymous;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\InvitationRecipient", mappedBy="invitation", cascade={"persist"}, orphanRemoval=true)
* @Assert\Count(
* min = 1,
* minMessage = "You must specify at least one coworker"
* )
* @Assert\Valid()
*/
private $recipients;
public function __construct()
{
$this->isAnonymous = true;
$this->recipients = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getIsAnonymous(): ?bool
{
return $this->isAnonymous;
}
public function setIsAnonymous(bool $isAnonymous): self
{
$this->isAnonymous = $isAnonymous;
return $this;
}
/**
* @return Collection|InvitationRecipient[]
*/
public function getRecipients(): Collection
{
return $this->recipients;
}
public function addRecipient(InvitationRecipient $recipient): self
{
if (!$this->recipients->contains($recipient)) {
$this->recipients[] = $recipient;
$recipient->setInvitation($this);
}
return $this;
}
public function removeRecipient(InvitationRecipient $recipient): self
{
if ($this->recipients->contains($recipient)) {
$this->recipients->removeElement($recipient);
// set the owning side to null (unless already changed)
if ($recipient->getInvitation() === $this) {
$recipient->setInvitation(null);
}
}
return $this;
}
}