src/Entity/Invitation.php line 14

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. use Gedmo\Timestampable\Traits\TimestampableEntity;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\InvitationRepository")
  10.  */
  11. class Invitation
  12. {
  13.     use TimestampableEntity;
  14.     /**
  15.      * @ORM\Id()
  16.      * @ORM\GeneratedValue()
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity="App\Entity\User")
  22.      * @ORM\JoinColumn(nullable=false)
  23.      */
  24.     private $user;
  25.     /**
  26.      * @ORM\ManyToOne(targetEntity="App\Entity\Company")
  27.      * @ORM\JoinColumn(nullable=false)
  28.      */
  29.     private $company;
  30.     /**
  31.      * @ORM\Column(type="boolean")
  32.      * @Assert\Type(type="boolean")
  33.      */
  34.     private $isAnonymous;
  35.     /**
  36.      * @var Collection
  37.      *
  38.      * @ORM\OneToMany(targetEntity="App\Entity\InvitationRecipient", mappedBy="invitation", cascade={"persist"}, orphanRemoval=true)
  39.      * @Assert\Count(
  40.      *      min = 1,
  41.      *      minMessage = "You must specify at least one coworker"
  42.      * )
  43.      * @Assert\Valid()
  44.      */
  45.     private $recipients;
  46.     public function __construct()
  47.     {
  48.         $this->isAnonymous true;
  49.         $this->recipients = new ArrayCollection();
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getUser(): ?User
  56.     {
  57.         return $this->user;
  58.     }
  59.     public function setUser(?User $user): self
  60.     {
  61.         $this->user $user;
  62.         return $this;
  63.     }
  64.     public function getCompany(): ?Company
  65.     {
  66.         return $this->company;
  67.     }
  68.     public function setCompany(?Company $company): self
  69.     {
  70.         $this->company $company;
  71.         return $this;
  72.     }
  73.     public function getIsAnonymous(): ?bool
  74.     {
  75.         return $this->isAnonymous;
  76.     }
  77.     public function setIsAnonymous(bool $isAnonymous): self
  78.     {
  79.         $this->isAnonymous $isAnonymous;
  80.         return $this;
  81.     }
  82.     /**
  83.      * @return Collection|InvitationRecipient[]
  84.      */
  85.     public function getRecipients(): Collection
  86.     {
  87.         return $this->recipients;
  88.     }
  89.     public function addRecipient(InvitationRecipient $recipient): self
  90.     {
  91.         if (!$this->recipients->contains($recipient)) {
  92.             $this->recipients[] = $recipient;
  93.             $recipient->setInvitation($this);
  94.         }
  95.         return $this;
  96.     }
  97.     public function removeRecipient(InvitationRecipient $recipient): self
  98.     {
  99.         if ($this->recipients->contains($recipient)) {
  100.             $this->recipients->removeElement($recipient);
  101.             // set the owning side to null (unless already changed)
  102.             if ($recipient->getInvitation() === $this) {
  103.                 $recipient->setInvitation(null);
  104.             }
  105.         }
  106.         return $this;
  107.     }
  108. }