handling multi types and acc-period/repositories endpoint

This commit is contained in:
2021-05-13 00:54:32 +02:00
parent 4a04628d5b
commit 87e2ac9386
9 changed files with 434 additions and 6 deletions

View File

@@ -28,10 +28,15 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use Chill\PersonBundle\Entity\Person;
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
{
@@ -39,6 +44,7 @@ class Resource
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"read"})
*/
private $id;
@@ -91,7 +97,7 @@ class Resource
return $this->thirdParty;
}
public function setThirdParty(?ThirdParty $thirdParty): self
private function setThirdParty(?ThirdParty $thirdParty): self
{
$this->thirdParty = $thirdParty;
@@ -103,7 +109,7 @@ class Resource
return $this->person;
}
public function setPerson(?Person $person): self
private function setPerson(?Person $person): self
{
$this->person = $person;
@@ -121,9 +127,35 @@ class Resource
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 Person|ThirdParty
* @return ThirdParty|Person
* @Groups({"read", "write"})
*/
public function getResource()
{