, * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Repository\AccompanyingPeriod\ResourceRepository; use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\Groups; /** * @ORM\Entity(repositoryClass=ResourceRepository::class) * @ORM\Table(name="chill_person_accompanying_period_resource") * @DiscriminatorMap(typeProperty="type", mapping={ * "accompanying_period_resource"=Resource::class * }) */ class Resource { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") * @Groups({"read"}) */ private $id; /** * @ORM\ManyToOne( * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod", * inversedBy="resources" * ) * @ORM\JoinColumn(nullable=false) */ private $accompanyingPeriod; /** * @ORM\ManyToOne(targetEntity=ThirdParty::class) * @ORM\JoinColumn(nullable=true) */ private $thirdParty; /** * @ORM\ManyToOne(targetEntity=Person::class) * @ORM\JoinColumn(nullable=true) */ private $person; /** * @ORM\ManyToOne(targetEntity=Comment::class) * @ORM\JoinColumn(nullable=true) */ private $comment; public function getId(): ?int { return $this->id; } public function getAccompanyingPeriod(): ?AccompanyingPeriod { return $this->accompanyingPeriod; } public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self { $this->accompanyingPeriod = $accompanyingPeriod; return $this; } public function getThirdParty(): ?ThirdParty { return $this->thirdParty; } private function setThirdParty(?ThirdParty $thirdParty): self { $this->thirdParty = $thirdParty; return $this; } public function getPerson(): ?Person { return $this->person; } private function setPerson(?Person $person): self { $this->person = $person; return $this; } public function getComment(): ?Comment { return $this->comment; } public function setComment(?Comment $comment): self { $this->comment = $comment; return $this; } /** * * @param $resource Person|ThirdParty */ public function setResource($resource): self { if ($resource instanceof ThirdParty) { $this->setThirdParty($resource); $this->setPerson(NULL); } elseif ($resource instanceof Person) { $this->setPerson($resource); $this->setThirdParty(NULL); } elseif (NULL === $resource) { $this->setPerson(NULL); $this->setThirdParty(NULL); } else { throw new \UnexpectedValueException(sprintf("the resource ". "should be an instance of %s or %s", Person::class, ThirdParty::class)); } return $this; } /** * @return ThirdParty|Person * @Groups({"read", "write"}) */ public function getResource() { return $this->person ?? $this->thirdParty; } }