From 25634ba12bc79f6058aac041ac5184f704a558c2 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 1 Apr 2021 11:06:36 +0200 Subject: [PATCH] Make some relations bidirectionnal --- .../Entity/AccompanyingPeriod.php | 75 +++++++++++++++---- .../Entity/AccompanyingPeriod/Comment.php | 4 +- .../Entity/AccompanyingPeriod/Resource.php | 5 +- 3 files changed, 66 insertions(+), 18 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 915500392..2e8b02f0d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -24,7 +24,9 @@ namespace Chill\PersonBundle\Entity; use Chill\MainBundle\Entity\Scope; use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; +use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin; +use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -74,7 +76,16 @@ class AccompanyingPeriod * @ORM\Column(type="text") */ private $remark = ''; - + + /** + * @var Collection + * + * @ORM\OneToMany(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Comment", + * mappedBy="accompanyingPeriod" + * ) + */ + private $comments; + /** * @var Collection * @@ -167,6 +178,15 @@ class AccompanyingPeriod */ private $confidential = false; + /** + * @var Collection + * + * @ORM\OneToMany( + * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Resource", + * mappedBy="accompanyingPeriod" + * ) + */ + private $resources; /** * AccompanyingPeriod constructor. @@ -254,14 +274,8 @@ class AccompanyingPeriod return false; } - - /** - * Set remark - * - * @param string $remark - * @return AccompanyingPeriod - */ - public function setRemark($remark) + + public function setRemark(string $remark): self { if ($remark === null) { $remark = ''; @@ -271,17 +285,29 @@ class AccompanyingPeriod return $this; } - - /** - * Get remark - * - * @return string - */ - public function getRemark() + + public function getRemark(): string { return $this->remark; } + public function getComments(): Collection + { + return $this->comments; + } + + public function addComment(Comment $comment): self + { + $this->comments[] = $comment; + + return $this; + } + + public function removeComment(Comment $comment): void + { + $this->comments->removeElement($comment); + } + /** * Get Participations Collection */ @@ -557,4 +583,21 @@ class AccompanyingPeriod { $this->scopes->removeElement($scope); } + + public function getResources(): Collection + { + return $this->resources; + } + + public function addResource(Resource $resource): self + { + $this->resources[] = $resource; + + return $this; + } + + public function removeResource(Resource $resource): void + { + $this->resources->removeElement($resource); + } } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php index 15b52a9dd..e8ecf3248 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php @@ -41,7 +41,9 @@ class Comment private $id; /** - * @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class) + * @ORM\ManyToOne( + * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod", + * inversedBy="comments") * @ORM\JoinColumn(nullable=false) */ private $accompanyingPeriod; diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php index 90236f014..ec13fcad6 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php @@ -43,7 +43,10 @@ class Resource private $id; /** - * @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class) + * @ORM\ManyToOne( + * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod", + * inversedBy="resources" + * ) * @ORM\JoinColumn(nullable=false) */ private $accompanyingPeriod;