add api for getting goal and results by social action and goal

This commit is contained in:
2021-06-22 16:08:53 +02:00
parent 34d6452286
commit b53f6af8d8
14 changed files with 700 additions and 12 deletions

View File

@@ -38,13 +38,12 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Column(type="text")
* @Serializer\Groups({"read"})
* @Serializer\Groups({"read", "accompanying_period_work:edit"})
*/
private string $note = "";
/**
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
* @Serializer\Groups({"read"})
*/
private ?AccompanyingPeriod $accompanyingPeriod = null;
@@ -83,13 +82,16 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Column(type="date_immutable")
* @Serializer\Groups({"accompanying_period_work:create"})
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"})
*/
private \DateTimeImmutable $startDate;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default":null})
* @Serializer\Groups({"accompanying_period_work:create", "read"})
* @Serializer\Groups({"accompanying_period_work:create"})
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"})
* @Assert\GreaterThan(propertyPath="startDate",
* message="accompanying_course_work.The endDate should be greater than the start date"
* )
@@ -99,6 +101,8 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
* @Serializer\Groups({"read"})
* @Serializer\Groups({"accompanying_period_work:create"})
* @Serializer\Groups({"accompanying_period_work:edit"})
*
* In schema : traitant
*/
@@ -115,13 +119,22 @@ use Symfony\Component\Validator\Constraints as Assert;
private string $createdAutomaticallyReason = "";
/**
* @ORM\OneToMany(targetEntity=AccompanyingPeriodWorkGoal::class, mappedBy="accompanyingPeriodWork")
* @ORM\OneToMany(
* targetEntity=AccompanyingPeriodWorkGoal::class,
* mappedBy="accompanyingPeriodWork",
* cascade={"persist"},
* orphanRemoval=true
* )
* @Serializer\Groups({"read"})
* @Serializer\Groups({"accompanying_period_work:edit"})
*/
private Collection $goals;
/**
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorks")
* @ORM\JoinTable(name="chill_person_accompanying_period_work_result")
* @Serializer\Groups({"read"})
* @Serializer\Groups({"accompanying_period_work:edit"})
*/
private Collection $results;
@@ -130,6 +143,8 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\JoinTable(name="chill_person_accompanying_period_work_third_party")
*
* In schema : intervenants
* @Serializer\Groups({"read"})
* @Serializer\Groups({"accompanying_period_work:edit"})
*/
private Collection $thirdParties;
@@ -255,7 +270,7 @@ use Symfony\Component\Validator\Constraints as Assert;
return $this->endDate;
}
public function setEndDate(\DateTimeInterface $endDate): self
public function setEndDate(?\DateTimeInterface $endDate = null): self
{
$this->endDate = $endDate;
@@ -310,7 +325,7 @@ use Symfony\Component\Validator\Constraints as Assert;
{
if (!$this->goals->contains($goal)) {
$this->goals[] = $goal;
$goal->setAccompanyingPeriodWork2($this);
$goal->setAccompanyingPeriodWork($this);
}
return $this;
@@ -318,10 +333,10 @@ use Symfony\Component\Validator\Constraints as Assert;
public function removeGoal(AccompanyingPeriodWorkGoal $goal): self
{
if ($this->goals->removeElement($goal)) {
if ($this->goals->removeElement($goal)) {
// set the owning side to null (unless already changed)
if ($goal->getAccompanyingPeriodWork2() === $this) {
$goal->setAccompanyingPeriodWork2(null);
if ($goal->getAccompanyingPeriodWork() === $this) {
$goal->setAccompanyingPeriodWork(null);
}
}

View File

@@ -7,10 +7,17 @@ use Chill\PersonBundle\Entity\SocialWork\Result;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
* @ORM\Table(name="chill_person_accompanying_period_work_goal")
* @Serializer\DiscriminatorMap(
* typeProperty="type",
* mapping={
* "accompanying_period_work_goal":AccompanyingPeriodWorkGoal::class
* }
* )
*/
class AccompanyingPeriodWorkGoal
{
@@ -18,11 +25,14 @@ class AccompanyingPeriodWorkGoal
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
*/
private $id;
/**
* @ORM\Column(type="text")
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"})
*/
private $note;
@@ -33,12 +43,16 @@ class AccompanyingPeriodWorkGoal
/**
* @ORM\ManyToOne(targetEntity=Goal::class)
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"})
*/
private $goal;
/**
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorkGoals")
* @ORM\JoinTable(name="chill_person_accompanying_period_work_goal_result")
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"})
*/
private $results;
@@ -71,6 +85,13 @@ class AccompanyingPeriodWorkGoal
public function setAccompanyingPeriodWork(?AccompanyingPeriodWork $accompanyingPeriodWork): self
{
if ($this->accompanyingPeriodWork instanceof AccompanyingPeriodWork
&& $accompanyingPeriodWork !== $this->accompanyingPeriodWork
&& $accompanyingPeriodWork !== null
) {
throw new \LogicException("Change accompanying period work is not allowed");
}
$this->accompanyingPeriodWork = $accompanyingPeriodWork;
return $this;

View File

@@ -5,10 +5,17 @@ namespace Chill\PersonBundle\Entity\SocialWork;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
* @ORM\Table(name="chill_person_social_work_goal")
* @Serializer\DiscriminatorMap(
* typeProperty="type",
* mapping={
* "social_work_goal":Goal::class
* }
* )
*/
class Goal
{
@@ -16,11 +23,13 @@ class Goal
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
*/
private $id;
/**
* @ORM\Column(type="json")
* @Serializer\Groups({"read"})
*/
private $title = [];
@@ -46,6 +55,11 @@ class Goal
$this->results = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): array
{
return $this->title;

View File

@@ -7,10 +7,17 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
* @ORM\Table(name="chill_person_social_work_result")
* @Serializer\DiscriminatorMap(
* typeProperty="type",
* mapping={
* "social_work_result":Result::class
* }
* )
*/
class Result
{
@@ -18,11 +25,13 @@ class Result
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
*/
private $id;
/**
* @ORM\Column(type="json")
* @Serializer\Groups({"read"})
*/
private $title = [];